Class SegmentSlic<T extends ImageBase<T>>
- All Implemented Interfaces:
Stoppable
- Direct Known Subclasses:
SegmentSlic_F32
,SegmentSlic_PlF32
,SegmentSlic_PlU8
,SegmentSlic_U8
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.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
The mean in k-means.static class
Stores how far a cluster is from the specified pixelstatic class
K-means clustering information for each pixel.Nested classes/interfaces inherited from interface org.ddogleg.struct.Stoppable
Stoppable.Stopped
-
Field Summary
Modifier and TypeFieldDescriptionstatic final int
protected DogArray<SegmentSlic.Cluster>
protected ConnectRule
protected int
protected T
protected DogArray<SegmentSlic.Pixel>
protected ClusterLabeledImage
-
Constructor Summary
ModifierConstructorDescriptionprotected
SegmentSlic
(int numberOfRegions, float m, int totalIterations, ConnectRule connectRule, ImageType<T> imageType) -
Method Summary
Modifier and TypeMethodDescriptionabstract void
addColor
(float[] color, int index, float weight) Performs a weighted add to the cluster's color at the specified pixel in the imagevoid
assignLabelsToPixels
(GrayS32 pixelToRegions, DogArray_I32 regionMemberCount, DogArray<float[]> regionColor) Selects which region each pixel belongs to based on which cluster it is the closest toabstract float
colorDistance
(float[] color, int index) Euclidean Squared distance away that the pixel is from the provided colorprotected void
Computes how far away each cluster is from each pixel.abstract float
getIntensity
(int x, int y) Intensity of the pixel at the specified locationprotected float
gradient
(int x, int y) Computes the gradient at the specified pixelprotected void
prepares all data structuresprotected void
initialize all the clusters at regularly spaced intervals.boolean
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 gradientvoid
void
abstract void
setColor
(float[] color, int x, int y) Sets the cluster's to the pixel color at that locationprotected void
Update the value of each cluster using Maximization step.
-
Field Details
-
BORDER
public static final int BORDER- See Also:
-
gridInterval
protected int gridInterval -
input
-
segment
-
clusters
-
pixels
-
imageType
-
connectRule
-
-
Constructor Details
-
SegmentSlic
protected SegmentSlic(int numberOfRegions, float m, int totalIterations, ConnectRule connectRule, ImageType<T> imageType)
-
-
Method Details
-
process
-
initalize
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
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
-
getClusters
-
getImageType
-
getConnectRule
-
requestStop
public void requestStop()- Specified by:
requestStop
in interfaceStoppable
-
isStopRequested
public boolean isStopRequested()- Specified by:
isStopRequested
in interfaceStoppable
-