Re: need some help with custom filter in Photoshop

From: Anders Thulin (ath_no_spam_please_at_algonet.se)
Date: 02/27/05


Date: Sun, 27 Feb 2005 08:42:55 GMT

Blaine Waddington wrote:

> I keep running into these "custom" or kernal filters in Photoshop and other
> programs but, try as I might, I have been unable to find good tutorials as
> to how they work with some practical input values.

   A textbook in image processing perhaps? *Real* image processing, not
image editing or synthesizing. (I remember Gonzales & Wintz from way back, but
Gonzales & Woods probably replaces that nowadays.)

   Kernels are square arrays (typically of odd sizes, like 3x3) containing a
number of specially selected coeffiecents. The size is the 'input area',
the coefficients the weighting of the corresponding pixels in the input image,
and the actual function being performed over these pixels is typically
summing follwoed by a scaling operation implicit in the kernel. Output is
one single pixel orresponding to the center of the kernel.

   Processing is done by placing the kernel in all possible positions on the
input image, and creating an output image from the input pixels. (image
edges get special treatment.) For example (3x3 kernel, with coordinate [0,0] in the center):

   out[x,y] := sum of (in[x-1,y-1]*kernel[-1,-1], ..., in[x+1,y+1]*kernel[1,1]);

Each pixel gets multiplied with the corresponding kernel coefficient, and the result is
summed.

   If the kernel is all 1, and you add a division by 9 at the end, this is a simple
averaging filter (remember, pixels are from input image only). By changing the kernel,
you can weight pixels to influence the outcome more (though you may need to change the
9 accordingly). For instance, corner pixels may get weight 1, orthogonal pixels weight
4, central pixel weight 9 -- this filter is slightly more spatially sensitive than
the 'all 1' one.

   You can also use kernels for feature detection, such as edge detection.

   If kernel is [[-1,-1,-1],[-1,8,-1],[-1,-1,-1]], you'll get a
resulting image that is all edges from the original image, i.e. places
where a low pixel value was next to a high pixel, regardless of direction
(though within the spatial limitations of a 3x3 kernel).

   If you change that to [-1,8,-1][-1,8,-1][-1,8,-1], you'll
enhance narrow vertical lines. Typically, the results from several
such 'convolutions' are combined for further processing, and possibly
even used as input images for higher-level convolutions.

   3x3 pixels are a bit too primitive, though -- 5x5 or 7x7 often makes for
better results, but of course requires much more processing power.
For these sizes, you need hardware assist ... or specialized hardware.
In a past life, I worked with a company where 11x11 kernels were thought
of as barely useful -- 19x19 and above were more like real life.

   If you want to go deeper, look for the term 'convolution' in the context
of image processing. You may need some math background, though.

-- 
Anders Thulin     ath*algonet.se     http://www.algonet.se/~ath


Relevant Pages

  • Re: Filtering kernel width
    ... , how wide should the window be, ... function leaves a realizable filter of finite size: ... However it doesn't seem to really explain how many pixels you ... Assume a 1D binomial kernel ...
    (comp.graphics.algorithms)
  • Re: what is the Nyuist rate of an image?
    ... Do you mean to shift by 0.5 of the diagonal distance between pixels in a ... Use the 1D kernel only in the diagonal direction to directly shift. ...
    (sci.image.processing)
  • Re: Determining the Shape of Pixels and Frames
    ... give us the link to your MVP public profile... ... Yes the pixels would still be non-square ... ... When such a DV AVI video is displayed in Media Player the ... 720x480 input image is mapped to an area of 640x426 within the frame of size ...
    (microsoft.public.windowsxp.moviemaker)
  • Java2D Image Manipulation!
    ... First of all, I'm creating an image manipulation software, for image ... Is BufferedImage enough? ... On the other hand, if I use the Kernel methods, can I choose the ... number of pixels that are too bright) if the image is not in memory (is ...
    (comp.lang.java.gui)
  • Re: Magic kernel for image zoom resampling?
    ... with filters and sinc functions, didn't do a good job of it, and went ... pixels in the upsampled image, or in other words that the kernel, from ... the upsampled image's point of view, is 3m pixels wide. ... The parabolas on either end reduce to zero at the extremes. ...
    (sci.image.processing)

Loading