Class BinaryRegionSegmentation

java.lang.Object
imagingbook.common.regions.BinaryRegionSegmentation
Direct Known Subclasses:
BreadthFirstSegmentation, DepthFirstSegmentation, RecursiveSegmentation, RegionContourSegmentation, SequentialSegmentation

public abstract class BinaryRegionSegmentation extends Object

Performs region segmentation on a given binary image. See Ch. 8 of [1] for additional details. This class is abstract, since the implementation depends on the concrete region segmentation algorithm being used. Concrete implementations (subclasses of this class) are BreadthFirstSegmentation, DepthFirstSegmentation, RecursiveSegmentation, SequentialSegmentation, RegionContourSegmentation. Most of the work is done by the constructor(s). If the segmentation has failed for some reason getRegions() returns null.

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

Version:
2021/12/22
See Also:
  • Field Details

  • Method Details

    • getWidth

      public int getWidth()
      Returns the width of the segmented image.
      Returns:
      the width of the segmented image
    • getHeight

      public int getHeight()
      Returns the height of the segmented image.
      Returns:
      the height of the segmented image
    • getMinLabel

      public int getMinLabel()
      Returns the minimum label assigned by this segmentation.
      Returns:
      the minimum label
    • getMaxLabel

      public int getMaxLabel()
      Returns the maximum label assigned by this segmentation.
      Returns:
      the maximum label
    • isSegmented

      public boolean isSegmented()
      Returns true if the segmentation did complete successfully, false otherwise.
      Returns:
      true if segmentation was successful
    • getRegions

      Returns an unsorted list of all regions associated with this region labeling. The returned list is empty if no regions were detected. See also getRegions(boolean).
      Returns:
      a (possibly empty) list of detected regions
    • getRegions

      public List<BinaryRegion> getRegions(boolean sort)
      Returns a (optionally sorted) list of all regions associated with this region labeling. The returned list is empty if no regions were detected.
      Parameters:
      sort - set true to sort regions by size (largest regions first).
      Returns:
      the list of detected regions or null if the segmentation has failed.
    • getLabel

      public int getLabel(int u, int v)
      Returns the label number for the specified image coordinate. -1 is returned for out-of-image coordinates.
      Parameters:
      u - the horizontal coordinate.
      v - the vertical coordinate.
      Returns:
      the label number for the given position or -1 if outside the image
    • getRegion

      public SegmentationBackedRegion getRegion(int label)
      Finds the region associated to the specified label or null if no region for that label exists.
      Parameters:
      label - the region's label number
      Returns:
      the region object associated with the given label or null if it does not exist
    • getRegion

      public SegmentationBackedRegion getRegion(int u, int v)
      Returns the BinaryRegion instance associated with the given image position or null if the segmentation contains no region covering the given position.
      Parameters:
      u - the horizontal position.
      v - the vertical position.
      Returns:
      The associated BinaryRegion object or null if this BinaryRegionSegmentation has no region at the given position.