java.lang.Object
imagingbook.common.regions.Contour
- All Implemented Interfaces:
Comparable<Contour>,Iterable<Pnt2d>
- Direct Known Subclasses:
Contour.Inner,Contour.Outer
This class represents a closed contour as a sequence of pixel coordinates. It implements the Comparable
interface for sorting contours by length. It supports iteration over the points along the contour, e.g., by
Contour C = ...;
for (Point p : C) {
// process p ...
}
- Version:
- 2020/12/21
-
Nested Class Summary
Nested Classes -
Constructor Summary
ConstructorsConstructorDescriptionContour(int label) Creates a new (empty) contour with the given region label. -
Method Summary
Modifier and TypeMethodDescriptionvoidintintReturns the number of successive duplicates in this contour.intgetLabel()Get the region label associated with this contour.intGet the length of the contour.Pnt2d[]Get the contour points as an array.Get the list of contour points.Get the polygon for this contour (for subsequent drawing).getPolygonPath(double xOffset, double yOffset) Get the polygon for this contour (for subsequent drawing).booleanChecks if this contour is closed w.r.t. the specifiedNeighborhoodType2D, i.e., if the last and the first contour point are "connected".iterator()toString()Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface java.lang.Iterable
forEach, spliterator
-
Constructor Details
-
Contour
Creates a new (empty) contour with the given region label.- Parameters:
label- the region label for this contour.
-
-
Method Details
-
addPoint
-
getPointList
Get the list of contour points.- Returns:
- a reference to the internal list of contour points.
-
getPointArray
Get the contour points as an array.- Returns:
- a new array of contour points.
-
getLength
Get the length of the contour.- Returns:
- the number of points on the contour.
-
getLabel
Get the region label associated with this contour.- Returns:
- the region label of the contour.
-
toString
-
getPolygonPath
Get the polygon for this contour (for subsequent drawing).- Returns:
- the polygon.
-
getPolygonPath
Get the polygon for this contour (for subsequent drawing). An offset can be specified for shifting the contour positions to pixel centers (by passing 0.5, 0.5).- Parameters:
xOffset- the horizontal offset.yOffset- the vertical offset.- Returns:
- a polygon.
-
countDuplicatePoints
Returns the number of successive duplicates in this contour. The result should be zero.- Returns:
- as described.
-
isClosed
Checks if this contour is closed w.r.t. the specifiedNeighborhoodType2D, i.e., if the last and the first contour point are "connected".- Parameters:
nht- the (@link NeighborhoodType}.- Returns:
- true if the contour is closed.
-
compareTo
- Specified by:
compareToin interfaceComparable<Contour>
-
iterator
-