日韩久久久精品,亚洲精品久久久久久久久久久,亚洲欧美一区二区三区国产精品 ,一区二区福利

Python中讀取圖片并轉化為numpy.ndarray()數據的6種方式

系統 2202 0

Python中讀取圖片并轉化為numpy.ndarray()數據的6種方式

方式:? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?返回類型

OpenCV? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? np.ndarray
PIL? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?PIL.JpegImagePlugin.JpegImageFile
keras.preprocessing.image? ? ? ? ? ? ? ?PIL.JpegImagePlugin.JpegImageFile
Skimage.io? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? np.ndarray
matplotlib.pyplot? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? np.ndarray
matplotlib.image? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? np.ndarray

?

            
              import numpy as np
import cv2
from keras.preprocessing.image import ImageDataGenerator, array_to_img, img_to_array, load_img
from PIL import Image
import skimage.io as io
import matplotlib.pyplot as plt
import matplotlib.image as mpig


'''
方式:                        返回類型

OpenCV                        np.ndarray
PIL                           PIL.JpegImagePlugin.JpegImageFile
keras.preprocessing.image     PIL.JpegImagePlugin.JpegImageFile
Skimage.io                    np.ndarray
matplotlib.pyplot             np.ndarray
matplotlib.image              np.ndarray
'''

imagePath="E:/DataSet/test1/trainSet/bus/300.jpg"


'''
方式一:使用OpenCV
'''
img1=cv2.imread(imagePath)
print("img1:",img1.shape)
print("img1:",type(img1))
print("-"*10)


'''
方式二:使用PIL
'''
img2=Image.open(imagePath)
print("img2:",img2)
print("img2:",type(img2))
#轉換成np.ndarray格式
img2=np.array(img2)
print("img2:",img2.shape)
print("img2:",type(img2))
print("-"*10)


'''
方式三:使用keras.preprocessing.image
'''
img3=load_img(imagePath)
print("img3:",img3)
print("img3:",type(img3))
#轉換成np.ndarray格式,使用np.array(),或者使用keras里的img_to_array()
#使用np.array()
#img3=np.array(img2)
#使用keras里的img_to_array()
img3=img_to_array(img3)
print("img3:",img3.shape)
print("img3:",type(img3))
print("-"*10)


'''
方式四:使用Skimage.io
'''
img4=io.imread(imagePath)
print("img4:",img4.shape)
print("img4:",type(img4))
print("-"*10)


'''
方式五:使用matplotlib.pyplot
'''
img5=plt.imread(imagePath)
print("img5:",img5.shape)
print("img5:",type(img5))
print("-"*10)


'''
方式六:使用matplotlib.image
'''
img6=mpig.imread(imagePath)
print("img6:",img6.shape)
print("img6:",type(img6))
print("-"*10)
            
          

運行結果:

            
              Using TensorFlow backend.
img1: (256, 384, 3)
img1: 
              
                
----------
img2: 
                
                  
img2: 
                  
                    
img2: (256, 384, 3)
img2: 
                    
                      
----------
img3: 
                      
                        
img3: 
                        
                          
img3: (256, 384, 3)
img3: 
                          
                            
----------
img4: (256, 384, 3)
img4: 
                            
                              
----------
img5: (256, 384, 3)
img5: 
                              
                                
----------
img6: (256, 384, 3)
img6: 
                                
                                  
----------
                                
                              
                            
                          
                        
                      
                    
                  
                
              
            
          

Python中讀取圖片并轉化為numpy.ndarray()數據的6種方式_第1張圖片


更多文章、技術交流、商務合作、聯系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號聯系: 360901061

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對您有幫助就好】

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長會非常 感謝您的哦!!!

發表我的評論
最新評論 總共0條評論
主站蜘蛛池模板: 友谊县| 达拉特旗| 雷波县| 肥东县| 积石山| 双鸭山市| 邹城市| 岑巩县| 荆门市| 凤阳县| 竹北市| 那曲县| 洪湖市| 鹿泉市| 郓城县| 孟连| 乌鲁木齐县| 宜兰市| 东乡| 通化县| 扶沟县| 皮山县| 绥中县| 郴州市| 修武县| 南丹县| 余庆县| 务川| 寻甸| 和田县| 孙吴县| 安顺市| 六安市| 安新县| 湟源县| 万源市| 台州市| 宁武县| 潞西市| 清新县| 鄂托克前旗|