当前位置:   article > 正文

Python读取文件夹图片并显示_python 读取图片目录并显示

python 读取图片目录并显示

1 显示某个文件下的所有图片

  1. import matplotlib.image as im
  2. import matplotlib.pyplot as plt
  3. %matplotlib inline #jupyter notebook需要加这一句
  4. import os
  5. #需要读取的路径
  6. path_name = r'E:\BreakHis_dataset\validation\12'
  7. for item in os.listdir(path=path_name):
  8. img = im.imread(os.path.join(path_name,item))
  9. plt.imshow(img)
  10. plt.show()

2 读取图片数据并存储

  1. import os
  2. import cv2
  3. # this if for store all of the image data
  4. array_of_img = []
  5. # this function is for read image,the input is directory name
  6. def read_directory(directory_name):
  7. # this loop is for read each image in this foder,directory_name is the foder name with images.
  8. for filename in os.listdir(directory_name):
  9. #print(filename) #just for test
  10. #img is used to store the image data
  11. img = cv2.imread(directory_name + "/" + filename)
  12. array_of_img.append(img)
  13. #print(img)
  14. print(array_of_img)

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/凡人多烦事01/article/detail/632388
推荐阅读
相关标签
  

闽ICP备14008679号