- All Implemented Interfaces:
GenericProperties
,Comparable<BinaryRegion>
,Iterable<Pnt2d>
- Direct Known Subclasses:
SegmentationBackedRegion
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
-
Nested Class Summary
Nested classes/interfaces inherited from interface imagingbook.common.util.GenericProperties
GenericProperties.PropertyKey<T>, GenericProperties.PropertyMap
-
Method Summary
Modifier and TypeMethodDescriptionint
compareTo
(BinaryRegion other) abstract boolean
contains
(int u, int v) Checks if the given pixel position is contained in thisBinaryRegion
instance.boolean
Checks if the given pixel position is contained in thisBinaryRegion
instance.abstract Rectangle
Get the x/y axes-parallel bounding box as a rectangle (including the extremal coordinates).Returns the center of this region as a 2D point.double[]
Calculates and returns a vector of central moments: (mu20, mu02, mu11).double[][]
Returns the 2x2 covariance matrix for the pixel coordinates contained in this region:
| σ20 σ11 |
| σ11 σ02 |Calculates and returns this region's equivalent ellipse (see Sec.Get all inner contours of this region if available, null otherwise.double[]
Calculates and returns a vector of ordinary moments: (m10, m01, m20, m02, m11).abstract Contour
Returns the (single) outer contour of this region if available, null otherwise.Returns an instance ofGenericProperties.PropertyMap
with keys of typeString
and values of typeObject
.abstract int
getSize()
Get the size of this region.abstract long
getX1Sum()
Returns the sum of the x-coordinates of the points contained in this region.abstract long
getX2Sum()
Returns the sum of the squared x-coordinates of the points contained in this region.abstract long
getXYSum()
Returns the sum of the mixed x*y-coordinates of the points contained in this region.abstract long
getY1Sum()
Returns the sum of the y-coordinates of the points contained in this region.abstract long
getY2Sum()
Returns the sum of the squared y-coordinates of the points contained in this region.toString()
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface imagingbook.common.util.GenericProperties
clearAllProperties, getProperty, removeProperty, setProperty
Methods inherited from interface java.lang.Iterable
forEach, iterator, spliterator
-
Method Details
-
getX1Sum
Returns the sum of the x-coordinates of the points contained in this region.- Returns:
- the sum of x-values.
-
getY1Sum
Returns the sum of the y-coordinates of the points contained in this region.- Returns:
- the sum of y-values.
-
getX2Sum
Returns the sum of the squared x-coordinates of the points contained in this region.- Returns:
- the sum of squared x-values.
-
getY2Sum
Returns the sum of the squared y-coordinates of the points contained in this region.- Returns:
- the sum of squared y-values.
-
getXYSum
Returns the sum of the mixed x*y-coordinates of the points contained in this region.- Returns:
- the sum of xy-values.
-
getMoments
Calculates and returns a vector of ordinary moments: (m10, m01, m20, m02, m11).- Returns:
- vector of ordinary moments
-
getCentralMoments
Calculates and returns a vector of central moments: (mu20, mu02, mu11).- Returns:
- vector of central moments
-
getCovarianceMatrix
Returns the 2x2 covariance matrix for the pixel coordinates contained in this region:
| σ20 σ11 |
| σ11 σ02 |- Returns:
- the covariance matrix
-
getSize
Get the size of this region.- Returns:
- the number of region points.
-
getBoundingBox
Get the x/y axes-parallel bounding box as a rectangle (including the extremal coordinates).- Returns:
- the bounding box rectangle.
-
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
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
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
- Specified by:
compareTo
in interfaceComparable<BinaryRegion>
-
contains
Checks if the given pixel position is contained in thisBinaryRegion
instance.- Parameters:
u
- x-coordinatev
- y-coordinate- Returns:
- true if (u,v) is contained in this region
-
contains
Checks if the given pixel position is contained in thisBinaryRegion
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 ofGenericProperties.PropertyMap
with keys of typeString
and values of typeObject
. Implementing classes must define this method, which will typically return a reference to a local map instance. The returned object must not benull
.- Specified by:
getPropertyMap
in interfaceGenericProperties
- Returns:
- the
GenericProperties.PropertyMap
associated with the implementing instance
-
toString
-