Class ROIGeometry
- All Implemented Interfaces:
Serializable
ImageN operations often involve converting ROI objects to images. This class implements its getAsImage()
method using the JAITools "VectorBinarize" operator to avoid exhausting available memory when dealing with ROIs that
cover massive image areas.
Note that this class can be used to honour floating precision pixel coordinates by setting the
useFixedPrecision constructor argument to false. The effect of the default fixed coordinate precision
is to provide equivalent behaviour to that of the standard ROIShape, where pixel coordinates are treated as
referring to the upper-left pixel corner.
- Since:
- 1.1
- Author:
- Michael Bedward, Andrea Aime
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final booleanDefault setting for use of anti-aliasing when drawing the referenceGeometryduring agetAsImage()request.static final booleanDefault setting for use of fixed precision (true). -
Constructor Summary
ConstructorsConstructorDescriptionROIGeometry(Rectangle rect) ROIGeometry(Geometry geom) Constructor which takes aGeometryobject to be used as the reference against which to test inclusion of image coordinates.ROIGeometry(Geometry geom, boolean useFixedPrecision) Constructor which takes aGeometryobject and abooleanvalue for whether to use fixed coordinate precision (equivalent to working with integer pixel coordinates).ROIGeometry(Geometry geom, boolean antiAliasing, boolean useFixedPrecision) Constructors a new ROIGeometry.ROIGeometry(Geometry geom, boolean antiAliasing, boolean useFixedPrecision, RenderingHints hints) Fully-specified constructor.ROIGeometry(Geometry geom, RenderingHints hints) Builds a new ROIGeometry. -
Method Summary
Modifier and TypeMethodDescriptionReturns a new instance which is the union of this ROI androi.booleancontains(double x, double y) Tests if this ROI contains the given image location.booleancontains(double x, double y, double w, double h) Tests if this ROI contains the given rectangle.booleancontains(int x, int y) Tests if this ROI contains the given image location.booleancontains(int x, int y, int w, int h) Tests if this ROI contains the given rectangle.booleanTests if this ROI contains the given point.booleancontains(Rectangle2D rect) Tests if this ROI contains the given rectangle.booleanTests if this ROI contains the given point.booleanTests if this ROI contains the given rectangle.exclusiveOr(ROI roi) Returns a new instance which is the exclusive OR of this ROI androi.int[][]getAsBitmask(int x, int y, int width, int height, int[][] mask) Returns a bitmask for a given rectangular region of the ROI indicating whether the pixel is included in the region of interest.Returns the ROI as a JTSGeometry.Gets an image representation of this ROI using theVectorBinarizeoperation.getAsRectangleList(int x, int y, int width, int height) Returns aLinkedListofRectangles for a given rectangular region of the ROI.Gets a newShaperepresenting this ROI.Gets the enclosing rectangle of this ROI.Gets the enclosing double-precision rectangle of this ROI.intReturns the inclusion/exclusion threshold value.Returns a new instance which is the intersection of this ROI androi.booleanintersects(double x, double y, double w, double h) Tests if the given rectangle intersects with this ROI.booleanintersects(int x, int y, int w, int h) Tests if the given rectangle intersects with this ROI.booleanintersects(Rectangle2D rect) Tests if the given rectangle intersects with this ROI.booleanintersects(Rectangle rect) Tests if the given rectangle intersects with this ROI.performImageOp(RenderedImageFactory RIF, ParameterBlock paramBlock, int sourceIndex, RenderingHints renderHints) Transforms an ROI using an imaging operation.performImageOp(String name, ParameterBlock paramBlock, int sourceIndex, RenderingHints renderHints) Transforms an ROI using an imaging operation.voidsetThreshold(int threshold) Sets the inclusion/exclusion threshold value.Returns a new instance which is the difference of this ROI androi.toString()Returns a new ROI created by applying the given transform to this ROI.transform(AffineTransform at, Interpolation interp) Returns a new ROI created by applying the given transform to this ROI.
-
Field Details
-
DEFAULT_ROIGEOMETRY_ANTIALISING
public static final boolean DEFAULT_ROIGEOMETRY_ANTIALISINGDefault setting for use of anti-aliasing when drawing the referenceGeometryduring agetAsImage()request. The default value istruewhich provides behaviour corresponding to that of the standard ImageNROIShapeclass.- See Also:
-
DEFAULT_ROIGEOMETRY_USEFIXEDPRECISION
public static final boolean DEFAULT_ROIGEOMETRY_USEFIXEDPRECISIONDefault setting for use of fixed precision (true).- See Also:
-
-
Constructor Details
-
ROIGeometry
Constructor which takes aGeometryobject to be used as the reference against which to test inclusion of image coordinates. The argumentgeommust be either aPolygonorMultiPolygon. The input geometry is copied so subsequent changes to it will not be reflected in theROIGeometryobject.- Parameters:
geom- either aPolygonorMultiPolygonobject defining the area(s) of inclusion.- Throws:
IllegalArgumentException- ifgeomisnullor not an instance of eitherPolygonorMultiPolygon
-
ROIGeometry
-
ROIGeometry
Constructor which takes aGeometryobject and abooleanvalue for whether to use fixed coordinate precision (equivalent to working with integer pixel coordinates). The argumentgeommust be either aPolygonorMultiPolygon. The input geometry is copied so subsequent changes to it will not be reflected in theROIGeometryobject.- Parameters:
geom- either aPolygonorMultiPolygonobject defining the area(s) of inclusion.useFixedPrecision- whether to use fixed precision when comparing pixel coordinates to the reference geometry- Throws:
IllegalArgumentException- ifgeomisnullor not an instance of eitherPolygonorMultiPolygon
-
ROIGeometry
Constructors a new ROIGeometry. The argumentgeommust be either aPolygonorMultiPolygon. The input geometry is copied so subsequent changes to it will not be reflected in theROIGeometryobject.- Parameters:
geom- either aPolygonorMultiPolygonobject defining the area(s) of inclusion.antiAliasing- whether to use anti-aliasing when converting this ROI to an imageuseFixedPrecision- whether to use fixed precision when comparing pixel coordinates to the reference geometry- Throws:
IllegalArgumentException- ifgeomisnullor not an instance of eitherPolygonorMultiPolygon
-
ROIGeometry
Builds a new ROIGeometry. The argumentgeommust be either aPolygonorMultiPolygon. The input geometry is copied so subsequent changes to it will not be reflected in theROIGeometryobject.- Parameters:
geom- either aPolygonorMultiPolygonobject defining the area(s) of inclusion.hints- The ImageN hints to be used when generating the raster equivalent of this ROI- Throws:
IllegalArgumentException- ifgeomisnullor not an instance of eitherPolygonorMultiPolygon
-
ROIGeometry
public ROIGeometry(Geometry geom, boolean antiAliasing, boolean useFixedPrecision, RenderingHints hints) Fully-specified constructor. The argumentgeommust be either aPolygonorMultiPolygon. The input geometry is copied so subsequent changes to it will not be reflected in theROIGeometryobject.- Parameters:
geom- either aPolygonorMultiPolygonobject defining the area(s) of inclusion.antiAliasing- whether to use anti-aliasing when converting this ROI to an imageuseFixedPrecision- whether to use fixed precision when comparing pixel coordinates to the reference geometryhints- The ImageN hints to be used when generating the raster equivalent of this ROI- Throws:
IllegalArgumentException- ifgeomisnullor not an instance of eitherPolygonorMultiPolygon
-
-
Method Details
-
add
Returns a new instance which is the union of this ROI androi. This is only possible ifroiis an instance of ROIGeometry orROIShape. -
contains
Tests if this ROI contains the given point. -
contains
Tests if this ROI contains the given point. -
contains
public boolean contains(int x, int y) Tests if this ROI contains the given image location. -
contains
public boolean contains(double x, double y) Tests if this ROI contains the given image location. -
contains
Tests if this ROI contains the given rectangle. -
contains
Tests if this ROI contains the given rectangle. -
contains
public boolean contains(int x, int y, int w, int h) Tests if this ROI contains the given rectangle. -
contains
public boolean contains(double x, double y, double w, double h) Tests if this ROI contains the given rectangle. -
exclusiveOr
Returns a new instance which is the exclusive OR of this ROI androi. This is only possible ifroiis an instance of ROIGeometry orROIShape.- Overrides:
exclusiveOrin classROI- Parameters:
roi- the ROI to add- Returns:
- the union as a new instance
-
getAsBitmask
public int[][] getAsBitmask(int x, int y, int width, int height, int[][] mask) Description copied from class:ROIReturns a bitmask for a given rectangular region of the ROI indicating whether the pixel is included in the region of interest. The results are packed into 32-bit integers, with the MSB considered to lie on the left. The last entry in each row of the result may have bits that lie outside of the requested rectangle. These bits are guaranteed to be zeroed.The
maskarray, if supplied, must be of length equal to or greater thanheightand each of its subarrays must have length equal to or greater than (width + 31)/32. Ifnullis passed in, a suitable array will be constructed. If the mask is non-null but has insufficient size, an exception will be thrown.- Overrides:
getAsBitmaskin classROI- Parameters:
x- The X coordinate of the upper left corner of the rectangle.y- The Y coordinate of the upper left corner of the rectangle.width- The width of the rectangle.height- The height of the rectangle.mask- A two-dimensional array of ints at least (width + 31)/32 entries wide and (height) entries tall, or null.- Returns:
- A reference to the
maskparameter, or to a newly constructed array ifmaskisnull. If the specified rectangle does intersect with the image bounds then anullis returned.
-
getAsImage
Gets an image representation of this ROI using theVectorBinarizeoperation. For an ROI with very large bounds but simple shape(s) the resulting image has a small memory footprint.- Overrides:
getAsImagein classROI- Returns:
- a new image representing this ROI
- See Also:
-
getAsRectangleList
Description copied from class:ROIReturns aLinkedListofRectangles for a given rectangular region of the ROI. TheRectangles in the list are merged into a minimal set.- Overrides:
getAsRectangleListin classROI- Parameters:
x- The X coordinate of the upper left corner of the rectangle.y- The Y coordinate of the upper left corner of the rectangle.width- The width of the rectangle.height- The height of the rectangle.- Returns:
- A
LinkedListofRectangles. If the specified rectangle does intersect with the image bounds then anullis returned.
-
getAsShape
Gets a newShaperepresenting this ROI.- Overrides:
getAsShapein classROI- Returns:
- the shape
-
getAsGeometry
Returns the ROI as a JTSGeometry.- Returns:
- the geometry
-
getBounds
Gets the enclosing rectangle of this ROI. -
getBounds2D
Gets the enclosing double-precision rectangle of this ROI.- Overrides:
getBounds2Din classROI- Returns:
- a new rectangle
-
getThreshold
public int getThreshold()Description copied from class:ROIReturns the inclusion/exclusion threshold value.- Overrides:
getThresholdin classROI
-
intersect
Returns a new instance which is the intersection of this ROI androi. This is only possible ifroiis an instance of ROIGeometry orROIShape. -
intersects
Tests if the given rectangle intersects with this ROI.- Overrides:
intersectsin classROI- Parameters:
rect- the rectangle- Returns:
trueif there is an intersection;falseotherwise
-
intersects
Tests if the given rectangle intersects with this ROI.- Overrides:
intersectsin classROI- Parameters:
rect- the rectangle- Returns:
trueif there is an intersection;falseotherwise
-
intersects
public boolean intersects(int x, int y, int w, int h) Tests if the given rectangle intersects with this ROI.- Overrides:
intersectsin classROI- Parameters:
x- rectangle origin X ordinatey- rectangle origin Y ordinatew- rectangle widthh- rectangle height- Returns:
trueif there is an intersection;falseotherwise
-
intersects
public boolean intersects(double x, double y, double w, double h) Tests if the given rectangle intersects with this ROI.- Overrides:
intersectsin classROI- Parameters:
x- rectangle origin X ordinatey- rectangle origin Y ordinatew- rectangle widthh- rectangle height- Returns:
trueif there is an intersection;falseotherwise
-
performImageOp
public ROI performImageOp(RenderedImageFactory RIF, ParameterBlock paramBlock, int sourceIndex, RenderingHints renderHints) Description copied from class:ROITransforms an ROI using an imaging operation. The operation is specified by aRenderedImageFactory. The operation'sParameterBlock, minus the image source itself is supplied, along with an index indicating where to insert the ROI image. TherenderHintsargument allows rendering hints to be passed in.- Overrides:
performImageOpin classROI- Parameters:
RIF- ARenderedImageFactorythat will be used to create the op.paramBlock- AParameterBlockcontaining all sources and parameters for the op except for the ROI itself.sourceIndex- The index of theParameterBlock's sources where the ROI is to be inserted.renderHints- ARenderingHintsobject containing rendering hints, or null.
-
performImageOp
public ROI performImageOp(String name, ParameterBlock paramBlock, int sourceIndex, RenderingHints renderHints) Description copied from class:ROITransforms an ROI using an imaging operation. The operation is specified by name; the default ImageN registry is used to resolve this into a RIF. The operation'sParameterBlock, minus the image source itself is supplied, along with an index indicating where to insert the ROI image. TherenderHintsargument allows rendering hints to be passed in.- Overrides:
performImageOpin classROI- Parameters:
name- The name of the operation to perform.paramBlock- AParameterBlockcontaining all sources and parameters for the op except for the ROI itself.sourceIndex- The index of theParameterBlock's sources where the ROI is to be inserted.renderHints- ARenderingHintsobject containing rendering hints, or null.
-
setThreshold
public void setThreshold(int threshold) Description copied from class:ROISets the inclusion/exclusion threshold value.- Overrides:
setThresholdin classROI
-
subtract
Returns a new instance which is the difference of this ROI androi. This is only possible ifroiis an instance of ROIGeometry orROIShape. -
transform
Returns a new ROI created by applying the given transform to this ROI. -
transform
Returns a new ROI created by applying the given transform to this ROI. -
toString
-