Class ROIGeometry

Object
ROI
ROIGeometry
All Implemented Interfaces:
Serializable

public class ROIGeometry extends ROI
An ROI class backed by a vector object providing precision and the ability to handle massive regions. It has a minimal memory footprint allowing it to be used with massive images.

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 Details

    • DEFAULT_ROIGEOMETRY_ANTIALISING

      public static final boolean DEFAULT_ROIGEOMETRY_ANTIALISING
      Default setting for use of anti-aliasing when drawing the reference Geometry during a getAsImage() request. The default value is true which provides behaviour corresponding to that of the standard ImageN ROIShape class.
      See Also:
    • DEFAULT_ROIGEOMETRY_USEFIXEDPRECISION

      public static final boolean DEFAULT_ROIGEOMETRY_USEFIXEDPRECISION
      Default setting for use of fixed precision (true).
      See Also:
  • Constructor Details

    • ROIGeometry

      public ROIGeometry(Geometry geom)
      Constructor which takes a Geometry object to be used as the reference against which to test inclusion of image coordinates. The argument geom must be either a Polygon or MultiPolygon. The input geometry is copied so subsequent changes to it will not be reflected in the ROIGeometry object.
      Parameters:
      geom - either a Polygon or MultiPolygon object defining the area(s) of inclusion.
      Throws:
      IllegalArgumentException - if geom is null or not an instance of either Polygon or MultiPolygon
    • ROIGeometry

      public ROIGeometry(Rectangle rect)
    • ROIGeometry

      public ROIGeometry(Geometry geom, boolean useFixedPrecision)
      Constructor which takes a Geometry object and a boolean value for whether to use fixed coordinate precision (equivalent to working with integer pixel coordinates). The argument geom must be either a Polygon or MultiPolygon. The input geometry is copied so subsequent changes to it will not be reflected in the ROIGeometry object.
      Parameters:
      geom - either a Polygon or MultiPolygon object defining the area(s) of inclusion.
      useFixedPrecision - whether to use fixed precision when comparing pixel coordinates to the reference geometry
      Throws:
      IllegalArgumentException - if geom is null or not an instance of either Polygon or MultiPolygon
    • ROIGeometry

      public ROIGeometry(Geometry geom, boolean antiAliasing, boolean useFixedPrecision)
      Constructors a new ROIGeometry. The argument geom must be either a Polygon or MultiPolygon. The input geometry is copied so subsequent changes to it will not be reflected in the ROIGeometry object.
      Parameters:
      geom - either a Polygon or MultiPolygon object defining the area(s) of inclusion.
      antiAliasing - whether to use anti-aliasing when converting this ROI to an image
      useFixedPrecision - whether to use fixed precision when comparing pixel coordinates to the reference geometry
      Throws:
      IllegalArgumentException - if geom is null or not an instance of either Polygon or MultiPolygon
    • ROIGeometry

      public ROIGeometry(Geometry geom, RenderingHints hints)
      Builds a new ROIGeometry. The argument geom must be either a Polygon or MultiPolygon. The input geometry is copied so subsequent changes to it will not be reflected in the ROIGeometry object.
      Parameters:
      geom - either a Polygon or MultiPolygon object defining the area(s) of inclusion.
      hints - The ImageN hints to be used when generating the raster equivalent of this ROI
      Throws:
      IllegalArgumentException - if geom is null or not an instance of either Polygon or MultiPolygon
    • ROIGeometry

      public ROIGeometry(Geometry geom, boolean antiAliasing, boolean useFixedPrecision, RenderingHints hints)
      Fully-specified constructor. The argument geom must be either a Polygon or MultiPolygon. The input geometry is copied so subsequent changes to it will not be reflected in the ROIGeometry object.
      Parameters:
      geom - either a Polygon or MultiPolygon object defining the area(s) of inclusion.
      antiAliasing - whether to use anti-aliasing when converting this ROI to an image
      useFixedPrecision - whether to use fixed precision when comparing pixel coordinates to the reference geometry
      hints - The ImageN hints to be used when generating the raster equivalent of this ROI
      Throws:
      IllegalArgumentException - if geom is null or not an instance of either Polygon or MultiPolygon
  • Method Details

    • add

      public ROI add(ROI roi)
      Returns a new instance which is the union of this ROI and roi. This is only possible if roi is an instance of ROIGeometry or ROIShape.
      Overrides:
      add in class ROI
      Parameters:
      roi - the ROI to add
      Returns:
      the union as a new instance
    • contains

      public boolean contains(Point p)
      Tests if this ROI contains the given point.
      Overrides:
      contains in class ROI
      Parameters:
      p - the point
      Returns:
      true if the point is within this ROI; false otherwise
    • contains

      public boolean contains(Point2D p)
      Tests if this ROI contains the given point.
      Overrides:
      contains in class ROI
      Parameters:
      p - the point
      Returns:
      true if the point is within this ROI; false otherwise
    • contains

      public boolean contains(int x, int y)
      Tests if this ROI contains the given image location.
      Overrides:
      contains in class ROI
      Parameters:
      x - location X ordinate
      y - location Y ordinate
      Returns:
      true if the location is within this ROI; false otherwise
    • contains

      public boolean contains(double x, double y)
      Tests if this ROI contains the given image location.
      Overrides:
      contains in class ROI
      Parameters:
      x - location X ordinate
      y - location Y ordinate
      Returns:
      true if the location is within this ROI; false otherwise
    • contains

      public boolean contains(Rectangle rect)
      Tests if this ROI contains the given rectangle.
      Overrides:
      contains in class ROI
      Parameters:
      rect - the rectangle
      Returns:
      true if the rectangle is within this ROI; false otherwise
    • contains

      public boolean contains(Rectangle2D rect)
      Tests if this ROI contains the given rectangle.
      Overrides:
      contains in class ROI
      Parameters:
      rect - the rectangle
      Returns:
      true if the rectangle is within this ROI; false otherwise
    • contains

      public boolean contains(int x, int y, int w, int h)
      Tests if this ROI contains the given rectangle.
      Overrides:
      contains in class ROI
      Parameters:
      x - rectangle origin X ordinate
      y - rectangle origin Y ordinate
      w - rectangle width
      h - rectangle height
      Returns:
      true if the rectangle is within this ROI; false otherwise
    • contains

      public boolean contains(double x, double y, double w, double h)
      Tests if this ROI contains the given rectangle.
      Overrides:
      contains in class ROI
      Parameters:
      x - rectangle origin X ordinate
      y - rectangle origin Y ordinate
      w - rectangle width
      h - rectangle height
      Returns:
      true if the rectangle is within this ROI; false otherwise
    • exclusiveOr

      public ROI exclusiveOr(ROI roi)
      Returns a new instance which is the exclusive OR of this ROI and roi. This is only possible if roi is an instance of ROIGeometry or ROIShape.
      Overrides:
      exclusiveOr in class ROI
      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: ROI
      Returns 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 mask array, if supplied, must be of length equal to or greater than height and each of its subarrays must have length equal to or greater than (width + 31)/32. If null is passed in, a suitable array will be constructed. If the mask is non-null but has insufficient size, an exception will be thrown.

      Overrides:
      getAsBitmask in class ROI
      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 mask parameter, or to a newly constructed array if mask is null. If the specified rectangle does intersect with the image bounds then a null is returned.
    • getAsImage

      public PlanarImage getAsImage()
      Gets an image representation of this ROI using the VectorBinarize operation. For an ROI with very large bounds but simple shape(s) the resulting image has a small memory footprint.
      Overrides:
      getAsImage in class ROI
      Returns:
      a new image representing this ROI
      See Also:
    • getAsRectangleList

      public LinkedList getAsRectangleList(int x, int y, int width, int height)
      Description copied from class: ROI
      Returns a LinkedList of Rectangles for a given rectangular region of the ROI. The Rectangles in the list are merged into a minimal set.
      Overrides:
      getAsRectangleList in class ROI
      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 LinkedList of Rectangles. If the specified rectangle does intersect with the image bounds then a null is returned.
    • getAsShape

      public Shape getAsShape()
      Gets a new Shape representing this ROI.
      Overrides:
      getAsShape in class ROI
      Returns:
      the shape
    • getAsGeometry

      public Geometry getAsGeometry()
      Returns the ROI as a JTS Geometry.
      Returns:
      the geometry
    • getBounds

      public Rectangle getBounds()
      Gets the enclosing rectangle of this ROI.
      Overrides:
      getBounds in class ROI
      Returns:
      a new rectangle
    • getBounds2D

      public Rectangle2D getBounds2D()
      Gets the enclosing double-precision rectangle of this ROI.
      Overrides:
      getBounds2D in class ROI
      Returns:
      a new rectangle
    • getThreshold

      public int getThreshold()
      Description copied from class: ROI
      Returns the inclusion/exclusion threshold value.
      Overrides:
      getThreshold in class ROI
    • intersect

      public ROI intersect(ROI roi)
      Returns a new instance which is the intersection of this ROI and roi. This is only possible if roi is an instance of ROIGeometry or ROIShape.
      Overrides:
      intersect in class ROI
      Parameters:
      roi - the ROI to intersect with
      Returns:
      the intersection as a new instance
    • intersects

      public boolean intersects(Rectangle rect)
      Tests if the given rectangle intersects with this ROI.
      Overrides:
      intersects in class ROI
      Parameters:
      rect - the rectangle
      Returns:
      true if there is an intersection; false otherwise
    • intersects

      public boolean intersects(Rectangle2D rect)
      Tests if the given rectangle intersects with this ROI.
      Overrides:
      intersects in class ROI
      Parameters:
      rect - the rectangle
      Returns:
      true if there is an intersection; false otherwise
    • intersects

      public boolean intersects(int x, int y, int w, int h)
      Tests if the given rectangle intersects with this ROI.
      Overrides:
      intersects in class ROI
      Parameters:
      x - rectangle origin X ordinate
      y - rectangle origin Y ordinate
      w - rectangle width
      h - rectangle height
      Returns:
      true if there is an intersection; false otherwise
    • intersects

      public boolean intersects(double x, double y, double w, double h)
      Tests if the given rectangle intersects with this ROI.
      Overrides:
      intersects in class ROI
      Parameters:
      x - rectangle origin X ordinate
      y - rectangle origin Y ordinate
      w - rectangle width
      h - rectangle height
      Returns:
      true if there is an intersection; false otherwise
    • performImageOp

      public ROI performImageOp(RenderedImageFactory RIF, ParameterBlock paramBlock, int sourceIndex, RenderingHints renderHints)
      Description copied from class: ROI
      Transforms an ROI using an imaging operation. The operation is specified by a RenderedImageFactory. The operation's ParameterBlock, minus the image source itself is supplied, along with an index indicating where to insert the ROI image. The renderHints argument allows rendering hints to be passed in.
      Overrides:
      performImageOp in class ROI
      Parameters:
      RIF - A RenderedImageFactory that will be used to create the op.
      paramBlock - A ParameterBlock containing all sources and parameters for the op except for the ROI itself.
      sourceIndex - The index of the ParameterBlock's sources where the ROI is to be inserted.
      renderHints - A RenderingHints object containing rendering hints, or null.
    • performImageOp

      public ROI performImageOp(String name, ParameterBlock paramBlock, int sourceIndex, RenderingHints renderHints)
      Description copied from class: ROI
      Transforms 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's ParameterBlock, minus the image source itself is supplied, along with an index indicating where to insert the ROI image. The renderHints argument allows rendering hints to be passed in.
      Overrides:
      performImageOp in class ROI
      Parameters:
      name - The name of the operation to perform.
      paramBlock - A ParameterBlock containing all sources and parameters for the op except for the ROI itself.
      sourceIndex - The index of the ParameterBlock's sources where the ROI is to be inserted.
      renderHints - A RenderingHints object containing rendering hints, or null.
    • setThreshold

      public void setThreshold(int threshold)
      Description copied from class: ROI
      Sets the inclusion/exclusion threshold value.
      Overrides:
      setThreshold in class ROI
    • subtract

      public ROI subtract(ROI roi)
      Returns a new instance which is the difference of this ROI and roi. This is only possible if roi is an instance of ROIGeometry or ROIShape.
      Overrides:
      subtract in class ROI
      Parameters:
      roi - the ROI to add
      Returns:
      the union as a new instance
    • transform

      public ROI transform(AffineTransform at, Interpolation interp)
      Returns a new ROI created by applying the given transform to this ROI.
      Overrides:
      transform in class ROI
      Parameters:
      at - the transform
      interp - ignored
      Returns:
      the new ROI
    • transform

      public ROI transform(AffineTransform at)
      Returns a new ROI created by applying the given transform to this ROI.
      Overrides:
      transform in class ROI
      Parameters:
      at - the transform
      Returns:
      the new ROI
    • toString

      public String toString()
      Overrides:
      toString in class Object