Skip to content Skip to sidebar Skip to footer

How To Read Images Into A Script Without Using Using Imageio Or Scikit Image?

I am trying to read a png image in python. The imread function in scipy is being deprecated and they recommend using imageio library. However, I am would rather restrict my usage o

Solution 1:

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

import matplotlib.pyplotas plt
import matplotlib.imageas mpimg

img=mpimg.imread('image_name.png')

And plot the image if you want

imgplot = plt.imshow(img)

Solution 2:

You can also use Pillow like this:

from PIL import Image
image = Image.open("image_path.jpg")
image.show()

Solution 3:

import matplotlib.pyplot as pltimage= plt.imread('images/my_image4.jpg')
plt.imshow(image)

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

Solution 4:

If you just want to read an image in Python using the specified libraries only, I will go with matplotlib

In matplotlib :

import matplotlib.imageread_img= matplotlib.image.imread('your_image.png')

Solution 5:

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

importcv2image= 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.

Post a Comment for "How To Read Images Into A Script Without Using Using Imageio Or Scikit Image?"