Java Reference
In-Depth Information
The first
filter()
method call is passed an existing
BufferedImage
instance
named
bi
asitsfirstargument.Itssecondargumentis
null
,whichtells
filter()
to
createanew
BufferedImage
instanceasthedestination.Youcannotpassthesame
BufferedImage
instance as the second argument because
ConvolveOp
doesn't
support in-place filtering for buffered images.
The second
filter()
method call is passed the buffered image's raster (obtained
byinvoking
BufferedImage
's
WritableRaster getRaster()
method)asits
first argument. It is also passed
null
as its second argument because
ConvolveOp
doesn't support in-place filtering for rasters.
Note
Forconvenience,Ifocusonbufferedimage-basedprocessing.Also,Idemon-
stratevariousfilters/imageoperatorsinthecontextofa
BIP
applicationthat'sincluded
with this topic's code.
You can create a blur kernel that blurs an image by combining equal amounts of
source and neighbor pixel component values. The resulting kernel appears here:
float ninth = 1.0f/9.0f;
float[] blurKernel =
{
ninth, ninth, ninth,
ninth, ninth, ninth,
ninth, ninth, ninth
};
Kernel kernel = new Kernel(3, 3, blurKernel);
Figure 7-29
shows the blur kernel's results—compare with
Figure 7-10
.