Java Reference
In-Depth Information
convolutions. We can also work at the pixel level of an image and directly examine
and modify the colors that define each point in an image.
We might want to manipulate an image just to present it in some new and
interesting manner. For example, we could sharpen an image so that it is more
pleasing in appearance. In technical applications, a more common goal of image
processing is to extract some information. For example, we might use a color filter
on a photograph to look for a particular color in the field of view that indicates the
presence of a material or object of interest. An edge detection filter can greatly
simplify a complex scene so that searching for a particular shape in the image is
much easier for pattern recognition tools.
The Java 2D API brought a much expanded array of tools and techniques for
imaging processing. We can only touch upon a handful of these capabilities here.
In the remaining sections we focus primarily on the Java 2D techniques available
with BufferedImage but also look at pixel handling with the basic Image
class.
11.8 Pixel handling
An image in Java consists essentially of an array of data in which each element
describes the color of a point, or pixel ,inthe image. As discussed above, the
interpretation of a value in the array element is determined by a color model.
Both with Image and BufferedImage we can create images from pixel arrays
and also access and modify the pixels of existing images.
11.8.1 ARGB Pixels
Java provides for different color models but the default model is the ARGB color
model where a 32-bit integer value is packed with 8 bits for each of the three
colors (Red, Green, and Blue) and the alpha transparency factor (see Section
6.6.3). The bits are packed as in
Bits 0—7 -blue
Bits 8—15 -green
Bits 16—23 - red
Bits 24—31 - alpha
Yo u can use bit-handling operators (see Chapter 10) to obtain the individual
component values as in the following code where the variable pixel is an int
that contains an ARGB color value:
int alpha = (pixel >> 24) & 0xff;
int red = (pixel >> 16) & 0xff;
int green = (pixel >> 8) & 0xff;
int blue = (pixel)
& 0xff;
Search WWH ::




Custom Search