Class SegmentSlic<T extends ImageBase<T>>

java.lang.Object
boofcv.alg.segmentation.slic.SegmentSlic<T>
All Implemented Interfaces:
Stoppable
Direct Known Subclasses:
SegmentSlic_F32, SegmentSlic_PlF32, SegmentSlic_PlU8, SegmentSlic_U8

public abstract class SegmentSlic<T extends ImageBase<T>> extends Object implements Stoppable

K-means based superpixel image segmentation, see [1]. The image is broken up into superpixels (clusters of connected pixels) in a grid like pattern. A connectivity rule of 4 or 8 is enforced across all the clusters. Clustering is done using k-means, where each point is composed on the 2D image coordinate and an intensity value in each color band, thus K = 2+numBands. Instead of computing the distance of each cluster's center from each point only points within a distance of S si considered. The difference in scale difference between pixels and image intensity is handled through a user configurable tuning parameter.

Deviations from paper:

  • In the paper a LAB color space is always used. In this implementation a general purpose N-dimensional color space is used.
  • To correctly support LAB or other color spaces a specialized implementation might be needed to ensure the intensity of a pixel is computed correctly.
  • Small regions are merged into other regions based on how similar their color is. In the paper a small region is merged into the largest region it is connected to.

[1] Radhakrishna Achanta, Appu Shaji, Kevin Smith, Aurelien Lucchi, Pascal Fua, and Sabine Süsstrunk, SLIC Superpixels, EPFL Technical Report no. 149300, June 2010.

  • Field Details

  • Constructor Details

    • SegmentSlic

      protected SegmentSlic(int numberOfRegions, float m, int totalIterations, ConnectRule connectRule, ImageType<T> imageType)
  • Method Details

    • process

      public void process(T input, GrayS32 output)
    • initalize

      protected void initalize(T input)
      prepares all data structures
    • initializeClusters

      protected void initializeClusters()
      initialize all the clusters at regularly spaced intervals. Their locations are perturbed a bit to reduce the likelihood of a bad location. Initial color is set to the image color at the location
    • perturbCenter

      protected void perturbCenter(SegmentSlic.Cluster c, int x, int y)
      Set the cluster's center to be the pixel in a 3x3 neighborhood with the smallest gradient
    • gradient

      protected float gradient(int x, int y)
      Computes the gradient at the specified pixel
    • setColor

      public abstract void setColor(float[] color, int x, int y)
      Sets the cluster's to the pixel color at that location
    • addColor

      public abstract void addColor(float[] color, int index, float weight)
      Performs a weighted add to the cluster's color at the specified pixel in the image
    • colorDistance

      public abstract float colorDistance(float[] color, int index)
      Euclidean Squared distance away that the pixel is from the provided color
    • getIntensity

      public abstract float getIntensity(int x, int y)
      Intensity of the pixel at the specified location
    • computeClusterDistance

      protected void computeClusterDistance()
      Computes how far away each cluster is from each pixel. Expectation step.
    • updateClusters

      protected void updateClusters()
      Update the value of each cluster using Maximization step.
    • assignLabelsToPixels

      public void assignLabelsToPixels(GrayS32 pixelToRegions, DogArray_I32 regionMemberCount, DogArray<float[]> regionColor)
      Selects which region each pixel belongs to based on which cluster it is the closest to
    • getRegionMemberCount

      public DogArray_I32 getRegionMemberCount()
    • getClusters

      public DogArray<SegmentSlic.Cluster> getClusters()
    • getImageType

      public ImageType<T> getImageType()
    • getConnectRule

      public ConnectRule getConnectRule()
    • requestStop

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

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