Class AlgorithmAnisotropicDiffusion
- java.lang.Object
-
- java.lang.Thread
-
- gov.nih.mipav.model.algorithms.AlgorithmBase
-
- gov.nih.mipav.model.algorithms.filters.AlgorithmAnisotropicDiffusion
-
- All Implemented Interfaces:
AlgorithmInterface
,java.awt.event.ActionListener
,java.awt.event.WindowListener
,java.lang.Runnable
,java.util.EventListener
public class AlgorithmAnisotropicDiffusion extends AlgorithmBase implements AlgorithmInterface
This algorithm anisotropically diffuses an image. That is to say it blurs over regions of an image where the gradient mag. is relatively small but diffuses little over areas of the image where the gradient mag is large (i.e. edges). Therefore, objects are blurred but not edges of objects. K is a factor that controls the diffusion rate. A large value causes this algorithm to act like gaussian smoothing where the number of iterations is related to the sigma of the gaussian. Small values of k reduce the diffusion across edges.The basic equation is the I(x,y,z,t+1) = I(x,y,z,t) + lambda*c(x,y,z,t)*Laplacian(I(x,y,z,t)) I(x,y,z,t) is the brightness function. It is required that 0
This program uses the a constant times the square root of the sum of the squares of the normalized first order derivatives of the Gaussian function as an approximate gradient function. The constant is selected so that the maximium value of this approximation to the gradient function is 100.
- Version:
- 0.1 March 6, 1998
- Author:
- Matthew J. McAuliffe, Ph.D.
-
-
Field Summary
Fields Modifier and Type Field Description private boolean
entireImage
Flag, if true, indicates that the whole image should be processed.private float[]
GxData
Storage location of the first derivative of the Gaussian in the X direction.private float[]
GyData
Storage location of the first derivative of the Gaussian in the Y direction.private float[]
GzData
Storage location of the first derivative of the Gaussian in the Z direction.private int
iterations
Number of iterations of the diffusion.private int[]
kExtents
Dimensionality of the kernel.private int[]
klapExtents
Dimensionality for the Laplacian kernel.private float
konsnt
Controls the diffusion rate.private float[]
lapData
Storage location of the Laplacian data.private float[]
outputBuffer
Receives output of AlgorithmConvolverprivate float[]
sigmas
Standard deviations of the gaussian used to calculate the kernels.-
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 AlgorithmAnisotropicDiffusion(ModelImage srcImg, float[] sigmas, int iter, float kValue, boolean maskFlag, boolean img25D)
Creates a new AlgorithmAnisotropicDiffusion object.AlgorithmAnisotropicDiffusion(ModelImage destImg, ModelImage srcImg, float[] sigmas, int iter, float kValue, boolean maskFlag, boolean img25D)
Creates a new AlgorithmAnisotropicDiffusion object.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
algorithmPerformed(AlgorithmBase algorithm)
Called after an algorithm this listener is registered to exits (maybe successfully, maybe not).private void
calcInPlace2D(int nImages)
Calculates the diffused image and replaces the source image with the diffused image.private void
calcInPlace3D()
Calculates the diffused image and replaces the source image with the diffused image.private void
calcStoreInDest2D(int nImages)
Calculates the diffused image and stores the resultant diffused image in the destination image model.private void
calcStoreInDest3D()
Calculates the diffused image and stores the resultant diffused image in the destination image model.void
finalize()
Sets class storages arrays to null so that System.gc() can free the memory.private void
makeKernels2D()
Creates the derivative kernels used to calculate the gradient magnitude and kernel for the diffusion process.private void
makeKernels3D()
Creates the 3D derivative kernels used to calculate the gradient magnitude and kernel for the diffusion process.void
runAlgorithm()
Starts the algorithm.void
setLinkedProgressValues(int n, AlgorithmBase convolver)
Sets convolver progress values so that linked algorithm will show at least a 1% change.-
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
-
entireImage
private boolean entireImage
Flag, if true, indicates that the whole image should be processed. If false on process the image over the mask areas.
-
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.
-
iterations
private int iterations
Number of iterations of the diffusion.
-
kExtents
private int[] kExtents
Dimensionality of the kernel.
-
klapExtents
private int[] klapExtents
Dimensionality for the Laplacian kernel.
-
konsnt
private float konsnt
Controls the diffusion rate. A large value causes this algorithms to act like gaussian smoothing and therefore diffuses across edges. K = small reduces blur across edges. Typical K = 5.
-
lapData
private float[] lapData
Storage location of the Laplacian data.
-
sigmas
private float[] sigmas
Standard deviations of the gaussian used to calculate the kernels.
-
outputBuffer
private float[] outputBuffer
Receives output of AlgorithmConvolver
-
-
Constructor Detail
-
AlgorithmAnisotropicDiffusion
public AlgorithmAnisotropicDiffusion(ModelImage srcImg, float[] sigmas, int iter, float kValue, boolean maskFlag, boolean img25D)
Creates a new AlgorithmAnisotropicDiffusion object.- Parameters:
srcImg
- reference to the source imagesigmas
- sigmas used to describe the gaussian that is used in the calculation of the gradient magnitudeiter
- number of iterations (t) of the diffusion equationkValue
- K is a factor that controls the diffusion rate. A large value causes this algorithms to act like gaussian smoothing and therefore diffuses across edges. K = small reduces blur across edges. Typical K = 5;maskFlag
- Flag that indicates that the anisotropic diffusion will be performed for the whole image if equal to trueimg25D
- Flag, if true, indicates that each slice of the 3D volume should be processed independently. 2D images disregard this flag.
-
AlgorithmAnisotropicDiffusion
public AlgorithmAnisotropicDiffusion(ModelImage destImg, ModelImage srcImg, float[] sigmas, int iter, float kValue, boolean maskFlag, boolean img25D)
Creates a new AlgorithmAnisotropicDiffusion object.- Parameters:
destImg
- Reference to destination image.srcImg
- Reference to the source image.sigmas
- Sigmas used to describe the gaussian that is used in the calculation of the gradient magnitude.iter
- Number of iterations (t) of the diffusion equationkValue
- K is a factor that controls the diffusion rate. A large value causes this algorithms to act like gaussian smoothing and therefore diffuses across edges. K = small reduces blur across edges. Typical K = 5.maskFlag
- Flag that indicates that the anisotropic diffusion will be performed for the whole image if equal to true.img25D
- Flag, if true, indicates that each slice of the 3D volume should be processed independently. 2D images disregard this flag.
-
-
Method Detail
-
finalize
public void finalize()
Sets class storages arrays to null so that System.gc() can free the memory.- Overrides:
finalize
in classAlgorithmBase
-
runAlgorithm
public void runAlgorithm()
Starts the algorithm.- Specified by:
runAlgorithm
in classAlgorithmBase
-
calcInPlace2D
private void calcInPlace2D(int nImages)
Calculates the diffused image and replaces the source image with the diffused image.- Parameters:
nImages
- number of images to be blurred. If 2D image then nImage = 1, if 3D image where each image is to processed independently then nImages equals the number of images in the volume.
-
calcInPlace3D
private void calcInPlace3D()
Calculates the diffused image and replaces the source image with the diffused image.
-
calcStoreInDest2D
private void calcStoreInDest2D(int nImages)
Calculates the diffused image and stores the resultant diffused image in the destination image model.- Parameters:
nImages
- number of images to be blurred. If 2D image then nImage = 1, if 3D image where each image is to processed independently then nImages equals the number of images in the volume.
-
calcStoreInDest3D
private void calcStoreInDest3D()
Calculates the diffused image and stores the resultant diffused image in the destination image model.
-
makeKernels2D
private void makeKernels2D()
Creates the derivative kernels used to calculate the gradient magnitude and kernel for the diffusion process.
-
makeKernels3D
private void makeKernels3D()
Creates the 3D derivative kernels used to calculate the gradient magnitude and kernel for the diffusion process.
-
setLinkedProgressValues
public void setLinkedProgressValues(int n, AlgorithmBase convolver)
Sets convolver progress values so that linked algorithm will show at least a 1% change.
-
algorithmPerformed
public void algorithmPerformed(AlgorithmBase algorithm)
Description copied from interface:AlgorithmInterface
Called 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:
algorithmPerformed
in interfaceAlgorithmInterface
- Parameters:
algorithm
- the algorithm which has just completed
-
-