This is my code
from PIL import Image
pil_im = Image.open(\'data/empire.jpg\')
I would like to do some image manipulation on it, and then s
You can use IPython's Module: display
to load the image. You can read more from the Doc.
from IPython.display import Image
pil_img = Image(filename='data/empire.jpg')
display(pil_img)
As OP's requirement is to use PIL
, if you want to show inline image, you can use matplotlib.pyplot.imshow
with numpy.asarray
like this too:
from matplotlib.pyplot import imshow
import numpy as np
from PIL import Image
%matplotlib inline
pil_im = Image.open('data/empire.jpg', 'r')
imshow(np.asarray(pil_im))
If you only require a preview rather than an inline, you may just use show
like this:
pil_im = Image.open('data/empire.jpg', 'r')
pil_im.show()
In order to simply visualize the image in a notebook you can use display()
%matplotlib inline
from PIL import Image
im = Image.open(im_path)
display(im)
Use IPython display to render PIL images in a notebook.
from PIL import Image # to load images
from IPython.display import display # to display images
pil_im = Image.open('path/to/image.jpg')
display(pil_im)
You can open an image using the Image class from the package PIL and display it with plt.imshow directly.
# First import libraries.
from PIL import Image
import matplotlib.pyplot as plt
# The folliwing line is useful in Jupyter notebook
%matplotlib inline
# Open your file image using the path
img = Image.open(<path_to_image>)
# Since plt knows how to handle instance of the Image class, just input your loaded image to imshow method
plt.imshow(img)
If you are using the pylab extension, you could convert the image to a numpy array and use matplotlib's imshow.
%pylab # only if not started with the --pylab option
imshow(array(pil_im))
EDIT: As mentioned in the comments, the pylab module is deprecated, so use the matplotlib magic instead and import the function explicitly:
%matplotlib
from matplotlib.pyplot import imshow
imshow(array(pil_im))
Based on other answers and my tries, best experience would be first installing, pillow and scipy, then using the following starting code on your jupyter notebook:
%matplotlib inline
from matplotlib.pyplot import imshow
from scipy.misc import imread
imshow(imread('image.jpg', 1))