Python, PIL and Gaussian Blur

I have been searching high and low for a good gaussian blur for Python, I looked at ScyPy, Numpy, a bunch of random hand-coded versions around the internet, and it turns out that there's one built into PIL (v1.1.5). Not sure how fast it is compared to other versions, but the important part for me is, it's there. Just not documented (that I could find...)

The other problem

Turns out, if you look at the source, ImageFilter.py line 156(ish).

class GaussianBlur(Filter):
    name = "GaussianBlur"

    def __init__(self, radius=2):
        self.radius = 2
    def filter(self, image):
        return image.gaussian_blur(self.radius)

...but if you look closely under the constructor, self.radius isn't assigned to the value passed into to method, it's hard-coded to 2!!! Blasphemy!

So I borrowed theirs and fixed it:

class MyGaussianBlur(ImageFilter.Filter):
    name = "GaussianBlur"

    def __init__(self, radius=2):
        self.radius = radius
    def filter(self, image):
        return image.gaussian_blur(self.radius)

Sweetness, gaussian blur for PIL.

af

Posted

May 28, 2011
by AnonymousUser

Categories

General Posts

Tags

pil
python