pythonware.com ::: library ::: Python Imaging Library Handbook (2003 Edition)

Back   Next

On this page:
Example
Filters

The ImageFilter Module

The ImageFilter module contains definitions for a pre-defined set of filters, which can be be used in conjuction with the filter method of the Image class.

Example

Filter an Image
import ImageFilter

im1 = im.filter(ImageFilter.BLUR)

im2 = im.filter(ImageFilter.MinFilter(3))
im3 = im.filter(ImageFilter.MinFilter) # same as MinFilter(3)

Filters

The current version of the library provides the following set of predefined image enhancement filters:

BLUR, CONTOUR, DETAIL, EDGE_ENHANCE, EDGE_ENHANCE_MORE, EMBOSS, FIND_EDGES, SMOOTH, SMOOTH_MORE, and SHARPEN.

Kernel

Kernel(size, kernel, scale=None, offset=0)

(New in 1.1.5) Create a convolution kernel of the given size. In the current version, the size must be either (3, 3) or (5, 5), and the kernel argument must be a sequence containing 9 or 25 integer or floating point weights.

If the scale argument is given, the result of applying the kernel to each pixel is divided by the scale value. The default is the sum of the kernel weights.

If the offset argument is given, the value is added to the result, after it has been divided by the scale.

RankFilter

RankFilter(size, rank)

(New in 1.1.5) Create a rank filter of the given size. For each pixel in the input image, the rank filter sorts all pixels in a (size, size) environment, and copies the rank'th value to the output image.

MinFilter

MinFilter(size=3)

(New in 1.1.5) Create a min filter of the given size. For each pixel in the input image, this filter copies the smallest pixel value from a (size, size) environment to the output image.

MedianFilter

MedianFilter(size=3)

(New in 1.1.5) Create a min filter of the given size. For each pixel in the input image, this filter copies the smallest pixel value from a (size, size) environment to the output image.

MaxFilter

MaxFilter(size=3)

(New in 1.1.5) Create a max filter of the given size. For each pixel in the input image, this filter copies the largest pixel value from a (size, size) environment to the output image.

Back   Next