Advertisement

python(一)——读取图片的几种方式以及图像宽和高

阅读量:

1.PIL

复制代码
    from PIL import Image
    image_PIL=Image.open('G:\Coursera-ML-AndrewNg-Notes\code\ex7-kmeans and PCA\data\ bird_small.png')
    image_PIL.show()
    print('输出类型:{}'.format(type(image_PIL)))
    print('图片的尺寸:{}'.format(image_PIL.size))
    
      
      
      
      
    

输出类型:<class ‘PIL.PngImagePlugin.PngImageFile’>
图片的尺寸:(128, 128)

2.CV2

复制代码
    import cv2
    image_cv=cv2.imread('G:\Coursera-ML-AndrewNg-Notes\code\ex7-kmeans and PCA\data\ bird_small.png')
    cv2.imshow('image',image_cv)
    print('输出类型:{}'.format(type(image_cv)))
    print('图片的尺寸:{}'.format(image_cv.shape))
    
      
      
      
      
    

输出类型:<class ‘numpy.ndarray’>
图片的尺寸:(128, 128, 3)

3.matplotlib.pyplot

复制代码
    import matplotlib.pyplot as plt
    image_matplot = plt.imread('G:\Coursera-ML-AndrewNg-Notes\code\ex7-kmeans and PCA\data\ bird_small.png')
    plt.imshow(image_matplot)
    print('输出类型:{}'.format(type(image_matplot)))
    print('图片的尺寸:{}'.format(image_matplot.shape))
    
      
      
      
      
    

输出类型:<class ‘numpy.ndarray’>
图片的尺寸:(128, 128, 3)

全部评论 (0)

还没有任何评论哟~