Class AlgorithmAGVF
- All Implemented Interfaces:
AlgorithmInterface,ActionListener,WindowListener,Runnable,EventListener
- Direct Known Subclasses:
AlgorithmCellTrackingAGVF
2 iterative processes are used. The first calculates the gradient vector field. The gradient of the edge map is used to initialize the iterative equation for the gradient vector field. In the second iterative process which calculates the boundary, the point is moved by the gradient vector field.
* This original GVF algorithm has:
u[i] += mu*del2(u[i]) - Math.sqrt(fx[i]*fx[i] + fy[i]*fy[i])*(u[i] - fx[i]);
v[i] += mu*del2(v[i]) - Math.sqrt(fx[i]*fx[i] + fy[i]*fy[i])*(v[i] - fy[i]);
This program uses the generalized GVF algorithm with:
du/dt = g(|grad f|)del2xy(u) - h(|grad f|)*(u - fx) dv/dt = g(|grad f|)del2xy(v) - h(|grad f|)*(v - fy) g[i] =
Math.exp(-(fx[i]*fx[i] + fy[i]*fy[i])/(k*k))
h[i] = 1 - g[i] du/dt = u(i,j,n+1) - u(i,j,n)/(delta t) del2xy(u) = (1/((delta x)(delta y)))* (u(i+1,j,n) +
u(i,j+1,n) + u(i-1,j,n) + u(i,j-1,n) - 4u(i,j,n) = del2(u)/((delta x)*(delta y)) u(i,j,n+1) = u(i,j,n) + g(|grad
f|)*(delta t)/((delta x)*(delta y)) * del2(u) - (1 - g(|grad f|)*(u - fx)*delta t Letting detla x = 1, delta y = 1,
and delta t = 0.25: u[i] += 0.25f*(g[i]*del2(u[i]) - (1 - g[i])*(u[i] - fx[i]));
v[i] += 0.25f*(g[i]*del2(v[i]) - (1 - g[i])*(v[i] - fy[i]));
Stability for the original GVF algorithm requires mu invalid input: '<'= 0.25f and stability for the generalized GVF algorithm
requires that delta t invalid input: '<'= (delta x * delta y)/(4 * gmax) = 1/4. For 3D: delta t invalid input: '<'= (delta x * delta y * delta z)/(6*
gmax) = 1/6.
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.
Useful references on gradient vector field:
1.) "Gradient Vector Flow: A New External Force For Snakes", Chenyang Xu and Jerry L. Prince, IEEE Proc. Conf. on
Comp. Vis. Patt. Recog. (CVPR'97), pp. 66- 71.
2.) "Snakes, Shapes, and Gradient Vector Flow", Chenyang Xu and Jerry L. Prince, IEEE Transactions on Image
Processing, March, 1998, pp. 359-369.
3.) "Generalized gradient vector flow external forces for active contours", Chenyang Xu and Jerry Prince, Signal
Processing, 71(2), December, 1998, pp. 131-139.
4.) "Gradient Vector Flow Deformable Models", Handbook of Medical Imaging, ChenYang Xu and Jerry Prince, edited by I.
Bankman, Academic Press, 2000, pp. 159-169.
5.) "Image Segmentation Using Deformable Models", Handbook of Medical Imaging -- Volume 2: Medical Imaging and
Analysis, Chenyang Xu, Dzung Pham, and Jerry Prince, edited by J.M. Fitzpatrick and M. Sonka, SPIE Press, May, 2000,
pp. 129-174.
More information on gradient vector field can be found at Chenyang Xu's homepage at http://iacl.ece.jhu.edu/~chenyang
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class java.lang.Thread
Thread.Builder, Thread.State, Thread.UncaughtExceptionHandler -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected intMaximum iterations to generate new boundary.private booleanOnly applies to 3D, if true do slice by slice.private float[]DOCUMENT ME!protected int[]DOCUMENT ME!private float[]DOCUMENT ME!private float[]DOCUMENT ME!private float[]DOCUMENT ME!private float[]DOCUMENT ME!private float[]DOCUMENT ME!private intMaximum iterations to generate generalized gradient vector field.private float[]Storage location of the first derivative of the Gaussian in the X direction.private float[]Storage location of the first derivative of the Gaussian in the Y direction.private float[]Storage location of the first derivative of the Gaussian in the Z direction.private int[]Dimensionality of the kernel.private floatIn the paper "Generalized gradient vector flow external forces for active contours" by Chenyang Xu and Jerry Prince values of 0.05, 0.15, and 0.2 were used for k.private intDOCUMENT ME!private float[]private booleanIf true propagate the contour to an adjacent slice.private VOIThe resultant polygon and the evolution has completed.private float[]Standard deviations of the gaussian used to calculate the kernels.private floatDOCUMENT ME!private VOIThe initial VOI to initialize the evolution process.private intDOCUMENT ME!private float[]DOCUMENT ME!private float[]DOCUMENT ME!private float[]DOCUMENT ME!protected intDOCUMENT ME!protected intDOCUMENT ME!protected intDOCUMENT ME!Fields 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
ConstructorsConstructorDescriptionAlgorithmAGVF(ModelImage resultImage, ModelImage srcImg, float[] sigmas, int gvfIterations, int boundaryIterations, float k, float smoothness, VOI srcVOI, boolean do25D) Creates a new AlgorithmAGVF object. -
Method Summary
Modifier and TypeMethodDescriptionvoidalgorithmPerformed(AlgorithmBase algorithm) Called after an algorithm this listener is registered to exits (maybe successfully, maybe not).private voidcalc25D()Prepares the data and runs the algorithm for a 3D image.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 voidcalcGVF(int sliceNum, float[] imgBuffer) Calculate GVF from image buffer.private voidcalcGVF3D(float[] imgBuffer) Calculate GVF from 3D image buffer.protected 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 Vector<WildMagic.LibFoundation.Mathematics.Vector3f> cleanLine(float[] xPts, float[] yPts, float[] zPts) protected voidcleanup()Sets structures to null.private doubledistance(float x1, float x2, float y1, float y2) Calculates the euclidian distance between two points.voidfinalize()Prepares this class for destruction.protected static floatgetBilinear(int i, float dx, float dy, int[] iExtents, float[] image) Performs bilinear interpolation of image data.Returns the resultant VOI.private voidMakes derivative kernels to be used in the calculation of the gradient magnitude.private voidMakes 3D derivative kernels to be used in the calculation of the gradient magnitude.voidstarts the snake algorithm.protected voidrunSnake(float[] xPoints, float[] yPoints, float[] zPoints, float[] u, float[] v, VOIBase resultContour) Actual function that evolves the boundary.protected voidActual function that evolves the boundary.private voidTakes the polygon and forms two special arrarys for use in runSnake.private voidTakes the polygon and forms two special arrarys for use in runSnake.voidsetPropagation(boolean flag) Sets the propagation flag.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, 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
-
boundaryIterations
protected int boundaryIterationsMaximum iterations to generate new boundary. -
extents
protected int[] extentsDOCUMENT ME! -
xDim
protected int xDimDOCUMENT ME! -
yDim
protected int yDimDOCUMENT ME! -
zDim
protected int zDimDOCUMENT ME! -
do25D
private boolean do25DOnly applies to 3D, if true do slice by slice. -
expGvfBuffer
private float[] expGvfBufferDOCUMENT ME! -
fx
private float[] fxDOCUMENT ME! -
fy
private float[] fyDOCUMENT ME! -
fz
private float[] fzDOCUMENT ME! -
gVal
private float[] gValDOCUMENT ME! -
gvfBuffer
private float[] gvfBufferDOCUMENT ME! -
gvfIterations
private int gvfIterationsMaximum iterations to generate generalized gradient vector field. -
GxData
private float[] GxDataStorage location of the first derivative of the Gaussian in the X direction. -
GyData
private float[] GyDataStorage location of the first derivative of the Gaussian in the Y direction. -
GzData
private float[] GzDataStorage location of the first derivative of the Gaussian in the Z direction. -
kExtents
private int[] kExtentsDimensionality of the kernel. -
kValue
private float kValueIn the paper "Generalized gradient vector flow external forces for active contours" by Chenyang Xu and Jerry Prince values of 0.05, 0.15, and 0.2 were used for k. -
length
private int lengthDOCUMENT ME! -
propagationFlag
private boolean propagationFlagIf true propagate the contour to an adjacent slice. -
resultVOI
The resultant polygon and the evolution has completed. -
sigmas
private float[] sigmasStandard deviations of the gaussian used to calculate the kernels. -
smoothness
private float smoothnessDOCUMENT ME! -
srcVOI
The initial VOI to initialize the evolution process. -
stSlice
private int stSliceDOCUMENT ME! -
uVal
private float[] uValDOCUMENT ME! -
vVal
private float[] vValDOCUMENT ME! -
wVal
private float[] wValDOCUMENT ME! -
outputBuffer
private float[] outputBuffer
-
-
Constructor Details
-
AlgorithmAGVF
public AlgorithmAGVF(ModelImage resultImage, ModelImage srcImg, float[] sigmas, int gvfIterations, int boundaryIterations, float k, float smoothness, VOI srcVOI, boolean do25D) Creates a new AlgorithmAGVF object.- Parameters:
resultImage- image of GVF field magnitudesrcImg- 2D or 3D source imagesigmas- describe the scale of the gaussian in each dimensiongvfIterations- iterations in calculating GVF fieldboundaryIterations- iterations in calculating boundaryk- GVF constantsmoothness- DOCUMENT ME!srcVOI- VOI that is to be evolveddo25D- only applies to 3D, if true do slice by slice
-
-
Method Details
-
finalize
public void finalize()Prepares this class for destruction.- Overrides:
finalizein classAlgorithmBase
-
getResultVOI
Returns the resultant VOI.- Returns:
- resultant VOI that has localized to the boundaries of the object
-
runAlgorithm
public void runAlgorithm()starts the snake algorithm.- Specified by:
runAlgorithmin classAlgorithmBase
-
setPropagation
public void setPropagation(boolean flag) Sets the propagation flag.- Parameters:
flag- if true result contour from a slice is propagated to the adjacent slice and used to initialize the snake algorithm for that slice. If false the snake algorithm stops after optimizing the boundary in the present slice.
-
getBilinear
protected static float getBilinear(int i, float dx, float dy, int[] iExtents, float[] image) Performs bilinear interpolation of image data.- Parameters:
i- index into imagedx- change in x from integerdy- change in y from integeriExtents- dimensions of imageimage- image data- Returns:
- DOCUMENT ME!
-
cleanLine
protected 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:
- DOCUMENT ME!
-
cleanLine
private Vector<WildMagic.LibFoundation.Mathematics.Vector3f> cleanLine(float[] xPts, float[] yPts, float[] zPts) -
cleanup
protected void cleanup()Sets structures to null. -
runSnake
Actual function that evolves the boundary.- Parameters:
xPoints- x coordinates that describe the contouryPoints- y coordinates that describe the contouru- x component of the GVFv- y component of the GVFresultGon- resultant polygon
-
runSnake
protected void runSnake(float[] xPoints, float[] yPoints, float[] zPoints, float[] u, float[] v, VOIBase resultContour) Actual function that evolves the boundary.- Parameters:
xPoints- x coordinates that describe the contouryPoints- y coordinates that describe the contouru- x component of the GVFv- y component of the GVFresultGon- resultant polygon
-
calc25D
private void calc25D()Prepares the data and runs the algorithm for a 3D image. -
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. -
calcGVF
private void calcGVF(int sliceNum, float[] imgBuffer) Calculate GVF from image buffer.- Parameters:
sliceNum-imgBuffer- DOCUMENT ME!
-
calcGVF3D
private void calcGVF3D(float[] imgBuffer) Calculate GVF from 3D image buffer.- Parameters:
imgBuffer- DOCUMENT ME!
-
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:
- DOCUMENT ME!
-
makeKernels2D
private void makeKernels2D()Makes derivative kernels to be used in the calculation of the gradient magnitude. -
makeKernels3D
private void makeKernels3D()Makes 3D derivative kernels to be used in the calculation of the gradient magnitude. -
setPoints
Takes the polygon and forms two special arrarys for use in runSnake.- Parameters:
xPoints- storage location of array of x coord. pointsyPoints- storage location array of y coord. pointsgon- initial polygon
-
setPoints
Takes the polygon and forms two special arrarys for use in runSnake.- Parameters:
xPoints- storage location of array of x coord. pointsyPoints- storage location array of y coord. pointsgon- initial polygon
-
algorithmPerformed
Description copied from interface:AlgorithmInterfaceCalled after an algorithm this listener is registered to exits (maybe successfully, maybe not). If the algorithm is run in a separate thread, this call will be made within that thread. If not, this call will be made from that same, shared thread.- Specified by:
algorithmPerformedin interfaceAlgorithmInterface- Parameters:
algorithm- the algorithm which has just completed
-