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 18.2.
Table 18-2. Image Operators in the 2D API
|
Name |
Description |
|---|---|
AffineTransformOp |
Transforms an image geometrically |
ColorConvertOp |
Converts from one color space to another |
ConvolveOp |
Performs a convolution, a mathematical operation that can be used to blur, sharpen, or otherwise process an image |
LookupOp |
Uses one or more lookup tables to process image values |
RescaleOp |
Uses a 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 18.6; the source code follows:
//file: ImageProcessor.java import java.awt.*; import java.awt.event.*; import java.awt.geom.*; import java.awt.image.*; import javax.swing.*; public class ImageProcessor extends JComponent { private BufferedImage source, destination; private JComboBox options; public ImageProcessor(BufferedImage image) { source = destination ...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