Image processing with pillow?

Description

To write a piece of python code for image processing with the help of pillow library in python.

Input

PNG Image.

Output

  Gray_scale image

  Blurred version of original image.

  Load the image source.

  Import pillow library.

  Convert the image into gray_scale image.

  Make the image blurred using pillow filter.

  Save both the images.

.

#import pillow library
from PIL import Image, ImageFilter

#load image
image = Image.open(‘ml_map.png’)

#The file format of the source file
print(“Image format\n”,image.format,”\n”)

#The pixel format used by the image
print(“Image mode\n”,image.mode,”\n”)

#Image size, in pixels
print(“Image size\n”,image.size,”\n”)

#Convert original into gray_scale image
greyscale_image = image.convert(‘L’)

#Show the grayscale image
greyscale_image.show()

#save the gray_scale image
greyscale_image.save(“gray_scale.png”)

#Blur the image
blurred = image.filter(ImageFilter.BLUR)

#Display blurred images
blurred.show()

#save the new image
blurred.save(“blurred.png”)

Leave Comment

Your email address will not be published. Required fields are marked *

clear formSubmit