Blurring images containing text using Python Imaging Library

python, python-imaging-library

Solution

`BLUR` is just a preset on `ImageFilter.Kernel`:

class BLUR(BuiltinFilter):
    name = "Blur"
    filterargs = (5, 5), 16, 0, (
        1,  1,  1,  1,  1,
        1,  0,  0,  0,  1,
        1,  0,  0,  0,  1,
        1,  0,  0,  0,  1,
        1,  1,  1,  1,  1
        )

where BuiltinFilter is a simple customization subclass of Kernel that bypasses the constructor, `filterargs` contains `size`, `scale`, `offset`, `kernel`. In other words, `BLUR` in the equivalent of:

BLUR = Kernel((5, 5), (1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1, 1, 1, 1, 1))

The scale is set to the default (`16`, the sum of the 25 weights), as is the offset.

You could try and use a smaller kernel instead:

mildblur = Kernel((3, 3), (1, 1, 1, 1, 0, 1, 1, 1, 1))

or play with the scale and offset values.

Problem

I have an image containing some text (in a standard document font-size) and I am trying to blur the image so that the text is no longer readable. However the default ImageFilter.BLUR in PIL is too strong, so the image is just blanked out save for a single pixle here and there. Is there a weaker BLUR somewhere in PIL? Or is there a better filter / a better way?

Original source