Class 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 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 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 equation
        kValue - 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.
      • 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 equation
        kValue - 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 class AlgorithmBase
      • 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 interface AlgorithmInterface
        Parameters:
        algorithm - the algorithm which has just completed