python的两种图像读取和处理方法

 1 skimage库
   
   from skimage import data_dir,io, data
   img = data.camera()   #读取data中预先保存的图像camera
                         #Anaconda 版本参见的预存路径,如c:\\ProgramData
\Anaconda3\lib\site-packages\skimage\data 路径。
   #img = io.imread(data_dir+'\camera.png') 
   #更保险的方式是用两个反斜杠,如下。否则可能出现OSError,提示找不到文件
   #img = io.imread(data_dir+'\\camera.png')   

   io.imshow(img)
   io.show()

   type(img)   # 打印出类别为numpy.ndarray,可直接对img执行flatten函数
   img.flatten()   
  
   2.2 Pillow (PIL) 的Image库

   from skimage import data_dir
   from PIL import Image
   img = Image.open(data_dir+'\\coffee.png')
   img.show()   #直接使用show,无需imshow)
   type(img)  #打印出类别是PngImageFile,可直接使用flatten函数
                      # 若为jpg格式,不能使用flatten函数
   img.flatten()

猜你喜欢

转载自blog.csdn.net/tbzj_2000/article/details/80410012