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
much simpler in jupyter using pillow.
from PIL import Image
image0=Image.open('image.png')
image0
I found that this is working
# source: http://nbviewer.ipython.org/gist/deeplook/5162445
from io import BytesIO
from IPython import display
from PIL import Image
def display_pil_image(im):
"""Displayhook function for PIL Images, rendered as PNG."""
b = BytesIO()
im.save(b, format='png')
data = b.getvalue()
ip_img = display.Image(data=data, format='png', embed=True)
return ip_img._repr_png_()
# register display func with PNG formatter:
png_formatter = get_ipython().display_formatter.formatters['image/png']
dpi = png_formatter.for_type(Image.Image, display_pil_image)
After this I can just do:
pil_im
But this must be last line in cell, with no print
after it
I suggest following installation by no image show img.show() (from PIL import Image)
$ sudo apt-get install imagemagick
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))
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)