Class SegmentMeanShift<T extends ImageBase<T>>

All Implemented Interfaces:

public class SegmentMeanShift<T extends ImageBase<T>> extends Object implements Stoppable

Performs mean-shift segmentation on an image. Primary based upon the description provided in [1], it first uses mean-shift to find the mode of each pixel in the image. The mode is the location mean-shift converges to when initialized at a particular pixel. All the pixels which have the same mode, to within tolerance, are combined into one region. Since mean-shift does not guarantee that pixels which have the same label are connected to each other the labeled image is now segmented to ensure connectivity between labels. If a minimum size is specified for a segment then small regions are pruned and their pixels combined into the adjacent region which has the most similar color.

Mean-shift segmentation can be slow but it has the advantage of there being relatively few tuning parameters. Few tuning parameters make it easier to work with and to some extent more robust.

NOTE: Connectivity rule of 4 tends to produce more tightly compact regions while 8 produces fewer regions but with a more complex surface.

[1] Comaniciu, Dorin, and Peter Meer. "Mean shift analysis and applications." Computer Vision, 1999. The Proceedings of the Seventh IEEE International Conference on. Vol. 2. IEEE, 1999.

  • Constructor Details

    • SegmentMeanShift

      public SegmentMeanShift(SegmentMeanShiftSearch<T> search, MergeRegionMeanShift merge, @Nullable @Nullable MergeSmallRegions<T> prune, ConnectRule connectRule)
      Specifies internal classes used by mean-shift.
      search - mean-shift search
      merge - Used to merge regions
      prune - Prunes small regions and merges them If null then prune step will be skipped.
      connectRule - Specify if a 4 or 8 connect rule should be used when segmenting disconnected regions. Try 4
  • Method Details

    • process

      public void process(T image, GrayS32 output)
      Performs mean-shift segmentation on the input image. The total number of regions can be found by calling getNumberOfRegions().
      image - Image
      output - Storage for output image. Each pixel is set to the region it belongs to.
    • getNumberOfRegions

      public int getNumberOfRegions()
      The number of regions which it found in the image.
      Total regions
    • getRegionColor

      public DogArray<float[]> getRegionColor()
      Average color of each region
    • getRegionSize

      public DogArray_I32 getRegionSize()
      Number of pixels in each region
    • getImageType

      public ImageType<T> getImageType()
    • requestStop

      public void requestStop()
      Specified by:
      requestStop in interface Stoppable
    • isStopRequested

      public boolean isStopRequested()
      Specified by:
      isStopRequested in interface Stoppable