[Image-SIG] Where do these methods come from?

Philipp Bender lists at rootiniert.de
Thu Jan 21 01:11:26 CET 2010


Hi there,

I am confused of the PIL code, I tried to write a custom non-linear filter 
that's the reason why I took a look.

Can someone give me a hint how this works:

ImageFilter.py, class RankFilter:

In the method "filter" which takes an image (which is obviously an Image()?) a 
method "image.rankfilter" is called. I cannot call this method on an image I 
e.g. loaded from a file and can't find it elsewhere in the code.

$ fgrep rankfilter *

returned only this file and on a *.so. Is that the key? Does "rankfilter" call 
a C-function which cannot be found in Python-code?

The other thing I originally planned was to write an own filter. I started 
with:

####

import Image
from ImageFilter import *

class BinomialFilter(Filter):

    name = "BinomialFilter"
    
    def __init__(self, scale=1):
        self.scale = 16
        self.offset = 1
        self.filtermatrix = [[1, 2, 1],[2, 4, 2],[1, 2, 1]]
        
    def filter(self, image):
        # convert to grayscale
        im = image.convert("L")
        return im

im = Image.open("/tmp/pic.jpg")
im.filter(BinomialFilter()).show()

###

which I thought should return me a grayscale image. But it returns a coloured 
image. What's wrong here?

Thank you for any advice,
Regards,
Philipp Bender


More information about the Image-SIG mailing list