Reading images in python

前端 未结 9 1981
北海茫月
北海茫月 2021-02-03 19:59

I am trying to read a png image in python. The imread function in scipy is being deprecated and they recommend using imageio

相关标签:
9条回答
  • 2021-02-03 20:04
    import matplotlib.pyplot as plt
    image = plt.imread('images/my_image4.jpg')
    plt.imshow(image)
    

    Using 'matplotlib.pyplot.imread' is recommended by warning messages in jupyter.

    0 讨论(0)
  • 2021-02-03 20:06

    Easy way

    from IPython.display import Image

    Image(filename ="Covid.jpg" size )

    0 讨论(0)
  • 2021-02-03 20:07

    From documentation:

    Matplotlib can only read PNGs natively. Further image formats are supported via the optional dependency on Pillow.

    So in case of PNG we may use plt.imread(). In other cases it's probably better to use Pillow directly.

    0 讨论(0)
  • 2021-02-03 20:10

    For the better answer, you can use these lines of code. Here is the example maybe help you :

    image = cv2.imread('/home/pictures/1.jpg')
    plt.imshow(image)
    plt.show()
    

    In imread() you can pass the directory .so you can also use str() and + to combine dynamic directories and fixed directory like this:

    path = '/home/pictures/'
    for i in range(2) :
        image = cv2.imread(str(path)+'1.jpg')
        plt.imshow(image)
        plt.show()
    

    Both are the same.

    0 讨论(0)
  • 2021-02-03 20:11

    With matplotlib you can use (as shown in the matplotlib documentation)

    import matplotlib.pyplot as plt
    import matplotlib.image as mpimg
    
    img=mpimg.imread('image_name.png')
    

    And plot the image if you want

    imgplot = plt.imshow(img)
    
    0 讨论(0)
  • 2021-02-03 20:17

    you can try to use cv2 like this

    import cv2
    
    image= cv2.imread('image page')
    
    cv2.imshow('image', image)
    
    cv2.waitKey(0)
    
    cv2.destroyAllWindows()
    
    0 讨论(0)
提交回复
热议问题