P. 1
ProgrammingJavaTMAdvanced Imaging

ProgrammingJavaTMAdvanced Imaging

|Views: 30|Likes:

More info:

Published by: Optionz Sick's Banditz on Jul 05, 2012
Copyright:Attribution Non-commercial

Availability:

Read on Scribd mobile: iPhone, iPad and Android.
download as PDF, TXT or read online from Scribd
See more
See less

12/24/2013

pdf

text

original

ThelineargeometrictransformationsdescribedinSection8.3,“Geometric
Transformation,”cannotintroducecurvatureinthemappingprocess.Image
warpingisatypeofgeometrictransformationthatintroducescurvatureintothe
mappingprocess.Theintroductionofcurvatureisimportantwhenanimagehas
beendistortedthroughlensaberrationsandothernon-linearprocesses.

Warpingtransformations,alsoknownasrubbersheettransformations,can
arbitrarilystretchtheimageaboutdefinedpoints.Thistypeofoperationprovides
anonlineartransformationbetweensourceanddestinationcoordinates.

JAIprovidesatransformationclass,Warp,thatisusedfornon-linearimage
coordinatetransformation.AsintheInterpolationclass(seeSection8.2,
“Interpolation”),pixelpositionsintheWarpclassarerepresentedusingfixed-
pointcoordinates,yieldingsubpixelaccuracybutstillallowingtheuseofinteger
arithmetic.ThedegreeofprecisionissetbymeansofthegetSubSampleBitsH
(horizontal)andgetSubSampleBitsV(vertical)parameterstothewarpRect
method.

// Set the shear direction:
// 0 = SHEAR_HORIZONTAL
// 1 = SHEAR_VERTICAL
int shear_dir = 1;

// Set the shear value and the x and y translation values.
float shear_amt = 0.7F;
float x_trans = 50.0F;
float y_trans = 100.0F;

// Create the Shear operation.
PlanarImage im2 = (PlanarImage)JAI.create("shear",

im0,
shear_amt,
shear_dir,
x_trans,
y_trans,
interp);

// Display the image.
imagePanel2 = new ScrollingImagePanel(im2, 512, 512);
add(imagePanel2);
pack();
show();

Listing8-7ExampleShearOperation(Continued)

8.7

Warping

GEOMETRIC IMAGE MANIPULATION

286

Programming in Java Advanced Imaging

ThekeymethodofthisclassiswarpRect,whichprovidesthelocationsofthe
pixelsinsourcespacethatmaptoagivenrectangularoutputregion.Theoutput
regionisspecifiedusingnormalinteger(fullpixel)coordinates.Thesource
positionsreturnedbythemethodarespecifiedinfixed-point,subpixel
coordinates.

JAIsupportssevenwarpingfunctions:

•Polynomial warp – a polynomial-based description of an image warp
(WarpPolynomial).

•Generalpolynomialwarp–ageneralpolynomial-baseddescriptionofan
image warp (WarpGeneralPolynomial).

•Gridwarp–aregulargrid-baseddescriptionofanimagewarp(WarpGrid).

•Quadratic warp – a quadratic-based description of an image warp
(WarpQuadratic).

•Cubic warp – a cubic-based description of an image warp (WarpCubic).

•Perspective warp – a perspective (projective) warp (WarpPerspective).

•Affine warp – affine-based warp (WarpAffine).

API:javax.media.jai.Warp

int[] warpRect(int x, int y, int width, int height,
intsubsampleBitsH, int subsampleBitsV, int[] destRect)

computes the source subpixel positions for a given rectangular destination
region. The destination region is specified using normal integral (full pixel)
coordinates.Thesourcepositionsreturnedbythemethodarespecifiedinfixed
point,subpixelcoordinatesusingthecurrentvalueofgetSubsampleBitsH()
andgetSubsampleBitsV().

Parameters:

x

Theminimumxcoordinateofthe
destinationregion.

y

Theminimumycoordinateofthe
destinationregion.

width

Thewidthofthedestinationregion.

height

Theheightofthedestinationregion.

subsampleBitsHThenumberoffractionalbitsusedto
specifyhorizontaloffsetsinthe
warpPositionsdata.

GEOMETRIC IMAGE MANIPULATION

Warping

287

Release 1.0.1, November 1999

As a convenience, an implementation is provided for this method that calls
warpSparseRect(). Subclasses may wish to provide their own
implementations for better performance.

float[] warpRect(int x, int y, int width, int height,
float[]destRect)

computes the source subpixel positions for a given rectangular destination
region. The destination region is specified using normal integral (full pixel)
coordinates. The source positions returned by the method are specified in
floating point.

As a convenience, an implementation is provided for this method that calls
warpSparseRect(). Subclasses may wish to provide their own
implementations for better performance.

int[] warpPoint(int x, int y, int subsampleBitsH,
intsubsampleBitsV, int[] destRect)

computes the source subpixel position for a given destination pixel. The
destinationpixelisspecifiedusingnormalintegral(fullpixel)coordinates.The
source position returned by the method is specified in fixed point, subpixel
coordinates using thesubsampleBitsH andsubsampleBitsV parameters.

As a convenience, an implementation is provided for this method that calls
warpSparseRect(). Subclasses may wish to provide their own
implementations for better performance.

float[] warpPoint(int x, int y, float[] destRect)

computes the source subpixel position for a given destination pixel. The
destinationpixelisspecifiedusingnormalintegral(fullpixel)coordinates.The
source position returned by the method is specified in floating point.

As a convenience, an implementation is provided for this method that calls
warpRect(). Subclasses may wish to provide their own implementations for
better performance.

subsampleBitsVThenumberoffractionalbitsusedto
specifyverticaloffsetsinthe
warpPositionsdata.

destRect

Anintarraycontainingatleast
2*width*heightelements,ornull.Ifnull,
anewarraywillbeconstructed.

8.7

Warping

GEOMETRIC IMAGE MANIPULATION

288

Programming in Java Advanced Imaging

int[] warpSparseRect(int x, int y, int width, int height,
intperiodX, int periodY, int subsampleBitsH,
intsubsampleBitsV, int[] destRect)

computes the source subpixel positions for a given rectangular destination
region,subsampledwithanintegralperiod.Thedestinationregionisspecified
usingnormalintegral(fullpixel)coordinates.Thesourcepositionsreturnedby
the method are specified in fixed point, subpixel coordinates using the
subsampleBitsH andsubsampleBitsV parameters.

As a convenience, an implementation is provided for this method that calls
warpSparseRect()withafloatdestRectparameter.Subclassesmaywishto
provide their own implementations for better performance.

abstract float[] warpSparseRect(int x, int y, int width,
intheight, int periodX, int periodY, float[] destRect)

computes the source subpixel positions for a given rectangular destination
region,subsampledwithanintegralperiod.Thedestinationregionisspecified
usingnormalintegral(fullpixel)coordinates.Thesourcepositionsreturnedby
the method are specified in floating point.

Parameters:

x

TheminimumXcoordinateofthe
destinationregion.

y

TheminimumYcoordinateofthe
destinationregion.

width

Thewidthofthedestinationregion.

height

Theheightofthedestinationregion.

periodX

Thehorizontalsamplingperiod.

periodY

Thehorizontalsamplingperiod.

subsample-

BitsH

Thenumberoffractionalbitsusedto
specifyhorizontaloffsetsinthe
warpPositionsdata.

subsample-

BitsV

Thenumberoffractionalbitsusedto
specifyverticaloffsetsinthe
warpPositionsdata.

destRect

Anintarraycontainingatleast

elements,ornull.Ifnull,anewarraywill
beconstructed.

2widthperiodX1

+
periodX

------------------------------------------------heightperiodY1

+
periodY

--------------------------------------------------

×

GEOMETRIC IMAGE MANIPULATION

Performing a Warp Operation

289

Release 1.0.1, November 1999

This method is abstract in this class and must be provided in concrete
subclasses.

Rectangle mapDestRect(Rectangle destRect)

computesarectanglethatisguaranteedtoenclosetheregionofthesourcethat
is required in order to produce a given rectangular output region. The routine
may return null if it is infeasible to compute such a bounding box.

The default (superclass) implementation returns null.

You're Reading a Free Preview

Download
scribd
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->