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:
java.awt.event.ActionListener,java.awt.event.WindowListener,java.lang.Runnable,java.util.EventListener
public class AlgorithmMeanShiftSegmentation extends AlgorithmBase
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 Classes Modifier and Type Class Description private classAlgorithmMeanShiftSegmentation.ClassStateStructstatic classAlgorithmMeanShiftSegmentation.kernelTypeprivate classAlgorithmMeanShiftSegmentation.RAListprivate classAlgorithmMeanShiftSegmentation.REGIONprivate classAlgorithmMeanShiftSegmentation.RegionListstatic classAlgorithmMeanShiftSegmentation.SpeedUpLevelprivate classAlgorithmMeanShiftSegmentation.userWeightFunct
-
Field Summary
Fields Modifier and Type Field Description private ModelImageboundariesImageprivate intcfprivate AlgorithmMeanShiftSegmentation.ClassStateStructclass_stateprivate AlgorithmMeanShiftSegmentation.userWeightFunctcurprivate double[]dataprivate doubleepsilonprivate doubleEPSILONprivate ModelImagefilteredImageprivate AlgorithmMeanShiftSegmentation.RAList[]freeRAListprivate doubleGAUSS_INCREMENTprivate doubleGAUSS_LIMITprivate intGAUSS_NUM_ELSprivate float[]hprivate AlgorithmMeanShiftSegmentation.userWeightFunctheadprivate intheightprivate double[]incrementprivate int[]indexTableprivate AlgorithmMeanShiftSegmentation.kernelType[]kernelprivate intkpprivate intLprivate int[]labelsprivate intLIMITprivate doubleLtprivate float[]LUV_dataprivate doubleLUV_thresholdprivate booleanmeasureTimeprivate intminRegionprivate int[]modePointCountsprivate float[]modesprivate byte[]modeTableprivate float[]msRawDataprivate intNprivate int[]neighprivate intNODE_MULTIPLEprivate float[]offsetprivate byte[]outputBuffer(package private) int[]Pprivate intpointCountprivate int[]pointListprivate AlgorithmMeanShiftSegmentation.RAList[]raListprivate floatrangeBandwidthprivate AlgorithmMeanShiftSegmentation.kernelTyperangeKernelTypeprivate AlgorithmMeanShiftSegmentation.RAList[]raPoolprivate intregionCount(package private) AlgorithmMeanShiftSegmentation.RegionListregionListprivate double[][]RGB(package private) floatrR2private byte[]segmentationBoundariesprivate floatspatialBandwidthprivate AlgorithmMeanShiftSegmentation.kernelTypespatialKernelTypeprivate doublespeedThresholdprivate AlgorithmMeanShiftSegmentation.SpeedUpLevelspeedUpLevelprivate inttprivate doubleTC_DIST_FACTORprivate doubleUn_primeprivate doubleVn_primeprivate double[][]wprivate double[]weightMapprivate booleanweightMapDefinedprivate intwidthprivate double[][]XYZprivate doubleYnprivate intzprivate intzDim-
Fields inherited from class gov.nih.mipav.model.algorithms.AlgorithmBase
destFlag, destImage, image25D, mask, maxProgressValue, minProgressValue, multiThreadingEnabled, nthreads, progress, progressModulus, progressStep, runningInSeparateThread, separable, srcImage, threadStopped
-
-
Constructor Summary
Constructors Constructor Description 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 Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private voidbuildRAM()private voidclassConsistencyCheck(int iN, boolean usingLattice)private voidcomputeEdgeStrengths()private voidconnect()private voiddefineBoundaries()private voiddefineLInput()private voiddestroyOutput()private voiddestroyRAM()private voidfill(int regionLoc, int label)private voidfilter()private voidgenerateLookupTable()private voidinitializeOutput()private intinsert(AlgorithmMeanShiftSegmentation.RAList source, AlgorithmMeanShiftSegmentation.RAList[] entry)private booleaninWindow(int mode1, int mode2)private voidLUVtoRGB(float[] luvVal, int luvOffset, byte[] rgbVal, int rgbOffset)private voidmeanShift()private 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)voidrunAlgorithm()Actually runs the algorithm.private voidsegment()private floatsqDistance(int mode1, int mode2)private voidtransitiveClosure()-
Methods 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, windowOpened
-
Methods 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, join, join, join, onSpinWait, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, suspend, toString, yield
-
-
-
-
Field Detail
-
L
private int L
-
N
private int N
-
kp
private int kp
-
P
int[] P
-
Yn
private final double Yn
- See Also:
- Constant Field Values
-
Un_prime
private final double Un_prime
- See Also:
- Constant Field Values
-
Vn_prime
private final double Vn_prime
- See Also:
- Constant Field Values
-
Lt
private final double Lt
- See Also:
- Constant Field Values
-
XYZ
private final double[][] XYZ
-
RGB
private final double[][] RGB
-
GAUSS_NUM_ELS
private final int GAUSS_NUM_ELS
- See Also:
- Constant Field Values
-
GAUSS_LIMIT
private final double GAUSS_LIMIT
- See Also:
- Constant Field Values
-
GAUSS_INCREMENT
private final double GAUSS_INCREMENT
- See Also:
- Constant Field Values
-
EPSILON
private final double EPSILON
- See Also:
- Constant Field Values
-
TC_DIST_FACTOR
private final double TC_DIST_FACTOR
- See Also:
- Constant Field Values
-
LIMIT
private final int LIMIT
- See Also:
- Constant Field Values
-
NODE_MULTIPLE
private final int NODE_MULTIPLE
- See Also:
- Constant Field Values
-
data
private double[] data
-
height
private int height
-
width
private int width
-
h
private float[] h
-
offset
private float[] offset
-
kernel
private AlgorithmMeanShiftSegmentation.kernelType[] kernel
-
w
private double[][] w
-
increment
private double[] increment
-
head
private AlgorithmMeanShiftSegmentation.userWeightFunct head
-
cur
private AlgorithmMeanShiftSegmentation.userWeightFunct cur
-
class_state
private AlgorithmMeanShiftSegmentation.ClassStateStruct 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
private AlgorithmMeanShiftSegmentation.RAList[] raList
-
freeRAList
private AlgorithmMeanShiftSegmentation.RAList[] freeRAList
-
raPool
private AlgorithmMeanShiftSegmentation.RAList[] 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
private AlgorithmMeanShiftSegmentation.kernelType spatialKernelType
-
rangeKernelType
private AlgorithmMeanShiftSegmentation.kernelType rangeKernelType
-
spatialBandwidth
private float spatialBandwidth
-
rangeBandwidth
private float rangeBandwidth
-
minRegion
private int minRegion
-
speedUpLevel
private AlgorithmMeanShiftSegmentation.SpeedUpLevel speedUpLevel
-
measureTime
private boolean measureTime
-
speedThreshold
private double speedThreshold
-
weightMap
private double[] weightMap
-
weightMapDefined
private boolean weightMapDefined
-
filteredImage
private ModelImage filteredImage
-
boundariesImage
private ModelImage boundariesImage
-
-
Constructor Detail
-
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 Detail
-
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)
-
-