Class BinaryRegion

java.lang.Object
imagingbook.common.regions.BinaryRegion
All Implemented Interfaces:
GenericProperties, Comparable<BinaryRegion>, Iterable<Pnt2d>
Direct Known Subclasses:
SegmentationBackedRegion

public abstract class BinaryRegion extends Object implements Comparable<BinaryRegion>, Iterable<Pnt2d>, GenericProperties

This class represents a connected component or binary region. See Sec. 8.4 of [1] for additional details. Instances of this class support iteration over the contained pixel coordinates of type Pnt2d, e.g., by

 import imagingbook.pub.geometry.basic.Pnt2d;
 BinaryRegion R = ...;
 for (Pnt2d p : R) {
    // process point p ...
 }
 

The advantage of providing iteration only is that it avoids the creation of (possibly large) arrays of pixel coordinates.

[1] W. Burger, M.J. Burge, Digital Image Processing – An Algorithmic Introduction, 3rd ed, Springer (2022).

Version:
2023/01/02
  • Method Details

    • getX1Sum

      public abstract long getX1Sum()
      Returns the sum of the x-coordinates of the points contained in this region.
      Returns:
      the sum of x-values.
    • getY1Sum

      public abstract long getY1Sum()
      Returns the sum of the y-coordinates of the points contained in this region.
      Returns:
      the sum of y-values.
    • getX2Sum

      public abstract long getX2Sum()
      Returns the sum of the squared x-coordinates of the points contained in this region.
      Returns:
      the sum of squared x-values.
    • getY2Sum

      public abstract long getY2Sum()
      Returns the sum of the squared y-coordinates of the points contained in this region.
      Returns:
      the sum of squared y-values.
    • getXYSum

      public abstract long getXYSum()
      Returns the sum of the mixed x*y-coordinates of the points contained in this region.
      Returns:
      the sum of xy-values.
    • getMoments

      public double[] getMoments()
      Calculates and returns a vector of ordinary moments: (m10, m01, m20, m02, m11).
      Returns:
      vector of ordinary moments
    • getCentralMoments

      public double[] getCentralMoments()
      Calculates and returns a vector of central moments: (mu20, mu02, mu11).
      Returns:
      vector of central moments
    • getCovarianceMatrix

      public double[][] getCovarianceMatrix()

      Returns the 2x2 covariance matrix for the pixel coordinates contained in this region:
      | σ20 σ11 |
      | σ11 σ02 |

      Returns:
      the covariance matrix
    • getSize

      public abstract int getSize()
      Get the size of this region.
      Returns:
      the number of region points.
    • getBoundingBox

      public abstract Rectangle getBoundingBox()
      Get the x/y axes-parallel bounding box as a rectangle (including the extremal coordinates).
      Returns:
      the bounding box rectangle.
    • getCenter

      public Pnt2d getCenter()
      Returns the center of this region as a 2D point.
      Returns:
      the center point of this region.
    • getEquivalentEllipse

      Calculates and returns this region's equivalent ellipse (see Sec. 8.6.3 of [1] for details).

      [1] W. Burger, M.J. Burge, Digital Image Processing – An Algorithmic Introduction, 3rd ed, Springer (2022).

      Returns:
      the equivalent ellipse (instance of GeometricEllipse)
    • getOuterContour

      public abstract Contour getOuterContour()
      Returns the (single) outer contour of this region if available, null otherwise. Points on an outer contour are arranged in clockwise order.
      Returns:
      the outer contour or null if not available
    • getInnerContours

      public abstract List<Contour> getInnerContours()
      Get all inner contours of this region if available, null otherwise. Points on inner contours are arranged in counter-clockwise order.
      Returns:
      the (possibly empty) list of inner contours or null if not available
    • compareTo

      public int compareTo(BinaryRegion other)
      Specified by:
      compareTo in interface Comparable<BinaryRegion>
    • contains

      public abstract boolean contains(int u, int v)
      Checks if the given pixel position is contained in this BinaryRegion instance.
      Parameters:
      u - x-coordinate
      v - y-coordinate
      Returns:
      true if (u,v) is contained in this region
    • contains

      public boolean contains(Pnt2d.PntInt p)
      Checks if the given pixel position is contained in this BinaryRegion instance.
      Parameters:
      p - the pixel coordinate
      Returns:
      true if the position is contained in this region
    • getPropertyMap

      Description copied from interface: GenericProperties
      Returns an instance of GenericProperties.PropertyMap with keys of type String and values of type Object. Implementing classes must define this method, which will typically return a reference to a local map instance. The returned object must not be null.
      Specified by:
      getPropertyMap in interface GenericProperties
      Returns:
      the GenericProperties.PropertyMap associated with the implementing instance
    • toString

      public String toString()
      Overrides:
      toString in class Object