Found 17 Articles for Pillow

Applying MinFilter on an image using Pillow library

Prasad Naik
Updated on 18-Mar-2021 06:55:06

163 Views

In this program, we will apply a minimum filter on an image using the pillow library. In minimum filtering, the value of each pixel in a selected window of the image is replaced by the minimum pixel of that window. The filter function is used to apply different filters using the pillow library.Original ImageAlgorithmStep 1: Import Image from Pillow. Step 2: Open the image. Step 3: Call the filter function and specify minfilter. Step 4: Display the output.Example Codefrom PIL import Image, ImageFilter im = Image.open('testimage.jpg') im1 = im.filter(ImageFilter.MinFilter(size = 7)) im1.show()Output

Rotating an image using Pillow library

Prasad Naik
Updated on 17-Mar-2021 08:45:51

687 Views

In this program, we will rotate an image using the pillow library. The rotate() function in the Image class takes in angle of rotation.Original ImageAlgorithmStep1: Import Image class from Pillow. Step 2: Open the image. Step 3: Rotate the image. Step 4: Display the output.Example Codefrom PIL import Image im = Image.open('testimage.jpg') im.rotate(45).show()Output

Cropping an image using the Pillow library

Prasad Naik
Updated on 17-Mar-2021 08:46:10

188 Views

In this program, we will crop an image using the Pillow library. We will use the crop() function for the same. The function takes left, top, right, bottom pixel coordinates to crop the image.Original ImageAlgorithmStep 1: Import Image from Pillow. Step 2: Read the image. Step 3: Crop the image using the crop function. Step 4: Display the output.Example Codefrom PIL import Image im = Image.open('testimage.jpg') width, height = im.size left = 5 top = height / 2 right = 164 bottom = 3 * height / 2 im1 = im.crop((left, top, right, bottom)) im1.show()Output

Loading and displaying an image using the Pillow library

Prasad Naik
Updated on 17-Mar-2021 08:46:35

139 Views

In this program, we will read or load an image using the pillow library. The pillow library consists of a method called Image.open(). This function takes the file path or the name of the file as a string. To display the image, we use another function show(). It does not require any parameter.Example Codefrom PIL import Image im = Image.open('testimage.jpg') im.show()Output

Finding edges in an image using Pillow

Prasad Naik
Updated on 17-Mar-2021 08:37:53

1K+ Views

In this program, we will find the edges in an image using the pillow library. The FIND_EDGES function in the ImageFilter class helps us to find the edges in our image.Original ImageAlgorithmStep 1: Import Image and ImageFilter from Pillow. Step 2: Open the image. Step 3: Call the filter function and specify the find_edges function. Step 4: Display the output.Example Codefrom PIL import Image, ImageFilter im = Image.open('testimage.jpg') im = im.filter(ImageFilter.FIND_EDGES) im.show()Output

Calculating the mean of all pixels for each band in an image using the Pillow library

Prasad Naik
Updated on 17-Mar-2021 08:27:40

2K+ Views

In this program, we will calculate the mean of all the pixels in each channel using the Pillow library. There are a total three channels in an image and therefore, we will get a list of three values.Original ImageAlgorithmStep 1: Import the Image and ImageStat libraries. Step 2: Open the image. Step 3: Pass the image to the stat function of the imagestat class. Step 4: Print the mean of the pixels.Example Codefrom PIL import Image, ImageStat im = Image.open('image_test.jpg') stat = ImageStat.Stat(im) print(stat.mean)Output[76.00257724463832, 69.6674300254453, 64.38017448200654]

Calculating the median of all pixels for each band in an image using the Pillow library

Prasad Naik
Updated on 17-Mar-2021 08:16:31

667 Views

In this program, we will calculate the MEDIAN of all the pixels in each channel using the Pillow library. There are a total 3 channels in an image and therefore we will get a list of three values.Original ImageAlgorithmStep 1: Import the Image and ImageStat libraries. Step 2: Open the image. Step 3: Pass the image to the stat function of the imagestat class. Step 4: Print the median of the pixels.Example Codefrom PIL import Image, ImageStat im = Image.open('image_test.jpg') stat = ImageStat.Stat(im) print(stat.median)Output[41, 43, 40]

Advertisements