Content tagged with "pil"

Python, PIL and Gaussian Blur Post on May 28, 2011

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

Lightroom -like histogram in Python Post on Nov 19, 2008

I just added a dynamically-generated histogram to the image items on my site. It's not really usefull information in the context of viewing a photograph, it's more functional when editing, but being the uber-geek that I am, I thought it would still be interesting information to have on my site, right along with the exif data (aperature, focal length, etc).

But not just any histo

I didn't just want a black and white representation of all the image histogram, I wanted something like the pretty histogram in Adobe Photoshop Lightroom:

Lightroom Histogram

All in all the final version took me about 1.5 hours to write in Python using PIL. The semi-tricky part was getting the overlapping colors. It turned out to be about 70 lines of code, and could probably be done much better. On my local Ubuntu install, a typical image histogram is generated in about 5-10 ms, not bad for a skinny white guy :)

Check out an image or two to see the pretty histogram in action :) Next step, drop shadows on the layers...

Cheers, Aaron