How do the PIL ImageFilter enhancement filters work?
Where can I find information on what algorithms the PIL ImageFilter functions use? Like how does edge_enhance work? I'm 开发者_运维技巧looking to implement a difference of Gaussians filter but if PIL has a filter that works similarly I'll use that.
The ImageFilter methods all use kernels convolved with an image to produce the filter effects. Here is good primer on kernel convolution. If you load the ImageFilter module you can figure out the kernels used for each kind of operation by looking at
>>> help(ImageFilter)
For example, for EDGE_ENHANCE_MORE help gives
filterargs = ((3, 3), 1, 0, (-1, -1, -1, -1, 9, -1, -1, -1, -1))
This means that the EDGE_ENHANCE_MORE kernel is size 3x3, scale factor 1, offset 0, and consists of -1 values except for the center value, which is 9. From what I've read it seems like you can create a custom filter (including a difference of Gaussians kernel) by supplying the appropriate arguments to a Kernel object:
Kernel(size, kernel, scale=None, offset=0)
精彩评论