Package gov.nih.mipav.model.algorithms
Class AlgorithmSnake
- java.lang.Object
-
- java.lang.Thread
-
- gov.nih.mipav.model.algorithms.AlgorithmBase
-
- gov.nih.mipav.model.algorithms.AlgorithmSnake
-
- All Implemented Interfaces:
java.awt.event.ActionListener,java.awt.event.WindowListener,java.lang.Runnable,java.util.EventListener
public class AlgorithmSnake extends AlgorithmBase
Snake-like algorithm deriviative. The algorithm is supplied a polygon (VOI - contour) and that polygon is allowed to evolve to the edge of the object generated by calculating the gradient magnitude (i.e. the energy function) at scale define by the user. The user/programmer supplies the sigmas (scales) at which to calculate the gradient magnitude. A large scale slows the snake and causes the snake to conform to large scale structure. A small sigma value causes the snake to conform to the small scale structure is therefore more sensitive to noise. The three-dimensional version is really a two-and-half dimensional algorithm where the resultant contour in a slice is projected into the adjacent slice and is used as an initialization to the evolution in the new slice.- Version:
- 0.1 Feb 11, 1998
- Author:
- Matthew J. McAuliffe, Ph.D.
- See Also:
AlgorithmBSpline,GenerateGaussian,AlgorithmVOISimplexOpt,AlgorithmBSnake
-
-
Field Summary
Fields Modifier and Type Field Description static intANY_DIRIndicates boundary can move in or out.private intboundaryIterationsMaximum number of snake iterations.private intevolveDirectionIndicates boundary how the VOI boundary can move - in and/or out.private float[]GxDataStorage location of the first derivative of the Gaussian in the X direction.private float[]GyDataStorage location of the first derivative of the Gaussian in the Y direction.private float[]GzDataStorage location of the first derivative of the Gaussian in the Z direction.static intIN_DIRIndicates boundary can move in.private int[]kExtentsDimensionality of the kernel.static intOUT_DIRIndicates boundary can move out.static intPROP_ALLPropagate the source VOI to slices above and below its current slice.static intPROP_NEXTPropagate the source VOI to slices above its current slice in the volume.static intPROP_PREVPropagate the source VOI to slices below its current slice in the volume.static intPROP_SINGLEDo not propagate the VOI to any slices (2D).private static floatPROP_THRESHOLDThe maximum ratio of change in the energy under the VOI after propagation.private intpropagationTypeThe VOI propagation mode to use.private VOIresultVOIThe resultant polygon and the evolution has completed.private float[]sigmasStandard deviations of the gaussian used to calculate the kernels.private floatsmoothnessThe maximum angle we want to have between points in the result VOI.private ModelImagesrcImageSource image.private VOIsrcVOIThe initial VOI to initialize the evolution process.-
Fields inherited from class gov.nih.mipav.model.algorithms.AlgorithmBase
destFlag, destImage, image25D, mask, maxProgressValue, minProgressValue, multiThreadingEnabled, nthreads, progress, progressModulus, progressStep, runningInSeparateThread, separable, threadStopped
-
-
Constructor Summary
Constructors Constructor Description AlgorithmSnake(ModelImage _srcImg, float[] _sigmas, int _boundaryIterations, float _smoothness, VOI srcVOI, int boundDir)Set up the snake algorithm so that it can be run.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private voidcalc2D()Prepares the data and runs the algorithm for a 2D image.private voidcalc3D()Prepares the data and runs the algorithm for a 3D image.private java.util.Vector<WildMagic.LibFoundation.Mathematics.Vector2f>cleanLine(float[] xPts, float[] yPts)Removes points (vectors) that form sharp angles (i.e. smoothes boudnary) Also adds points separated by some distance and removes adjacent pointsprivate java.util.Vector<WildMagic.LibFoundation.Mathematics.Vector3f>cleanLine(float[] xPts, float[] yPts, float[] zPts)private doubledistance(float x1, float x2, float y1, float y2)Calculates the euclidian distance between two points.private doubledistance(int x1, int x2, int y1, int y2)Calculates the euclidian distance between two points.voidfinalize()Prepares this class for destruction.VOIgetResultVOI()Returns the resultant VOI.private voidmakeKernels2D()Makes derivative kernels to be used in the calculation of the gradient magnitude.private voidmakeKernels3D()Makes derivative kernels to be used in the calculation of the gradient magnitude.private voidpropDown(VOIContour resultContour, VOI resultVOI, float baseEnergy, int baseNPts)private voidpropUp(VOIContour resultContour, VOI resultVOI, float baseEnergy, int baseNPts)voidrunAlgorithm()run - starts the snake algorithm.private floatrunSnake(float[] xPoints, float[] yPoints, float[] zPoints, float[] image, VOIBase contour)private floatrunSnake(float[] xPoints, float[] yPoints, float[] image, java.awt.Polygon resultGon)Actual function that evolves the boundary by moving normal to the boundary.private voidsetPoints(float[] xPoints, float[] yPoints, float[] zPoints, VOIBase contour)private voidsetPoints(float[] xPoints, float[] yPoints, java.awt.Polygon gon)Takes the polygon and forms two special arrays for use in runSnake.voidsetPropagation(int type)Sets the propagation type.-
Methods inherited from class gov.nih.mipav.model.algorithms.AlgorithmBase
actionPerformed, addListener, addProgressChangeListener, calculateImageSize, calculatePrincipleAxis, computeElapsedTime, computeElapsedTime, convertIntoFloat, delinkProgressToAlgorithm, delinkProgressToAlgorithmMulti, displayError, errorCleanUp, 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
-
PROP_SINGLE
public static final int PROP_SINGLE
Do not propagate the VOI to any slices (2D).- See Also:
- Constant Field Values
-
PROP_NEXT
public static final int PROP_NEXT
Propagate the source VOI to slices above its current slice in the volume.- See Also:
- Constant Field Values
-
PROP_PREV
public static final int PROP_PREV
Propagate the source VOI to slices below its current slice in the volume.- See Also:
- Constant Field Values
-
PROP_ALL
public static final int PROP_ALL
Propagate the source VOI to slices above and below its current slice.- See Also:
- Constant Field Values
-
ANY_DIR
public static final int ANY_DIR
Indicates boundary can move in or out.- See Also:
- Constant Field Values
-
IN_DIR
public static final int IN_DIR
Indicates boundary can move in.- See Also:
- Constant Field Values
-
OUT_DIR
public static final int OUT_DIR
Indicates boundary can move out.- See Also:
- Constant Field Values
-
PROP_THRESHOLD
private static final float PROP_THRESHOLD
The maximum ratio of change in the energy under the VOI after propagation.- See Also:
- Constant Field Values
-
boundaryIterations
private int boundaryIterations
Maximum number of snake iterations.
-
evolveDirection
private int evolveDirection
Indicates boundary how the VOI boundary can move - in and/or out.
-
GxData
private float[] GxData
Storage location of the first derivative of the Gaussian in the X direction.
-
GyData
private float[] GyData
Storage location of the first derivative of the Gaussian in the Y direction.
-
GzData
private float[] GzData
Storage location of the first derivative of the Gaussian in the Z direction.
-
kExtents
private int[] kExtents
Dimensionality of the kernel.
-
propagationType
private int propagationType
The VOI propagation mode to use.
-
resultVOI
private VOI resultVOI
The resultant polygon and the evolution has completed.
-
sigmas
private float[] sigmas
Standard deviations of the gaussian used to calculate the kernels.
-
smoothness
private float smoothness
The maximum angle we want to have between points in the result VOI.
-
srcImage
private ModelImage srcImage
Source image.
-
srcVOI
private VOI srcVOI
The initial VOI to initialize the evolution process.
-
-
Constructor Detail
-
AlgorithmSnake
public AlgorithmSnake(ModelImage _srcImg, float[] _sigmas, int _boundaryIterations, float _smoothness, VOI srcVOI, int boundDir)
Set up the snake algorithm so that it can be run.- Parameters:
_srcImg- 2D or 3D source image_sigmas- describe the scale of the gaussian in each dimension_boundaryIterations- maximum number of snake iterations_smoothness- the boundary smoothness parametersrcVOI- VOI that is to be evolvedboundDir- indicates the boundary direction (in and/or out)
-
-
Method Detail
-
finalize
public void finalize()
Prepares this class for destruction.- Overrides:
finalizein classAlgorithmBase
-
getResultVOI
public VOI getResultVOI()
Returns the resultant VOI.- Returns:
- resultant VOI that has localized to the boundaries of the object
-
runAlgorithm
public void runAlgorithm()
run - starts the snake algorithm.- Specified by:
runAlgorithmin classAlgorithmBase
-
setPropagation
public void setPropagation(int type)
Sets the propagation type.- Parameters:
type- if PROP_ALL, result contour from a slice is propagated to the adjacent slice and used to initialize the snake algorithm for that slice. If PROP_NEXT, result contour from the original slice is propagated to the next slice and used to initialize the snake algorithm for that slice. If PROP_PREV, result contour from the orginal slice is propagated to the previous slice. If PROP_SINGLE, the snake algorithm stops after optimizing the boundary in the present slice.
-
calc2D
private void calc2D()
Prepares the data and runs the algorithm for a 2D image.
-
calc3D
private void calc3D()
Prepares the data and runs the algorithm for a 3D image.
-
cleanLine
private java.util.Vector<WildMagic.LibFoundation.Mathematics.Vector2f> cleanLine(float[] xPts, float[] yPts)Removes points (vectors) that form sharp angles (i.e. smoothes boudnary) Also adds points separated by some distance and removes adjacent points- Parameters:
xPts- x coords of points that define a contouryPts- y coords of points that define a contour- Returns:
- an ordered list of the points along the cleaned-up line
-
cleanLine
private java.util.Vector<WildMagic.LibFoundation.Mathematics.Vector3f> cleanLine(float[] xPts, float[] yPts, float[] zPts)
-
distance
private double distance(int x1, int x2, int y1, int y2)Calculates the euclidian distance between two points.- Parameters:
x1- first x coord.x2- seconde x coord.y1- first y1 coord.y2- seconde y2 coord.- Returns:
- the distance between the points
(x1,y1)and(x2,y2)
-
distance
private double distance(float x1, float x2, float y1, float y2)Calculates the euclidian distance between two points.- Parameters:
x1- first x coord.x2- seconde x coord.y1- first y1 coord.y2- seconde y2 coord.- Returns:
- the distance between the points
(x1,y1)and(x2,y2)
-
makeKernels2D
private void makeKernels2D()
Makes derivative kernels to be used in the calculation of the gradient magnitude.
-
makeKernels3D
private void makeKernels3D()
Makes derivative kernels to be used in the calculation of the gradient magnitude.
-
runSnake
private float runSnake(float[] xPoints, float[] yPoints, float[] image, java.awt.Polygon resultGon)Actual function that evolves the boundary by moving normal to the boundary.- Parameters:
xPoints- x coordinates that describe the contouryPoints- y coordinates that describe the contourimage- image dataresultGon- resultant polygon- Returns:
- the sum of the energy along the boundary of the
resultGon
-
runSnake
private float runSnake(float[] xPoints, float[] yPoints, float[] zPoints, float[] image, VOIBase contour)
-
propDown
private void propDown(VOIContour resultContour, VOI resultVOI, float baseEnergy, int baseNPts)
-
propUp
private void propUp(VOIContour resultContour, VOI resultVOI, float baseEnergy, int baseNPts)
-
setPoints
private void setPoints(float[] xPoints, float[] yPoints, java.awt.Polygon gon)Takes the polygon and forms two special arrays for use in runSnake.- Parameters:
xPoints- storage location of array of x coord. pointsyPoints- storage location array of y coord. pointsgon- initial polygon
-
setPoints
private void setPoints(float[] xPoints, float[] yPoints, float[] zPoints, VOIBase contour)
-
-