# Applying rank filter to an image using the Pillow library

PillowPythonServer Side ProgrammingProgramming

In this program, we will blur an image using a rank filter. The ImageFilter class in the pillow library contains a function called RankFilter() which helps to apply the rank filter. It takes two parameters, size of the kernel and rank. Rank is 0 for a min filter, size*size/2 for a median filter and size*size-1 for a max filter.

## Algorithm

Step 1: Import Image and ImageFilter from Pillow.
Step 2: Open the image.
Step 3: Call the rankfilter() method and specify the size and rank.
Step 4: Display the output.

## Example Code

from PIL import Image, ImageFilter

im = Image.open('image_test.jpg')
im1 = im.filter(ImageFilter.RankFilter(7, 0))
im1.show()

## Output

Published on 18-Mar-2021 07:16:22