I tried to use IPython.display with the following code:
from IPython.display import display, Image
display(Image(filename=\'MyImage.png\'))
Your code:
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
What it should be:
plt.imshow(mpimg.imread('MyImage.png'))
File_name = mpimg.imread('FilePath')
plt.imshow(FileName)
plt.show()
you're missing a plt.show()
unless you're in Jupyter notebook, other IDE's do not automatically display plots so you have to use plt.show()
each time you want to display a plot or made a change to an existing plot in follow up code.
If you are using matplotlib and want to show the image in your interactive notebook, try the following:
%pylab inline
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
img = mpimg.imread('your_image.png')
imgplot = plt.imshow(img)
plt.show()
import IPython.display as display
from PIL import Image
image_path = 'my_image.jpg'
display.display(Image.open(image_path))
In a much simpler way, you can do the same using
from PIL import Image
image = Image.open('image.jpg')
image.show()
Using opencv-python is faster for more operation on image:
import cv2
import matplotlib.pyplot as plt
im = cv2.imread('image.jpg')
im_resized = cv2.resize(im, (224, 224), interpolation=cv2.INTER_LINEAR)
plt.imshow(cv2.cvtColor(im_resized, cv2.COLOR_BGR2RGB))
plt.show()
Your first suggestion works for me
from IPython.display import display, Image
display(Image(filename='path/to/image.jpg'))