Java Reference
In-Depth Information
filter classes are included in the java.awt.image package and you can also
create your own in a straightforward manner. The filter classes implement the
java.awt.image.BufferedImageOp interface. This interface holds five
methods but the most important is
public BufferedImage filter (BufferedImage source - image,
BufferedImage dest - image)
This method acts upon but does not change the source - image and creates the
processed image. If the destination image reference ( dest - image )isnot null ,
then the filter uses this image object to hold the processed image. If it is null ,
then the filter creates a new image object and returns it as the method return
value. In some filters, but not all, the source and destination images can be the
same. (This is referred to as in-place filtering.)
The five filtering classes provided with the java.awt.image package
include:
ConvolveOP - convolution filter that applies a given kernel operator to the image data
for edge detection, sharpening, and other effects.
AffineTransformOp -affine transforms include translation, scaling, flipping, rota-
tion, and shearing. These map 2D structures in one space to another space while main-
taining straight lines and the parallelism of the original image.
LookupOp - instances of LookupTable are used to map source pixels to destination
pixels according to the pixel component values (cannot be used with indexed color model
images). Provides color transformation effects such as the inversion of gray scales.
RescaleOp - apply a scaling factor to the color components so as to brighten or dim
an image.
ColorConvertOp - change to a different color space such as converting a color image
to a grey scale image.
In the following sections we discuss these filters in more detail. See Chapter 11
in the Web Course for demonstration programs for each filter type.
11.9.1 Convolution
The convolution filter applies a kernel operator to the 2D image matrix. The kernel
consists of a small square matrix (typically 3
3) that scans across the image
matrix. The kernel is centered on a pixel and each kernel element multiplies the
image pixel that it overlaps. The sum of these products for each color component
then determines the new value of the pixel at the center of the kernel. (Lower
limit on the sum is 0 and upper limit is 255 for RGB type pixels.)
Forexample, an edge detection kernel could consist of this 3
×
×
3 matrix:
0.0
1.0
0.0
1.0
4.0
1.0
0.0
1.0
0.0
Search WWH ::




Custom Search