|
Photoshop and other graphics packages support custom image filters. By specifying a small table of numbers, many simple effects can be achieved. Depending on the graphics application, the filter dialog should look something like this.
The dialog consists of a table of 25 weights, a scale value, and an offset value. These values are all integers. Fractional numbers (e.g. 2.5) are not allowed. The filter visits each pixel in the image sequentially, and for each pixel, a filtering formula is applied. The current pixel in the process is represented by the middle box in the table. The box immediately to the right represents the pixel immediately to the right of the current pixel. The box below center represents the pixel below the current pixel, and so on. Each one of these boxes has a number value indicating a weight. If the box is empty a weight of zero is assumed (which means it's not used in the calculation). The current pixel and its 24 neighbors are multiplied by their corresponding weights, and these products are then added together. This value is divided by the "scale" value, and finally the "offset" is added at the end. This value is the result of the filter, and it is done separately for each channel in the image (e.g. red, green, and blue) and for each pixel in the image. The results of the filter are stored in a separate image buffer until the process is complete, so the pixel values used in the calculation are always from the original image, never from previously filtered pixels. In other words, there is no "feedback" in the filtering process. Consider the following example filter:
You can read this formula as, the filtered pixel at the coordinates (x,y) is the value of the original pixel at (x,y) minus the value of the original pixel at (x-1, y-1) plus 128. The unfilled parts of the table are not included in the calculation. For the mathematically inclined, the general equation for a custom filter can be expressed in the following form.
where i is each column of the filter table and j is each row. The weighti,j is the value entered in the table at cell (i,j). Even if the math seems daunting, it's worth playing around with different values to get a feel for how it works. Here are a few general rules for creating a custom filter that doesn't just produce a mess. These are only guidelines, so feel free to bend the rules.
Lastly, here are a few examples of working custom filters and a sample image showing what the effect looks like.
Sample image: "Femmes de Tahiti [Sur la plage] (Tahitian Women [On the Beach])," painted by Eugène-Henri Paul Gauguin in 1891. |