Class SegmentMeanShiftSearch<T extends ImageBase<T>>
- All Implemented Interfaces:
Stoppable
- Direct Known Subclasses:
SegmentMeanShiftSearchColor
,SegmentMeanShiftSearchGray
Performs the search step in mean-shift image segmentation [1]. The mode of a pixel is the point at which mean-shift converges when initialized at that pixel. Pixels which have the same mode belong to the same segment. The weight kernel G(|x-y|^2/h) has independent normalization factors h for spacial and color components. A precomputed Normal distribution is used for the weight kernel.
Output is provided in the form of an image where each pixel contains the index of a region the pixel belongs to. Three other lists provide color value of the region, number of pixels in the region and the location of the mean-shift peak for that region. This output is unlikely to be final processing step since it will over segment the image. Merging of similar modes and pruning of small regions is a common next step.
An approximation of running mean-shift on each pixel is performed if the 'fast' flag is set to true. The approximation is about 5x faster and works by saving the mean-shift trajectory [2]. All points along the trajectory are given the same mode. When performing mean-shift if a pixel is encountered which has already been assigned a mode the search stops. This approximation tends to produce more regions and reduces clustering quality in high texture regions.
NOTES:
- Spacial distance is normalized by dividing the found Euclidean distance squared by the maximum possible Euclidean distance squared, thus ensuring it will be between 0 and 1.
- Color distance is normalized by dividing it by the maximum allows Euclidean distance squared. If its distance is more than the maximum allowed value then G() will be zero.
- Image edges are handled by truncating the spacial kernel. This truncation will create an asymmetric kernel, but there is really no good way to handle image edges.
CITATIONS:
- 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.
- Christoudias, Christopher M., Bogdan Georgescu, and Peter Meer. "Synergism in low level vision." Pattern Recognition, 2002. Proceedings. 16th International Conference on. Vol. 4. IEEE, 2002.
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.ddogleg.struct.Stoppable
Stoppable.Stopped
-
Field Summary
Modifier and TypeFieldDescriptionprotected float
protected T
protected float
protected int
protected DogArray<float[]>
protected DogArray<Point2D_I32>
protected DogArray_I32
protected float
protected float
protected GrayS32
protected GrayS32
protected int
protected int
protected float[]
protected boolean
protected float[]
protected int
protected int
-
Constructor Summary
ModifierConstructorDescriptionprotected
SegmentMeanShiftSearch
(int maxIterations, float convergenceTol, int radiusX, int radiusY, float maxColorDistance, boolean fast) Configures mean-shift segmentation -
Method Summary
Modifier and TypeMethodDescriptionstatic float
distanceSq
(float[] a, float[] b) Returns the Euclidean distance squared between the two vectorsDogArray<float[]>
Location of each peak in the imageFrom peak index to pixel indexNumber of pixels which each peak as a memberboolean
abstract void
Performs mean-shift clustering on the input imagevoid
protected float
weight
(float distance) Returns the weight given the normalized distance.
-
Field Details
-
maxIterations
protected int maxIterations -
convergenceTol
protected float convergenceTol -
radiusX
protected int radiusX -
radiusY
protected int radiusY -
widthX
protected int widthX -
widthY
protected int widthY -
maxColorDistanceSq
protected float maxColorDistanceSq -
pixelToMode
-
quickMode
-
modeLocation
-
modeMemberCount
-
modeColor
-
spacialTable
protected float[] spacialTable -
weightTable
protected float[] weightTable -
image
-
modeX
protected float modeX -
modeY
protected float modeY -
stopRequested
protected boolean stopRequested
-
-
Constructor Details
-
SegmentMeanShiftSearch
protected SegmentMeanShiftSearch(int maxIterations, float convergenceTol, int radiusX, int radiusY, float maxColorDistance, boolean fast) Configures mean-shift segmentation- Parameters:
maxIterations
- Maximum number of mean-shift iterations. Try 30convergenceTol
- When the change is less than this amount stop. Try 0.005radiusX
- Spacial kernel radius x-axisradiusY
- Spacial kernel radius y-axismaxColorDistance
- Maximum allowed Euclidean distance squared for the color componentfast
- Improve runtime by approximating running mean-shift on each pixel. Try true.
-
-
Method Details
-
process
Performs mean-shift clustering on the input image- Parameters:
image
- Input image
-
distanceSq
public static float distanceSq(float[] a, float[] b) Returns the Euclidean distance squared between the two vectors -
weight
protected float weight(float distance) Returns the weight given the normalized distance. Instead of computing the kernel distance every time a lookup table with linear interpolation is used. The distance has a domain from 0 to 1, inclusive- Parameters:
distance
- Normalized Euclidean distance squared. From 0 to 1.- Returns:
- Weight.
-
getPixelToRegion
From peak index to pixel index -
getModeLocation
Location of each peak in the image -
getRegionMemberCount
Number of pixels which each peak as a member -
getModeColor
-
getImageType
-
requestStop
public void requestStop()- Specified by:
requestStop
in interfaceStoppable
-
isStopRequested
public boolean isStopRequested()- Specified by:
isStopRequested
in interfaceStoppable
-