Class ClusterLabeledImage

java.lang.Object
boofcv.alg.segmentation.ms.RegionMergeTree
boofcv.alg.segmentation.ms.ClusterLabeledImage
All Implemented Interfaces:
Stoppable

public class ClusterLabeledImage
extends RegionMergeTree

Given a labeled image in which pixels that contains the same label may or may not be connected to each other, create a new labeled image in which only connected pixels have the same label. A two pass algorithm is used. In the first pass pixels are examined from top to bottom, left to right. For each pixel (the target), the input image and output image labels of its adjacent pixels are examined. If an adjacent pixel has the same input label as the target then it is either assigned the same output label or marked for being merged. Depending if it is not labeled or has an output label already, respectively. After all the pixels are process the merge requests are examined and a new set of output labels is created. A pass across the output image is done to relabel the inputs.

Clustering can be done using 4 or 8 connect, which defines what an adjacent pixel is. 4-connect just considers pixels which are (+1,0) (0,1) (-1,0) (0,-1). 8-connect considers (+1,0) (0,1) (-1,0) (0,-1) and (1,1) (-1,1) (-1,-1) (1,-1).

  • Field Details

    • connectRule

      protected ConnectRule connectRule
    • edgesIn

      protected int[] edgesIn
    • edgesOut

      protected int[] edgesOut
    • edges

      protected Point2D_I32[] edges
    • regionMemberCount

      protected DogArray_I32 regionMemberCount
  • Constructor Details

    • ClusterLabeledImage

      public ClusterLabeledImage​(ConnectRule connectRule)
      Configures labeling
      Parameters:
      connectRule - Which connectivity rule to use. 4 or 8
  • Method Details

    • setUpEdges

      protected void setUpEdges​(GrayS32 input, GrayS32 output)
      Declares lookup tables for neighbors
    • setUpEdges8

      protected void setUpEdges8​(GrayS32 image, int[] edges)
    • setUpEdges4

      protected void setUpEdges4​(GrayS32 image, int[] edges)
    • process

      public void process​(GrayS32 input, GrayS32 output, DogArray_I32 regionMemberCount)
      Relabels the image such that all pixels with the same label are a member of the same graph.
      Parameters:
      input - Labeled input image.
      output - Labeled output image.
      regionMemberCount - (Input/Output) Number of pixels which belong to each group.
    • connectInner

      protected void connectInner​(GrayS32 input, GrayS32 output)
      Examines pixels inside the image without the need for bounds checking
    • connectLeftRight

      protected void connectLeftRight​(GrayS32 input, GrayS32 output)
      Examines pixels along the left and right border
    • connectBottom

      protected void connectBottom​(GrayS32 input, GrayS32 output)
      Examines pixels along the bottom border