Optimize with a SATA RAID Storage Solution
Range of capacities as low as $1250 per TB. Ideal if you currently rely on servers/disks/JBODs
If you did any image processing work in JDK 1.0 or 1.1, you probably remember that it was a little obtuse. The old model of
image data producers and consumers is unwieldy for image processing. Before JDK 1.2, image processing involved
PixelGrabbers, and other such arcana. Java 2D, however, provides a cleaner, easier to use model.
This month, we'll examine the algorithms behind several important image-processing operations (ops) and show you how they can be implemented using Java 2D. We'll also show you how these ops are used to affect image appearance.
Because image processing is a genuinely useful standalone application of Java 2D, we've built this month's example, ImageDicer, to be as reusable as possible for your own applications. This single example demonstrates all of the image-processing techniques we'll cover in this month's column.
Note that shortly before this article went to publication, Sun released the Java 1.2 Beta 4 development kit. Beta 4 seems
to give better performance for our example image processing operations, but it also adds some new bugs involving bounds checking
ConvolveOps. These problems affect the edge detection and sharpening examples we use in our discussion.
We think these examples are valuable, so rather than omit them altogether, we compromised: to ensure it runs, the example code reflects the Beta 4 changes, but we've retained the figures from the 1.2 Beta 3 execution so you can see the operations working correctly.
Hopefully, Sun will address these bugs before the final Java 1.2 release.
Image processing doesn't have to be difficult. In fact, the fundamental concepts are really quite simple. An image, after all, is just a rectangle of colored pixels. Processing an image is simply a matter of calculating a new color for each pixel. The new color of each pixel can be based on the existing pixel color, the color of surrounding pixels, other parameters, or a combination of these elements.
The 2D API introduces a straightforward image processing model to help developers manipulate these image pixels. This model
is based on the
java.awt.image.BufferedImage class, and image processing operations like convolution and thresholding are represented by implementations of the
Java 2D's image processing model, based on BufferedImageOps
The implementation of these ops is relatively straightforward. Suppose, for example, that you already have the source image
source. Performing the operation illustrated in the figure above would take only a few lines of code: