Package com.jhlabs.image
Class PerspectiveFilter
java.lang.Object
com.jhlabs.image.AbstractBufferedImageOp
com.jhlabs.image.TransformFilter
com.jhlabs.image.PerspectiveFilter
- All Implemented Interfaces:
BufferedImageOp,Cloneable
A filter which performs a perspective distortion on an image.
Coordinates are treated as if the image was a unit square, i.e. the bottom-right corner of the image is at (1, 1).
The filter maps the unit square onto an arbitrary convex quadrilateral or vice versa.
-
Field Summary
Fields inherited from class com.jhlabs.image.TransformFilter
BILINEAR, CLAMP, edgeAction, interpolation, NEAREST_NEIGHBOUR, originalSpace, RGB_CLAMP, transformedSpace, WRAP, ZERO -
Constructor Summary
ConstructorsConstructorDescriptionConstruct a PerspectiveFilter.PerspectiveFilter(float x0, float y0, float x1, float y1, float x2, float y2, float x3, float y3) Construct a PerspectiveFilter. -
Method Summary
Modifier and TypeMethodDescriptionfilter(BufferedImage src, BufferedImage dst) getBounds2D(BufferedImage src) booleangetClip()floatGet the origin of the output image.floatGet the origin of the output image.getPoint2D(Point2D srcPt, Point2D dstPt) voidquadToUnitSquare(float x0, float y0, float x1, float y1, float x2, float y2, float x3, float y3) Set the transform to map a quadrilateral onto the unit square.voidsetClip(boolean clip) voidsetCorners(float x0, float y0, float x1, float y1, float x2, float y2, float x3, float y3) Set the new positions of the image corners.toString()protected voidtransformInverse(int x, int y, float[] out) Inverse transform a point.protected voidtransformSpace(Rectangle rect) Forward transform a rectangle.voidunitSquareToQuad(float x0, float y0, float x1, float y1, float x2, float y2, float x3, float y3) Set the transform to map the unit square onto a quadrilateral.Methods inherited from class com.jhlabs.image.TransformFilter
filterPixelsNN, getEdgeAction, getInterpolation, setEdgeAction, setInterpolationMethods inherited from class com.jhlabs.image.AbstractBufferedImageOp
clone, createCompatibleDestImage, getRenderingHints, getRGB, setRGB
-
Constructor Details
-
PerspectiveFilter
public PerspectiveFilter()Construct a PerspectiveFilter. -
PerspectiveFilter
public PerspectiveFilter(float x0, float y0, float x1, float y1, float x2, float y2, float x3, float y3) Construct a PerspectiveFilter.- Parameters:
x0- the new position of the top left cornery0- the new position of the top left cornerx1- the new position of the top right cornery1- the new position of the top right cornerx2- the new position of the bottom right cornery2- the new position of the bottom right cornerx3- the new position of the bottom left cornery3- the new position of the bottom left corner
-
-
Method Details
-
setClip
public void setClip(boolean clip) -
getClip
public boolean getClip() -
setCorners
public void setCorners(float x0, float y0, float x1, float y1, float x2, float y2, float x3, float y3) Set the new positions of the image corners. This is the same as unitSquareToQuad, but the coordinates are in image pixels, not relative to the unit square. This method is provided as a convenience.- Parameters:
x0- the new position of the top left cornery0- the new position of the top left cornerx1- the new position of the top right cornery1- the new position of the top right cornerx2- the new position of the bottom right cornery2- the new position of the bottom right cornerx3- the new position of the bottom left cornery3- the new position of the bottom left corner
-
unitSquareToQuad
public void unitSquareToQuad(float x0, float y0, float x1, float y1, float x2, float y2, float x3, float y3) Set the transform to map the unit square onto a quadrilateral. When filtering, all coordinates will be scaled by the size of the image.- Parameters:
x0- the new position of the top left cornery0- the new position of the top left cornerx1- the new position of the top right cornery1- the new position of the top right cornerx2- the new position of the bottom right cornery2- the new position of the bottom right cornerx3- the new position of the bottom left cornery3- the new position of the bottom left corner
-
quadToUnitSquare
public void quadToUnitSquare(float x0, float y0, float x1, float y1, float x2, float y2, float x3, float y3) Set the transform to map a quadrilateral onto the unit square. When filtering, all coordinates will be scaled by the size of the image.- Parameters:
x0- the old position of the top left cornery0- the old position of the top left cornerx1- the old position of the top right cornery1- the old position of the top right cornerx2- the old position of the bottom right cornery2- the old position of the bottom right cornerx3- the old position of the bottom left cornery3- the old position of the bottom left corner
-
filter
- Specified by:
filterin interfaceBufferedImageOp- Overrides:
filterin classTransformFilter
-
transformSpace
Description copied from class:TransformFilterForward transform a rectangle. Used to determine the size of the output image.- Overrides:
transformSpacein classTransformFilter- Parameters:
rect- the rectangle to transform
-
getOriginX
public float getOriginX()Get the origin of the output image. Use this for working out where to draw your new image.- Returns:
- the X origin.
-
getOriginY
public float getOriginY()Get the origin of the output image. Use this for working out where to draw your new image.- Returns:
- the Y origin.
-
getBounds2D
- Specified by:
getBounds2Din interfaceBufferedImageOp- Overrides:
getBounds2Din classAbstractBufferedImageOp
-
getPoint2D
- Specified by:
getPoint2Din interfaceBufferedImageOp- Overrides:
getPoint2Din classAbstractBufferedImageOp
-
transformInverse
protected void transformInverse(int x, int y, float[] out) Description copied from class:TransformFilterInverse transform a point. This method needs to be overriden by all subclasses.- Specified by:
transformInversein classTransformFilter- Parameters:
x- the X position of the pixel in the output imagey- the Y position of the pixel in the output imageout- the position of the pixel in the input image
-
toString
-