com.jhlabs.image

Class PerspectiveFilter

Implemented Interfaces:
BufferedImageOp, Cloneable

public class PerspectiveFilter
extends TransformFilter

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, NEAREST_NEIGHBOUR, RGB_CLAMP, WRAP, ZERO, edgeAction, interpolation, originalSpace, transformedSpace

Constructor Summary

PerspectiveFilter()
Construct a PerspectiveFilter.
PerspectiveFilter(float x0, float y0, float x1, float y1, float x2, float y2, float x3, float y3)
Construct a PerspectiveFilter.

Method Summary

BufferedImage
filter(BufferedImage src, BufferedImage dst)
Rectangle2D
getBounds2D(BufferedImage src)
boolean
getClip()
float
getOriginX()
Get the origin of the output image.
float
getOriginY()
Get the origin of the output image.
Point2D
getPoint2D(Point2D srcPt, Point2D dstPt)
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.
void
setClip(boolean clip)
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.
String
toString()
protected void
transformInverse(int x, int y, float[] out)
protected void
transformSpace(Rectangle rect)
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.

Methods inherited from class com.jhlabs.image.TransformFilter

filter, filterPixelsNN, getEdgeAction, getInterpolation, setEdgeAction, setInterpolation, transformInverse, transformSpace

Methods inherited from class com.jhlabs.image.AbstractBufferedImageOp

clone, createCompatibleDestImage, getBounds2D, getPoint2D, getRGB, getRenderingHints, 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 corner
y0 - the new position of the top left corner
x1 - the new position of the top right corner
y1 - the new position of the top right corner
x2 - the new position of the bottom right corner
y2 - the new position of the bottom right corner
x3 - the new position of the bottom left corner
y3 - the new position of the bottom left corner

Method Details

filter

public BufferedImage filter(BufferedImage src,
                            BufferedImage dst)
Overrides:
filter in interface TransformFilter

getBounds2D

public Rectangle2D getBounds2D(BufferedImage src)
Overrides:
getBounds2D in interface AbstractBufferedImageOp

getClip

public boolean getClip()

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.

getPoint2D

public Point2D getPoint2D(Point2D srcPt,
                          Point2D dstPt)
Overrides:
getPoint2D in interface AbstractBufferedImageOp

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 corner
y0 - the old position of the top left corner
x1 - the old position of the top right corner
y1 - the old position of the top right corner
x2 - the old position of the bottom right corner
y2 - the old position of the bottom right corner
x3 - the old position of the bottom left corner
y3 - the old position of the bottom left corner

setClip

public void setClip(boolean clip)

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 corner
y0 - the new position of the top left corner
x1 - the new position of the top right corner
y1 - the new position of the top right corner
x2 - the new position of the bottom right corner
y2 - the new position of the bottom right corner
x3 - the new position of the bottom left corner
y3 - the new position of the bottom left corner

toString

public String toString()

transformInverse

protected void transformInverse(int x,
                                int y,
                                float[] out)
Overrides:
transformInverse in interface TransformFilter

transformSpace

protected void transformSpace(Rectangle rect)
Overrides:
transformSpace in interface TransformFilter

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 corner
y0 - the new position of the top left corner
x1 - the new position of the top right corner
y1 - the new position of the top right corner
x2 - the new position of the bottom right corner
y2 - the new position of the bottom right corner
x3 - the new position of the bottom left corner
y3 - the new position of the bottom left corner