首页 > 代码库 > Python文件夹下图像数据可视化

Python文件夹下图像数据可视化

Python文件夹下图像数据可视化

 

  1. import matplotlib.pyplot as plt
  2. import matplotlib.image as mpimg
  3. import numpy as np
  4.  
  5. import urllib2
  6. import urllib
  7. import os
  8. import shutil
  9.  
  10. subdir= "/7"
  11. homedir = os.getcwd() + subdir
  12. # "/home/haoyou/Dev/last_caffe_with_stn/myprojects/spn-mnistcluttered/mnist-cluttered/"+subdir
  13.  
  14. import os
  15. def walk_dir(dir,fileinfo,topdown=True):
  16. for root, dirs, files in os.walk(dir, topdown):
  17. for name in files:
  18. print(os.path.join(name))
  19. fileinfo.write(os.path.join(root,name) + ‘\n‘)
  20. for name in dirs:
  21. print(os.path.join(name))
  22. fileinfo.write(‘ ‘ + os.path.join(root,name) + ‘\n‘)
  23. fileinfo = open(homedir+‘/list.txt‘,‘w‘)
  24. walk_dir(homedir,fileinfo)
  25.  
  26.  
  27. f = open(homedir+"/list.txt", "r")
  28. while True:
  29. for i in range(1,101):
  30. line = f.readline()
  31. if line:
  32.      line=line.strip()
  33. plt.subplot(10,10,i)
  34. lena = mpimg.imread(line)
  35. plt.imshow(lena,cmap=‘gray‘)
  36. plt.axis(‘off‘)
  37. else:
  38. break
  39.  
  40. plt.show()
  41. # for line in f:
  42. # #pass # do something here
  43. # line=line.strip()
  44. # print(line)
  45. # lena = mpimg.imread(line)
  46.  
  47.  
  48. f.close()

Python文件夹下图像数据可视化