Filtering Image Data
An image filter is an object that performs
transformations on image data. The Java 2D API supports image filtering
through the BufferedImageOp
interface. An image filter takes a BufferedImage as input (the source
image) and performs some processing on the image data,
producing another BufferedImage (the
destination image).
The 2D API comes with a handy toolbox of BufferedImageOp implementations, as summarized
in Table 21-1.
Table 21-1. Image operators in the 2D API
Name | Description |
|---|---|
| Transforms an image geometrically |
| Converts from one color space to another |
| Performs a convolution, a mathematical operation that can be used to blur, sharpen, or otherwise process an image |
| Uses one or more lookup tables to process image values |
| Uses multiplication to process image values |
Let’s take a look at two of the simpler image operators. First, try the following application. It loads an image (the first command-line argument is the filename) and processes it in different ways as you select items from the combo box. The application is shown in Figure 21-6.

Figure 21-6. The ImageProcessor application
Here’s the source code:
//file: ImageProcessor.javaimportjava.awt.*;importjava.awt.event.*;importjava.awt.geom.*;importjava.awt.image.*;importjavax.swing.*;publicclassImageProcessorextendsJComponent{private ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access