public abstract class SegmentSlic<T extends boofcv.struct.image.ImageBase>
extends java.lang.Object
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:
[1] Radhakrishna Achanta, Appu Shaji, Kevin Smith, Aurelien Lucchi, Pascal Fua, and Sabine Süsstrunk, SLIC Superpixels, EPFL Technical Report no. 149300, June 2010.
| Modifier and Type | Class and Description |
|---|---|
static class |
SegmentSlic.Cluster
The mean in k-means.
|
static class |
SegmentSlic.ClusterDistance
Stores how far a cluster is from the specified pixel
|
static class |
SegmentSlic.Pixel
K-means clustering information for each pixel.
|
| Modifier and Type | Field and Description |
|---|---|
static int |
BORDER |
protected org.ddogleg.struct.FastQueue<SegmentSlic.Cluster> |
clusters |
protected boofcv.struct.ConnectRule |
connectRule |
protected int |
gridInterval |
protected boofcv.struct.image.ImageType<T> |
imageType |
protected T |
input |
protected org.ddogleg.struct.FastQueue<SegmentSlic.Pixel> |
pixels |
protected ClusterLabeledImage |
segment |
| Constructor and Description |
|---|
SegmentSlic(int numberOfRegions,
float m,
int totalIterations,
boofcv.struct.ConnectRule connectRule,
boofcv.struct.image.ImageType<T> imageType) |
| Modifier and Type | Method and Description |
|---|---|
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
|
void |
assignLabelsToPixels(boofcv.struct.image.GrayS32 pixelToRegions,
org.ddogleg.struct.GrowQueue_I32 regionMemberCount,
org.ddogleg.struct.FastQueue<float[]> regionColor)
Selects which region each pixel belongs to based on which cluster it is the closest to
|
abstract float |
colorDistance(float[] color,
int index)
Euclidean Squared distance away that the pixel is from the provided color
|
protected void |
computeClusterDistance()
Computes how far away each cluster is from each pixel.
|
org.ddogleg.struct.FastQueue<SegmentSlic.Cluster> |
getClusters() |
boofcv.struct.ConnectRule |
getConnectRule() |
boofcv.struct.image.ImageType<T> |
getImageType() |
abstract float |
getIntensity(int x,
int y)
Intensity of the pixel at the specified location
|
org.ddogleg.struct.GrowQueue_I32 |
getRegionMemberCount() |
protected float |
gradient(int x,
int y)
Computes the gradient at the specified pixel
|
protected void |
initalize(T input)
prepares all data structures
|
protected void |
initializeClusters()
initialize all the clusters at regularly spaced intervals.
|
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
|
void |
process(T input,
boofcv.struct.image.GrayS32 output) |
abstract void |
setColor(float[] color,
int x,
int y)
Sets the cluster's to the pixel color at that location
|
protected void |
updateClusters()
Update the value of each cluster using Maximization step.
|
public static final int BORDER
protected int gridInterval
protected T extends boofcv.struct.image.ImageBase input
protected ClusterLabeledImage segment
protected org.ddogleg.struct.FastQueue<SegmentSlic.Cluster> clusters
protected org.ddogleg.struct.FastQueue<SegmentSlic.Pixel> pixels
protected boofcv.struct.image.ImageType<T extends boofcv.struct.image.ImageBase> imageType
protected boofcv.struct.ConnectRule connectRule
public SegmentSlic(int numberOfRegions,
float m,
int totalIterations,
boofcv.struct.ConnectRule connectRule,
boofcv.struct.image.ImageType<T> imageType)
public void process(T input, boofcv.struct.image.GrayS32 output)
protected void initalize(T input)
protected void initializeClusters()
protected void perturbCenter(SegmentSlic.Cluster c, int x, int y)
protected float gradient(int x,
int y)
public abstract void setColor(float[] color,
int x,
int y)
public abstract void addColor(float[] color,
int index,
float weight)
public abstract float colorDistance(float[] color,
int index)
public abstract float getIntensity(int x,
int y)
protected void computeClusterDistance()
protected void updateClusters()
public void assignLabelsToPixels(boofcv.struct.image.GrayS32 pixelToRegions,
org.ddogleg.struct.GrowQueue_I32 regionMemberCount,
org.ddogleg.struct.FastQueue<float[]> regionColor)
public org.ddogleg.struct.GrowQueue_I32 getRegionMemberCount()
public org.ddogleg.struct.FastQueue<SegmentSlic.Cluster> getClusters()
public boofcv.struct.image.ImageType<T> getImageType()
public boofcv.struct.ConnectRule getConnectRule()