Pillow's ImageFilter.MinFilter class provides the implementation of a minimum filter. It is a dilating filter which expands the darker objects present in an Image. The python example applies the minimum filter twice to an image and displays the output images.
When the minimum filter is applied to a digital image it picks up the minimum value of the neighbourhood pixel window and assigns it to the current pixel. A pixel with the minimum value is the darkest among the pixels present in the pixel window.
The dark values present in an image are enhanced by the minimum filter.
Minimum filter is also called as a dilation filter. When minimum filter is applied the object boundaries present in an image are extended.
The minimum filter is one of the morphological filters. The other morphological filters include maximum filter and the median filter.
The minimum filter removes any positive outlier noise present in a digital image.
Example
python
# -----Python example program for applying minimum filter to a Digital Image-----
# import the required PIL Modules
from PIL import Image
from PIL import ImageFont
from PIL import ImageDraw
from PIL import ImageFilter
# Draw text on the image
def writeText(baseImage, imageDescription, textSize, textX, textY, fontFileLocation):
baseImage = baseImage.convert('RGBA');
textImage = Image.new('RGBA', baseImage.size, (255,255,255,0));
# Select a font for the text
font = ImageFont.truetype(fontFileLocation, textSize);
draw = ImageDraw.Draw(textImage);
draw.text((textX,textY), imageDescription, font=font, fill=(255,255,255,255));
# Do an alpha composite of the two images and return
return Image.alpha_composite(baseImage, textImage);
# Text size and location
textSize = 150;
textX = 20;
textY = 60;
fontFileLocation = "/opt/X11/share/fonts/TTF/luxirr.ttf";
imageFilePath = "./droplets.jpg";
imageText = "Before applying minimum filter:";
# Create an image object from a file
imageInstance = Image.open(imageFilePath);
originalImage = writeText(imageInstance, imageText, textSize, textX, textY, fontFileLocation);
originalImage.show();
# Apply minimum filter twice to the image
minFilter1x = imageInstance.filter(ImageFilter.MinFilter);
imageText = "Minimum filter-1x:";
min1xWithText = writeText(minFilter1x, imageText, textSize, textX, textY, fontFileLocation);
minFilter2x = minFilter1x.filter(ImageFilter.MinFilter);
imageText = "Minimum filter-2x:";
min2xWithText = writeText(minFilter2x, imageText, textSize, textX, textY, fontFileLocation);
min1xWithText.show();
min2xWithText.show();
Output
Before applying minimum filter
After applying minimum filter 1x times
After applying minimum filter 2x times
Your privacy choices
We'd like to use Google Analytics cookies to count visits and see which tutorials are useful.
They are only set if you accept. We don't use advertising cookies and we don't sell your data.
You can change your choice any time from “Your privacy choices” at the bottom of every page.
Privacy Policy
Your privacy choices
Your browser sent a Global Privacy Control signal, so analytics is off unless you turn it on here.
Strictly necessary
Remembers this choice in your browser. No cookies, nothing sent to anyone.Always on