Python Pillow Tutorial
Python Pillow Tutorial
Python Pillow Tutorial
i
Python Pillow
In this tutorial, you will see the hands-on approach to learn different functionalities of
pillow, much more than, read & save an image, creating thumbnail & merge to images,
blur, crop, flip & rotate images, resizing & adding watermark, adding filters & working with
colors to an image and use of pillow & numpy in machine learning.
Audience
This tutorial is basically designed to work as a guide for developers who wants to learn
python capabilities, automate image editing. It is also for the beginners who wish to know
the image processing capabilities of python using pillow package and for the web
developers who wants to update and use images with logos & watermark on their websites.
Prerequisites
It would be helpful if you have prior knowledge on any of the below mentioned technologies
such as access to computer & python is installed in it (else we need to install it), basic
understanding of python data types and functions and ability to install Python
dependencies, i.e. “pip install ‘package_name’”.
All the content and graphics published in this e-book are the property of Tutorials Point (I)
Pvt. Ltd. The user of this e-book is prohibited to reuse, retain, copy, distribute or republish
any contents or a part of contents of this e-book in any manner without written consent
of the publisher.
We strive to update the contents of our website and tutorials as timely and as precisely as
possible, however, the contents may contain inaccuracies or errors. Tutorials Point (I) Pvt.
Ltd. provides no guarantee regarding the accuracy, timeliness or completeness of our
website or its contents including this tutorial. If you discover any errors on our website or
in this tutorial, please notify us at contact@tutorialspoint.com
ii
Python Pillow
Table of Contents
About the tutorial ............................................................................................................................................ ii
Audience .......................................................................................................................................................... ii
Prerequisites .................................................................................................................................................... ii
Simple blur..................................................................................................................................................... 22
iii
Python Pillow
Filters ............................................................................................................................................................. 48
ImageColor.getrgb() Method......................................................................................................................... 67
Canvas ........................................................................................................................................................... 72
iv
1. Python Pillow ― Overview Python Pillow
In today’s digital world, we come across lots of digital images. In case, we are working
with Python programming language, it provides lot of image processing libraries to add
image processing capabilities to digital images.
Some of the most common image processing libraries are: OpenCV, Python Imaging
Library (PIL), Scikit-image, Pillow. However, in this tutorial, we are only focusing on Pillow
module and will try to explore various capabilities of this module.
Pillow is built on top of PIL (Python Image Library). PIL is one of the important modules
for image processing in Python. However, the PIL module is not supported since 2011 and
doesn’t support python 3.
Pillow module gives more functionalities, runs on all major operating system and support
for python 3. It supports wide variety of images such as “jpeg”, “png”, “bmp”, “gif”, “ppm”,
“tiff”. You can do almost anything on digital images using pillow module. Apart from basic
image processing functionality, including point operations, filtering images using built-in
convolution kernels, and color space conversions.
Image Archives
The Python Imaging Library is best suited for image archival and batch processing
applications. Python pillow package can be used for creating thumbnails, converting from
one format to another and print images, etc.
Image Display
You can display images using Tk PhotoImage, BitmapImage and Windows DIB interface,
which can be used with PythonWin and other Windows-based toolkits and many other
Graphical User Interface (GUI) toolkits.
For debugging purposes, there is a show () method to save the image to disk which calls
the external display utility.
Image Processing
The Pillow library contains all the basic image processing functionality. You can do image
resizing, rotation and transformation.
Pillow module allows you to pull some statistics data out of image using histogram method,
which later can be used for statistical analysis and automatic contrast enhancement.
1
2. Python Pillow — Environment Setup Python Pillow
Installing pillow package is very easy, especially if you’re installing it using pip.
In case, if pip and pillow are already installed in your computer, above commands will
simply mention the ‘requirement already satisfied’ as shown below:
2
3. Python Pillow — Using Image Module Python Pillow
To display the image, pillow library is using an image class within it. The image module
inside pillow package contains some important inbuilt functions like, load images or create
new images, etc.
Instead of calling the Pillow module, we will call the PIL module as to make it backward
compatible with an older module called Python Imaging Library (PIL). That’s why our code
starts with “from PIL import Image” instead of “from Pillow import Image”.
Next, we’re going to load the image by calling the Image.open() function, which returns
a value of the Image object data type. Any modification we make to the image object can
be saved to an image file with the save() method. The image object we received using
Image.open(), later can be used to resize, crop, draw or other image manipulation
method calls on this Image object.
Example
Following example demonstrates the rotation of an image using python pillow:
Output
If you save the above program as Example.py and execute, it displays the original and
rotated images using standard PNG display utility, as follows:
3
Python Pillow
Actual image
4
Python Pillow
Image.filename
This function is used to get the file name or the path of the image.
>>>image = Image.open('beach1.jpg')
>>> image.filename
'beach1.jpg'
Image.format
This function returns file format of the image file like ‘JPEG’, ‘BMP’, ‘PNG’, etc.
5
Python Pillow
Image.mode
It is used to get the pixel format used by the image. Typical values are “1”, “L”, “RGB” or
“CMYK”.
>>> image.mode
'RGB'
Image.size
It returns the tuple consist of height & weight of the image.
>>> image.size
(1280, 721)
Image.width
It returns only the width of the image.
>>> image.width
1280
Image.height
It returns only the height of the image.
>>> image.height
721
Image.info
It returns a dictionary holding data associated with the image.
>>> image.info
{'jfif': 257, 'jfif_version': (1, 1), 'dpi': (300, 300), 'jfif_unit': 1,
'jfif_density': (300, 300), 'exif': b"Exif\x00\x00MM\x00*\x00\x00\x00
....
....
\xeb\x00\x00'\x10\x00\x00\xd7\xb3\x00\x00\x03\xe8"}
6
Python Pillow
Image.palette
It returns the colour palette table, if any.
>>> image.palette
7
4. Python Pillow — Working with Images Python Pillow
This chapter elaborates on topics including how to read and save an image in Pillow.
Reading an Image
Reading and writing images using pillow library is very simple, with the help of PIL.Image
module function.
Syntax
Image.open(fp, mode=’r’)
Where
fp: A filename (string), pathlib.Path object or a file object. The file object must
implement read(), seek() and tell() methods and be opened in binary mode.
mode: It’s an optional argument, if given, must be ‘r’.
Example
Following is a very simple example, where we are going to open an image of any format
(We are using .jpg), display it in a window and then save it (default location) with another
file format (.png).
In the above example, we import the Image module from PIL library and then, call the
Image.open() function to read an image from disk, which returns an image object data
type. It will automatically determine the type of file by looking at the file content. For
reading, the open() function accepts a filename(string), a path object or an
image(file) object.
So, by using the open() function, we are actually reading the image. Image.open() will
read the image and get all the relevant information from the image.
8
Python Pillow
Output
If you save the above program as Example.py and execute, it displays the original (.jpg)
and resaved (.bmp) images using standard PNG display utility, as follows:
Actual image
9
Python Pillow
Saving an Image
The save() function writes an image to file. Like for reading (open() function), the save()
function accepts a filename, a path object or a file object that has been opened to write.
Syntax
Image.save(fp, format=None, **params)
Where,
10
Python Pillow
KeyError – If the output format could not be determined from the file name, use
the format option to solve this.
IOError - If the file could not be written, the file may have been created, and may
contain partial data.
In short, the above syntax will save the image under the given filename. If no format is
specified, then it is based on current filename extension. To provide the additional
instructions to the writer, we use keyword options.
image.save('beach1.bmp')
In the above example, it saves the file based on the file extension to determine the type
of image, for example – the above will create a bmp file in our current working directory.
You can also explicitly specify the file type as a second parameter:
image.save('beach1.gif', 'GIF')
11
5. Python Pillow — Creating Thumbnails Python Pillow
Sometimes, it is required to have all images of equal height and width. One way to achieve
this, is by creating a thumbnail of all images using the thumbnail() function from pillow
library.
This method modifies the image to contain a thumbnail version of itself and the size of the
image will be no larger than the given size.
The method calculates an appropriate thumbnail size to preserve the aspect of the image,
calls the draft () method to configure the file reader (where applicable) and finally,
resizes the image.
Syntax
Image.thumbnail(size, resample=3)
Where,
Returns – None
Example
Following example demonstrates the creation of a thumbnail using python pillow:
def tnails():
try:
image = Image.open('images/cat.jpg')
image.thumbnail((90,90))
image.save('images/thumbnail.jpg')
image1 = Image.open('images/thumbnail.jpg')
image1.show()
except IOError:
pass
tnails()
12
Python Pillow
Output
If you save the above program as Example.py and execute, it displays the created
thumbnail using the default PNG display utility, as follows:
Original image
13
Python Pillow
Output image
14
6. Python Pillow — Merging Images Python Pillow
Pillow package allows you to paste an image onto another one. The merge() function
accepts a mode and a tuple of images as parameters, and combines them into a single
image.
Syntax
Image.merge(mode, bands)
Where,
Using the merge() function, you can merge the RGB bands of an image as:
On executing the above piece of code, you can see the original image and the image with
merge the RGB bands as shown below:
15
Python Pillow
Input image
16
Python Pillow
Output image
Create image object for the required images using the open() function.
While merging two images, you need to make sure that both images are of same
size. Therefore, get each sizes of both images and if required, resize them
accordingly.
Create an empty image using the Image.new() function.
Paste the images using the paste() function.
Save and display the resultant image using the save() and show() functions.
Example
Following example demonstrates the merging of two images using python pillow:
image1 = Image.open('images/elephant.jpg')
image1.show()
image2 = Image.open('images/ladakh.jpg')
image2.show()
#resize, first image
image1 = image1.resize((426, 240))
image1_size = image1.size
image2_size = image2.size
new_image = Image.new('RGB',(2*image1_size[0], image1_size[1]), (250,250,250))
new_image.paste(image1,(0,0))
new_image.paste(image2,(image1_size[0],0))
new_image.save("images/merged_image.jpg","JPEG")
new_image.show()
Output
If you save the above program as Example.py and execute, it displays the two input
images and the merged image using standard PNG display utility, as follows:
18
Python Pillow
Input image1
19
Python Pillow
Input image2
20
Python Pillow
Merged image
21
7. Python Pillow — Blur an Image Python Pillow
Blurring an image can be done by reducing the level of noise in the image by applying a
filter to an image. Image blurring is one of the important aspects of image processing.
The ImageFilter class in the Pillow library provides several standard image filters. Image
filters can be applied to an image by calling the filter() method of Image object with
required filter type as defined in the ImageFilter class.
There are various techniques used to blur images and we are going to discuss the below
mentioned techniques.
Simple blur
Box blur
Gaussian blur
All these three techniques are going to use ‘Image.filter()’ method for applying the filter
to images.
Simple blur
It applies a blurring effect on to the image as specified through a specific kernel or a
convolution matrix.
Syntax
filter(ImageFilter.BLUR)
Example
#Import required Image library
from PIL import Image, ImageFilter
blurImage = OriImage.filter(ImageFilter.BLUR)
blurImage.show()
#Save blurImage
blurImage.save('images/simBlurImage.jpg')
Output
22
Python Pillow
On executing, the above example generates the two standard PNG display utility windows
(in this case windows Photos app).
Original image
23
Python Pillow
Blurred image
Box blur
In this filter, we use ‘radius’ as parameter. Radius is directly proportional to the blur value.
Syntax
ImageFilter.BoxBlur(radius)
Where,
Example
#Import required Image library
from PIL import Image, ImageFilter
24
Python Pillow
Output
On executing, the above example generates the two standard PNG display utility windows
(in this case windows Photos app).
Original image
25
Python Pillow
Blurred image
Gaussian Blur
This filter also uses parameter radius and does the same work as box blur with some
algorithmic changes. In short, changing the radius value, will generate different intensity
of ‘Gaussianblur’ images.
Syntax
ImageFilter.GaussianBlur(radius=2)
Where,
Example
#Import required Image library
from PIL import Image, ImageFilter
26
Python Pillow
Output
On executing, the above example generates the two standard PNG display utility windows
(in this case windows Photos app).
Original image
27
Python Pillow
Blurred image
28
8. Python Pillow — Cropping an Image Python Pillow
Cropping is one of the important operations of the image processing to remove unwanted
portions of an image as well as to add required features to an image. It is widely used
process in web applications, for uploading an image.
The crop() function of the image class in Pillow requires the portion to be cropped as
rectangle. The rectangle portion to be cropped from an image is specified as a four-element
tuple and returns the rectangle portion of the image that has been cropped as an image
Object.
Example
Following example demonstrates how to rotate an image using python pillow:
Output
If you save the above program as Example.py and execute, it displays the original and
cropped images using standard PNG display utility, as follows:
29
Python Pillow
Original image
30
Python Pillow
Cropped image
31
9. Python Pillow — Flip and Rotate Images Python Pillow
While working on images using python image processing library, there are instances where
you need to flip an existing image to get some more insights out of it, to enhance its
visibility or because of your requirement.
Image module of the pillow library allows us to flip an image very easily. We are going to
use the transpose (method) function from the Image module for flipping the images. Some
of the mostly commonly used methods supported by ‘transpose()’ are:
Output
32
Python Pillow
Original image
33
Python Pillow
Flipped image
34
Python Pillow
Output
Original Image
35
Python Pillow
Flipped Image
36
Python Pillow
Output
Original Image
37
Python Pillow
Rotated Image
38
10. Python Pillow — Resizing an Image Python Pillow
Most of the digital image is a two-dimensional plane of pixels and it has a width and height.
The Image module from pillow library has an attribute size. This tuple consists of width
and height of the image as its elements. To resize an image, you call the resize() method
of pillow’s image class by giving width and height.
#Make the new image half the width and half the height of the original image
Output
If you save the above program as Example.py and execute, it displays the original and
resized images using standard PNG display utility, as follows:
39
Python Pillow
Original Image
40
Python Pillow
Resized Image
41
11. Python Pillow — Creating a Watermark Python Pillow
You have noticed that, some of the online photos are watermarked. Watermark is definitely
one of the better ways to protect your images from misuse. Also, it is recommended to
add watermark to your creative photos, before sharing them on social media to prevent it
from being misused.
Watermark is generally some text or logo overlaid on the photo that identifies who took
the photo or who owns the rights to the photo.
Pillow package allows us to add watermarks to your images. For adding watermark to our
image, we need “Image”, “ImageDraw” and “ImageFont” modules from pillow
package.
The ‘ImageDraw’ module adds functionality to draw 2D graphics onto new or existing
images. The ‘ImageFont’ module is employed for loading bitmap, TrueType and OpenType
font files.
Example
Following python program demonstrates how to add watermark to an image using python
pillow:
draw = ImageDraw.Draw(im)
text = "sample watermark"
42
Python Pillow
Output
Suppose, following is the input image boy.jpg located in the folder image.
After executing the above program, if you observe the output folder you can see the
resultant watermark.jpg file with watermark on it as shown below:
43
Python Pillow
44
12. Python Pillow — Adding Filters to an Image Python Pillow
The ImageFilter module contains definitions for a pre-defined set of filters, which we
used with Image.filter() method. These filters are used to change the looks and feel of
the image.
Example
Below example is Filtering an image:
im = Image.open('jungleSaf2.jpg')
im1 = im.filter(ImageFilter.BLUR)
im1.show()
im2 = im.filter(ImageFilter.MinFilter(3))
im2.show()
In above program, we have used the MinFilter() method, which is used to create a
minimum filter. It picks the lowest pixel value in a window with the given size.
ImageFilter.MinFilter(size=3)
Where,
Output
If you save the above program and execute, it shows the original image, blurred image
and, the blurred image with MinFilter using standard PNG display utility, as follows:
45
Python Pillow
Original Image
46
Python Pillow
Blurred Image
47
Python Pillow
Filters
The current version of pillow library provides below mentioned set of predefined image
enhancement filters.
BLUR
CONTOUR
DETAIL
EDGE_ENHANCE
EDGE_ENHANCE_MORE
EMBOSS
FIND_EDGES
SHARPEN
SMOOTH
SMOOTH_MORE
48
Python Pillow
Example
Following python example applies the blur filter on an image saves it and, displays it using
standard PNG display utility:
49
Python Pillow
Output
In the same way, to the image.filter() method you can pass any of the following
parameters to get respective outputs:
CONTOUR
DETAIL
EDGE_ENHANCE
EDGE_ENHANCE_MORE
EMBOSS
FIND_EDGES
SMOOTH
SMOOTH_MORE
SHARPEN
50
Python Pillow
Example
#Import required image modules
from PIL import Image, ImageFilter
Output
If you save the above program and execute, it shows the original image and, the filtered
image using standard PNG display utility, as follows:
Original image
51
Python Pillow
Filtered image
Example
#Import required image modules
from PIL import Image, ImageFilter
52
Python Pillow
img1 = img.filter(DETAIL)
img1.save('images/ImageFilter_blur.jpg')
img1.show()
Output
If you save the above program and execute, it shows the original image, and the filtered
image using standard PNG display utility, as follows:
Original image
53
Python Pillow
Filtered image
Example
#Import required image modules
from PIL import Image, ImageFilter
Output
54
Python Pillow
If you save the above program and execute, it shows the original image, and the filtered
image using standard PNG display utility, as follows:
Original image
Filtered image
55
Python Pillow
Example
#Import required image modules
from PIL import Image, ImageFilter
Output
If you save the above program and execute, it shows the original image, and the filtered
image using standard PNG display utility, as follows:
56
Python Pillow
Original image
Filtered image
57
Python Pillow
Example
#Import required image modules
from PIL import Image, ImageFilter
Output
If you save the above program and execute, it shows the original image and, the filtered
image using standard PNG display utility, as follows:
58
Python Pillow
Original image
Filtered image
59
Python Pillow
Example
#Import required image modules
from PIL import Image, ImageFilter
Output
If you save the above program and execute, it shows the original image and, the filtered
image using standard PNG display utility, as follows:
60
Python Pillow
Original image
Filtered image
61
Python Pillow
Example
#Import required image modules
from PIL import Image, ImageFilter
Output
If you save the above program and execute, it shows the original image and, the filtered
image using standard PNG display utility, as follows:
62
Python Pillow
Original image
Filtered image
Example
63
Python Pillow
Output
If you save the above program and execute, it shows the original image and, the filtered
image using standard PNG display utility, as follows:
Original image
64
Python Pillow
Filtered image
Example
#Import required image modules
from PIL import Image, ImageFilter
Output
If you save the above program and execute, it shows the original image and, the filtered
image using standard PNG display utility, as follows:
65
Python Pillow
Original image
Filtered image
66
13. Python Pillow — Colors on an Image Python Pillow
The ImageColor module contains colors in different format arranged in tables and it also
contains converters from CSS3-style color specifiers to RGB tuples.
Color Names
The ImageColor module supports the following strings formats:
The Image Color module provides around 140 standard color names, based on the
color’s supported by the X Window system and most web browsers. Color names
are case insensitive.
ImageColor.getrgb() Method
Convert a color string to an RGB tuple. If the string cannot be parsed, a ValueError
exception is raised by this function.
Syntax
PIL.ImageColor.getrgb(color)
Where,
Example 1
from PIL import ImageColor
# using getrgb
img = ImageColor.getrgb("blue")
print(img)
67
Python Pillow
img1 = ImageColor.getrgb("purple")
print(img1)
Output
(0, 0, 255)
(128, 0, 128)
Example 2
#Import required image modules
from PIL import Image,ImageColor
#Show image
img.show()
68
Python Pillow
Output
Syntax
PIL.ImageColor.getcolor(color, mode)
Where,
Example
#Import required image modules
69
Python Pillow
# using getrgb
img = ImageColor.getrgb("skyblue")
print(img)
img1 = ImageColor.getrgb("purple")
print(img1)
Output
(135, 206, 235)
(128, 0, 128)
70
14. Python Pillow — ImageDraw Module Python Pillow
The ‘ImageDraw’ module provides simple 2D graphics support for Image Object.
Generally, we use this module to create new images, annotate or retouch existing images
and to generate graphics on the fly for web use.
The graphics commands support the drawing of shapes and annotation of text.
Example
Following python example draws a line across the given image:
#Draw line
draw = ImageDraw.Draw(im)
draw.line((0, 0) + im.size, fill=128)
draw.line((0, im.size[1], im.size[0], 0), fill=128)
#Show image
im.show()
71
Python Pillow
Output
If you save the above program as Example.py and execute, it draws a line across the
image and displays it using standard PNG display utility, as follows:
Canvas
An ImageDraw is a Pillow drawable surface (i.e., a canvas) of an Image.
ImageDraw.Draw(img) returns a drawable canvas representation of Image
parameter img. The background of the canvas is the "img" image.
Example
Following python example draws text on the given image:
# get an image
base = Image.open('images/boy.jpg').convert('RGBA')
72
Python Pillow
# make a blank image for the text, initialized to transparent text color
txt = Image.new('RGBA', base.size, (255,255,255,0))
# get a font
fnt = ImageFont.truetype('E:/PythonPillow/Fonts/Pacifico.ttf', 40)
#Show image
out.show()
73
Python Pillow
Output
Line
Following is, the syntax to draw a line using python pillow:
The line() method draws a line from the upper left to lower right corners of bounding box
xy and canvas. The line is filled using color fill. Default values of None and 0 respectively
are for the parameters fill and width which are optional.
Example
from PIL import Image, ImageDraw
74
Python Pillow
img.show()
Output
Eclipse
Following is, the syntax to draw an ellipse using python pillow:
The ellipse() method draws the ellipse surrounded by bounding box xy on draw. The
shape is filled using color fill and the perimeter in color outline. Default values of None are
for the parameters fill and width which are optional.
Example
75
Python Pillow
Output
Rectangle
Following is, the syntax to draw a rectangle using python pillow:
The rectangle() method draws the rectangle given bounding box xy on draw. The shape
is filled using color fill and the perimeter in color outline. Default values of None are for
the parameters fill and width which are optional.
76
Python Pillow
draw.rectangle(
(200, 125, 300, 200),
fill=(255, 0, 0),
outline=(0, 0, 0))
img.show()
Output
Polygon
Following is, the syntax to draw a rectangle using python pillow:
77
Python Pillow
The polygon() method draws a polygon connecting with straight lines the co-ordinate
sequence locations seq on draw. The first and last co-ordinates in seq are also connected
by a straight-line. The shape is filled using color fill and the perimeter in color outline.
Parameters fill and outline are optional with default values None.
draw.polygon(
((200, 200), (300, 100), (250, 50)),
fill=(255, 0, 0),
outline=(0, 0, 0))
img.show()
78
Python Pillow
Output
79
15. Python Pillow — Image Sequences Python Pillow
The Python Imaging Library (PIL) contains some basic support for Image sequences
(animation formats). FLI/FLC, GIF and a few experimental formats are the supported
sequence formats. TIFF files can contain more than one frame as well.
Opening a sequence file, PIL automatically loads the first frame in the sequence. To move
between different frames, you can use the seek and tell methods.
except EOFError:
#End of sequence
pass
Output
raise EOFError
EOFError
As we can see above, you’ll get an EOFError exception when the sequence ends.
Most drivers in the latest version of library only allow you to seek to the next frame (as in
above example), to rewind the file, you may have to reopen it.
return self.img
except EOFError:
raise IndexError # end of sequence
81
16. Python Pillow — Writing Text on Image Python Pillow
You can write text on images by passing the location of the text, the text itself and the
color of the text. We can pass multiple other parameters to this method.
Example
from PIL import Image, ImageDraw
img = Image.open(beach1.jpg')
d1 = ImageDraw.Draw(img)
d1.text((28, 36), "Hello, TutorialsPoint!", fill=(255, 0, 0))
img.show()
img.save("images/image_text.jpg")
Input
Output
If you save the above program as Example.py and execute, it will add the given text on
it, and displays it using the standard PNG display utility, as follows:
82
Python Pillow
Example
from PIL import Image, ImageDraw, ImageFont
img = Image.open('images/logo.jpg')
d1 = ImageDraw.Draw(img)
myFont = ImageFont.truetype('E:/PythonPillow/Fonts/FreeMono.ttf', 40)
d1.text((0, 0), "Sample text", font=myFont, fill =(255, 0, 0))
img.show()
img.save("images/image_text.jpg")
83
Python Pillow
Output
84
17. Python Pillow — M L with Numpy Python Pillow
In this chapter, we use numpy to store and manipulate image data using python imaging
library – “pillow”.
Before proceeding with this chapter open command prompt in administrator mode and
execute the following command in it to install numpy:
Note: This works only if you have PIP installed and updated.
img = Image.fromarray(arr)
img.show()
img.save("RGB_image.jpg")
85
Python Pillow
Output
for x in range(300):
for y in range(150):
if (x % 16) // 8 == (y % 16)//8:
arr[y, x] = 0
86
Python Pillow
else:
arr[y, x] = 255
img = Image.fromarray(arr)
img.show()
img.save('greyscale.jpg')
Output
87
Python Pillow
Example
#Import required libraries
from PIL import Image
from numpy import array
#Display image
arr2im.show()
Output
If you save the above program as Example.py and execute:
Since we have used show() method the images are displayed using the default
PNG display utility, as follows.
88
Python Pillow
[[ 38 59 60]
[ 37 58 59]
[ 36 57 58]
...
[ 74 65 60]
[ 59 48 42]
[ 66 53 47]]
[[ 40 61 62]
[ 38 59 60]
[ 37 58 59]
...
[ 75 66 61]
[ 72 61 55]
[ 61 48 42]]
[[ 40 61 62]
[ 34 55 56]
[ 38 59 60]
...
[ 82 73 68]
[ 72 61 55]
[ 63 52 46]]]
89
Python Pillow
Original Image
90
Python Pillow
91