Java Reference
In-Depth Information
Forexample, the following code shows how to apply a shearing operation to
an image:
AffineTransform shearer = AffineTransform.getShearInstance
(0.4, 0.0);
AffineTransFormOp shear - op = new AffineTransformOp
(shearer, interpolation);
BufferedImage dest - img = shear - op.filter (source - img, null);
Each point in the source image at ( x,y )movesto ( x+0.4y, y )inthe desti-
nation image.
After an affine transform, a single pixel in a destination image usually does not
correspond directly to a single pixel in the source (i.e. it is split among two or more
destination pixels). So the transforms require an algorithm to determine the colors
of the destination pixels. The interpolation setting allows you to choose between
a nearest neighbor algorithm and a bilinear interpolation algorithm. The nearest
neighbor technique applies the color of the nearest transformed source pixel to the
destination pixel. The bilinear interpolation instead uses a combination of colors
from a set of transformed source pixels around the position of the destination
pixel. (A bicubic option was added with J2SE 5.0.)
Note that these transforms can result in cutting off some parts of the source
image that extend past the borders of the destination image. Also, some opera-
tions, such as a rotation, can leave some areas with zero color values (resulting
in black for RGB images and transparent black for ARGB) where no image data
remains.
11.9.3 Lookup tables
Lookup tables provide a very flexible approach to transforming the colors of an
image. One can use a lookup table filter, for example, to create a negative of
the source image. The LookupOp filter uses an instance of LookupTable (or,
actually, one of its two subclasses) to map source pixels to destination pixels
according to the source pixel component values. Note that this filter cannot be
used with indexed color model images (defined in Section 11.2).
Forexample, the eight bits of the red component for an RGB pixel would need
a table of up to 256 elements, each holding a value for the corresponding red
component in the destination pixel. You can provide one table used by all three
components or separate tables for each (four tables for ARGB pixels).
There are two subclasses of the abstract LookupTable . The ByteLookup-
Table and the ShortLookupTable essentially offer the same features except
for the type of arrays. Each provides a constructor for creating a single table for
all color components and a constructor for creating multiple tables, one for each
color component.
Search WWH ::




Custom Search