Package gov.nih.mipav.model.algorithms
Class AlgorithmMeanShiftSegmentation
java.lang.Object
java.lang.Thread
gov.nih.mipav.model.algorithms.AlgorithmBase
gov.nih.mipav.model.algorithms.AlgorithmMeanShiftSegmentation
- All Implemented Interfaces:
ActionListener,WindowListener,Runnable,EventListener
The java code is ported from C++ code downloaded from http://coewww.rutgers.edu/riul/research/code.html.
The relevant web page section says:
Edge Detection and Image SegmentatiON (EDISON) System
C++ code, can be used through a graphical interface or command line.
The system is described in Synergism in low level vision.
For comments, please contact Bogdan Georgescu or Chris M. Christoudias.
The EDISON system contains the image segmentation/edge preserving filtering algorithm described in the
paper Mean shift: A robust approach toward feature space analysis and the edge detection algorithm
described in the paper Edge detection with embedded confidence.
Relevant points from reference 1:
This code works on 2 dimensional gray level and color images. RGB is converted to LUV for processing.
Location and range vectors are concatenated
in a joint spatial-range domain of dimension d = p + 2, where p = 1 in the gray level case, 3 for color
images, and p > 3 in the multispectral case. There is a spatial kernel bandwidth hs and a range kernel
bandwidth hr. For the 256 by 256 gray level cameraman image mean shift filtering a uniform kernel
having hs = 8, hr = 4, M = 10 was used. For the 512 by 512 color image baboon normal filters with hs going from
8 to 32 and hr going from 4 to 16 were used. Only features with large spatial support are represented in
the filtered image when hs increases. On the other hand, only features with high color contrast survive
when hr is large. Mean shift filtering is run on the image before mean shift segmentation is performed.
In mean shift segmentation clusters are formed by grouping together pixels which are
closer than hs in the spatial domain and hr in the range domain. Assign a label Li to each of the pixels ]
depending on which cluster it belongs to. Optionally eliminate spatial regions containing less than M pixels.
The following were segmented with uniform kernels:
256 by 256 gray level MIT building with hs = 8, hr = 7, M = 20 into 225 homogeneous regions.
256 by 256 color room image with hs = 8, hr = 5, M = 20.
512 by 512 color lake image with hs = 16, hr = 7, M = 40.
512 by 512 color image hand with hs = 16, hr = 19, M = 40.
All 256 by 256 images used the same hs = 8 corresponding to a 17 by 17 spatial window,
while all 512 by 512 images used hs = 16 corresponding to a 31 by 31 window.
The range parameter hr and the smallest significant feature size M control the number
of regions in the segmented image. The more an image deviates from the assumed piecewise
constant model, larger values have to be used for hr and M to discard the effect of small
local variations in feature space.
4 color landscape images were segmented with hs = 8, hr = 7, M = 100.
4 other color examples used hs = 8, hr = 7, M = 20.
This code was ported by William Gandler.
References
-------------------------------------------------------------------------------------------------
[1] D. Comanicu, P. Meer: "Mean shift: A robust approach toward feature space analysis".
IEEE Trans. Pattern Anal. Machine Intell., May 2002.
[2] P. Meer, B. Georgescu: "Edge detection with embedded confidence". IEEE Trans. Pattern Anal.
Machine Intell., 28, 2001.
[3] C. Christoudias, B. Georgescu, P. Meer: "Synergism in low level vision". 16th International
Conference of Pattern Recognition, Track 1 - Computer Vision and Robotics, Quebec City,
Canada, August 2001.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate classstatic enumprivate classprivate classprivate classstatic enumprivate classNested classes/interfaces inherited from class java.lang.Thread
Thread.Builder, Thread.State, Thread.UncaughtExceptionHandler -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate ModelImageprivate intprivate double[]private doubleprivate final doubleprivate ModelImageprivate AlgorithmMeanShiftSegmentation.RAList[]private final doubleprivate final doubleprivate final intprivate float[]private intprivate double[]private int[]private intprivate intprivate int[]private final intprivate final doubleprivate float[]private doubleprivate booleanprivate intprivate int[]private float[]private byte[]private float[]private intprivate int[]private final intprivate float[]private byte[](package private) int[]private intprivate int[]private AlgorithmMeanShiftSegmentation.RAList[]private floatprivate AlgorithmMeanShiftSegmentation.RAList[]private int(package private) AlgorithmMeanShiftSegmentation.RegionListprivate final double[][](package private) floatprivate byte[]private floatprivate doubleprivate intprivate final doubleprivate final doubleprivate final doubleprivate double[][]private double[]private booleanprivate intprivate final double[][]private final doubleprivate intprivate intFields inherited from class gov.nih.mipav.model.algorithms.AlgorithmBase
destFlag, destImage, image25D, mask, maxProgressValue, minProgressValue, multiThreadingEnabled, nthreads, progress, progressModulus, progressStep, runningInSeparateThread, separable, srcImage, threadStoppedFields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY -
Constructor Summary
ConstructorsConstructorDescriptionAlgorithmMeanShiftSegmentation(ModelImage destImage, ModelImage srcImage, AlgorithmMeanShiftSegmentation.kernelType spatialKernelType, AlgorithmMeanShiftSegmentation.kernelType rangeKernelType, float spatialBandwidth, float rangeBandwidth, int minRegion, AlgorithmMeanShiftSegmentation.SpeedUpLevel speedUpLevel, boolean measureTime, double speedThreshold, double[] weightMap, boolean weightMapDefined, ModelImage filteredImage, ModelImage boundariesImage) -
Method Summary
Modifier and TypeMethodDescriptionprivate voidbuildRAM()private voidclassConsistencyCheck(int iN, boolean usingLattice) private voidprivate voidconnect()private voidprivate voidprivate voidprivate voidprivate voidfill(int regionLoc, int label) private voidfilter()private voidprivate voidprivate intprivate booleaninWindow(int mode1, int mode2) private voidLUVtoRGB(float[] luvVal, int luvOffset, byte[] rgbVal, int rgbOffset) private voidprivate intmy_round(double in_x) private voidnewNonOptimizedFilter(float sigmaS, float sigmaR) private voidnewOptimizedFilter1(float sigmaS, float sigmaR) private voidnewOptimizedFilter2(float sigmaS, float sigmaR) private voidprune(int minRegion) private voidRGBtoLUV(float[] rgb, int rgbOffset, double[] luv, int luvOffset) voidActually runs the algorithm.private voidsegment()private floatsqDistance(int mode1, int mode2) private voidMethods inherited from class gov.nih.mipav.model.algorithms.AlgorithmBase
actionPerformed, addListener, addProgressChangeListener, calculateImageSize, calculatePrincipleAxis, computeElapsedTime, computeElapsedTime, convertIntoFloat, delinkProgressToAlgorithm, delinkProgressToAlgorithmMulti, displayError, errorCleanUp, finalize, fireProgressStateChanged, fireProgressStateChanged, fireProgressStateChanged, fireProgressStateChanged, fireProgressStateChanged, generateProgressValues, getDestImage, getElapsedTime, getMask, getMaxProgressValue, getMinProgressValue, getNumberOfThreads, getProgress, getProgressChangeListener, getProgressChangeListeners, getProgressModulus, getProgressStep, getProgressValues, getSrcImage, isCompleted, isImage25D, isMultiThreadingEnabled, isRunningInSeparateThread, isThreadStopped, linkProgressToAlgorithm, linkProgressToAlgorithm, makeProgress, notifyListeners, removeListener, removeProgressChangeListener, run, setCompleted, setImage25D, setMask, setMaxProgressValue, setMinProgressValue, setMultiThreadingEnabled, setNumberOfThreads, setProgress, setProgressModulus, setProgressStep, setProgressValues, setProgressValues, setRunningInSeparateThread, setSrcImage, setStartTime, setThreadStopped, startMethod, windowActivated, windowClosed, windowClosing, windowDeactivated, windowDeiconified, windowIconified, windowOpenedMethods inherited from class java.lang.Thread
activeCount, checkAccess, clone, countStackFrames, currentThread, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, isVirtual, join, join, join, join, ofPlatform, ofVirtual, onSpinWait, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, sleep, start, startVirtualThread, stop, suspend, threadId, toString, yield
-
Field Details
-
L
private int L -
N
private int N -
kp
private int kp -
P
int[] P -
Yn
private final double Yn- See Also:
-
Un_prime
private final double Un_prime- See Also:
-
Vn_prime
private final double Vn_prime- See Also:
-
Lt
private final double Lt- See Also:
-
XYZ
private final double[][] XYZ -
RGB
private final double[][] RGB -
GAUSS_NUM_ELS
private final int GAUSS_NUM_ELS- See Also:
-
GAUSS_LIMIT
private final double GAUSS_LIMIT- See Also:
-
GAUSS_INCREMENT
private final double GAUSS_INCREMENT- See Also:
-
EPSILON
private final double EPSILON- See Also:
-
TC_DIST_FACTOR
private final double TC_DIST_FACTOR- See Also:
-
LIMIT
private final int LIMIT- See Also:
-
NODE_MULTIPLE
private final int NODE_MULTIPLE- See Also:
-
data
private double[] data -
height
private int height -
width
private int width -
h
private float[] h -
offset
private float[] offset -
kernel
-
w
private double[][] w -
increment
private double[] increment -
head
-
cur
-
class_state
-
msRawData
private float[] msRawData -
labels
private int[] labels -
modes
private float[] modes -
modePointCounts
private int[] modePointCounts -
indexTable
private int[] indexTable -
LUV_data
private float[] LUV_data -
regionCount
private int regionCount -
modeTable
private byte[] modeTable -
pointList
private int[] pointList -
pointCount
private int pointCount -
rR2
float rR2 -
regionList
AlgorithmMeanShiftSegmentation.RegionList regionList -
neigh
private int[] neigh -
LUV_threshold
private double LUV_threshold -
raList
-
freeRAList
-
raPool
-
epsilon
private double epsilon -
z
private int z -
zDim
private int zDim -
t
private int t -
cf
private int cf -
segmentationBoundaries
private byte[] segmentationBoundaries -
outputBuffer
private byte[] outputBuffer -
spatialKernelType
-
rangeKernelType
-
spatialBandwidth
private float spatialBandwidth -
rangeBandwidth
private float rangeBandwidth -
minRegion
private int minRegion -
speedUpLevel
-
measureTime
private boolean measureTime -
speedThreshold
private double speedThreshold -
weightMap
private double[] weightMap -
weightMapDefined
private boolean weightMapDefined -
filteredImage
-
boundariesImage
-
-
Constructor Details
-
AlgorithmMeanShiftSegmentation
public AlgorithmMeanShiftSegmentation(ModelImage destImage, ModelImage srcImage, AlgorithmMeanShiftSegmentation.kernelType spatialKernelType, AlgorithmMeanShiftSegmentation.kernelType rangeKernelType, float spatialBandwidth, float rangeBandwidth, int minRegion, AlgorithmMeanShiftSegmentation.SpeedUpLevel speedUpLevel, boolean measureTime, double speedThreshold, double[] weightMap, boolean weightMapDefined, ModelImage filteredImage, ModelImage boundariesImage)
-
-
Method Details
-
runAlgorithm
public void runAlgorithm()Description copied from class:AlgorithmBaseActually runs the algorithm. Implemented by inheriting algorithms.- Specified by:
runAlgorithmin classAlgorithmBase
-
defineBoundaries
private void defineBoundaries() -
generateLookupTable
private void generateLookupTable() -
meanShift
private void meanShift() -
defineLInput
private void defineLInput() -
RGBtoLUV
private void RGBtoLUV(float[] rgb, int rgbOffset, double[] luv, int luvOffset) -
segment
private void segment() -
LUVtoRGB
private void LUVtoRGB(float[] luvVal, int luvOffset, byte[] rgbVal, int rgbOffset) -
my_round
private int my_round(double in_x) -
destroyRAM
private void destroyRAM() -
prune
private void prune(int minRegion) -
sqDistance
private float sqDistance(int mode1, int mode2) -
transitiveClosure
private void transitiveClosure() -
inWindow
private boolean inWindow(int mode1, int mode2) -
computeEdgeStrengths
private void computeEdgeStrengths() -
buildRAM
private void buildRAM() -
insert
private int insert(AlgorithmMeanShiftSegmentation.RAList source, AlgorithmMeanShiftSegmentation.RAList[] entry) -
filter
private void filter() -
connect
private void connect() -
fill
private void fill(int regionLoc, int label) -
newNonOptimizedFilter
private void newNonOptimizedFilter(float sigmaS, float sigmaR) -
newOptimizedFilter1
private void newOptimizedFilter1(float sigmaS, float sigmaR) -
newOptimizedFilter2
private void newOptimizedFilter2(float sigmaS, float sigmaR) -
initializeOutput
private void initializeOutput() -
destroyOutput
private void destroyOutput() -
classConsistencyCheck
private void classConsistencyCheck(int iN, boolean usingLattice)
-