Java Reference
In-Depth Information
ConvolveOp lets you perform spatial convolutions (combining source pixel
and neighbor pixel colors/samples) such as blurring and sharpening.
LookupOp lets you modify pixel component values through lookup tables.
RescaleOp multipliespixelcomponentvaluesbyascalefactorandthenadds
anoffsettotheresult.Thisclassisusefulforbrighteninganddarkeningimages
(although lookup tables can be used for this purpose as well).
Caution LookupOp 's Java documentation for its WritableRaster fil-
ter(Raster src, WritableRaster dst) method states that a new raster
is created when you pass null to dst . However, passing null to dst causes
java.lang.NullPointerException to be thrown instead.
Convolving Images
ConvolveOp combines fractions of a source pixel's alpha (when present) and color
components with fractions of its immediate neighbor pixels' components to produce a
destination pixel. The percentage of each pixel's component values to combine is ob-
tainedfromatableoffloating-pointvalues,whichisknownasa kernel .Acomponent's
values are multiplied by the corresponding kernel value and the results are summed.
Eachsumisclampedtoa0/0.0(darkest/transparent)minimumanda255/1.0(brightest/
opaque) maximum.
ConvolveOp moves the kernel across the image to convolve each pixel. The ker-
nel'scentervalue(orthevaluenearestthecenter)appliestothesourcepixelbeingcon-
volved, whereas the other values apply to the neighboring pixels.
The identity kernel hasallvaluessetto0.0exceptforthecentervalue,whichissetto
1.0.Thisspecialkerneldoesn'tchangetheimagebecausemultiplyingthesourcepixel's
component values by 1.0 doesn't change these components, and multiplying neighbor
pixelcomponentvaluesby0.0resultsin0.0values,whichcontributenothingwhenad-
ded to the multiplication results.
Kernelsarerepresentedbyinstancesofthe java.awt.image.Kernel class.To
create a kernel, first create an array of floating-point percentage values, and then pass
thisarrayalongwiththetable'swidth(numberofcolumns)andheight(numberofrows)
to the Kernel(int width, int height, float[] data) constructor.
The following example shows you how to create an identity-based kernel:
float[] identityKernel =
{
0.0f, 0.0f, 0.0f,
Search WWH ::




Custom Search