Class AlgorithmConvolver

java.lang.Object
java.lang.Thread
gov.nih.mipav.model.algorithms.AlgorithmBase
gov.nih.mipav.model.algorithms.AlgorithmConvolver
All Implemented Interfaces:
ActionListener, WindowListener, Runnable, EventListener

public class AlgorithmConvolver extends AlgorithmBase
Convolves kernel with a 2D or 3D image - only pixels where the kernel is completely contained in the image are convolved, otherwise they are set to zero. This is reasonable since data at the edges of images is rarely used and large kernels should not be used since it is much faster to perform FFT, filter, and IFFT. The break even point is probably around a kernel size of 11 or so.

Since this class extends the AlgorithmBase class that extends the Thread class it can be run in its own thread by invoking algoConvolver3DObj.start(); It can also be invoked without a new thread by calling the the run() method directly (ie. algoConvolver3DObj.run()).

  1. Source image is exported (locked and unlocked by export)
  2. Kernel is exported
  3. Image is convolved with kernel
  4. Return
Version:
0.1 Aug 1, 1997
Author:
Matthew J. McAuliffe, Ph.D.
  • Field Details

    • kExtents

      private int[] kExtents
      The image data to convolve.
    • kernelBuffer

      private float[] kernelBuffer
    • kernelBufferX

      private float[] kernelBufferX
    • kernelBufferY

      private float[] kernelBufferY
    • kernelBufferZ

      private float[] kernelBufferZ
    • kernelBufferX2

      private float[] kernelBufferX2
    • kernelBufferY2

      private float[] kernelBufferY2
    • kernelBufferXX

      private float[] kernelBufferXX
    • kernelBufferXY

      private float[] kernelBufferXY
    • kernelBufferYY

      private float[] kernelBufferYY
    • kernelBufferXZ

      private float[] kernelBufferXZ
    • kernelBufferYZ

      private float[] kernelBufferYZ
    • kernelBufferZZ

      private float[] kernelBufferZZ
    • kernelBufferXXX

      private float[] kernelBufferXXX
    • kernelBufferXXY

      private float[] kernelBufferXXY
    • kernelBufferXYY

      private float[] kernelBufferXYY
    • kernelBufferYYY

      private float[] kernelBufferYYY
    • kernelBufferXXZ

      private float[] kernelBufferXXZ
    • kernelBufferXZZ

      private float[] kernelBufferXZZ
    • kernelBufferXYZ

      private float[] kernelBufferXYZ
    • kernelBufferYYZ

      private float[] kernelBufferYYZ
    • kernelBufferYZZ

      private float[] kernelBufferYZZ
    • kernelBufferZZZ

      private float[] kernelBufferZZZ
    • red

      private boolean red
    • blue

      private boolean blue
    • green

      private boolean green
    • outputBuffer

      private float[] outputBuffer
    • entireImage

      private boolean entireImage
    • doXY

      private boolean doXY
    • sqrtXY

      private boolean sqrtXY
    • sqrtXYZ

      private boolean sqrtXYZ
    • nms2

      private boolean nms2
    • nms2e

      private boolean nms2e
    • nms3

      private boolean nms3
    • nms3e

      private boolean nms3e
    • combined2D3D

      private boolean combined2D3D
    • intensityGaussianDenom

      private double intensityGaussianDenom
    • bilateral

      private boolean bilateral
  • Constructor Details

    • AlgorithmConvolver

      public AlgorithmConvolver(ModelImage srcImage, float[] kernel, int[] kExtents, boolean entireImage, boolean image25D)
      Sets the source and kernel images and calls the appropriate method based on image dimensionality.
      Parameters:
      srcImage -
      kernel -
      kExtents -
      entireImage -
      image25D -
    • AlgorithmConvolver

      public AlgorithmConvolver(ModelImage srcImage, float[] kernel, int[] kExtents, boolean entireImage, boolean image25D, double intensityGaussianDenom)
    • AlgorithmConvolver

      public AlgorithmConvolver(ModelImage srcImage, float[] kernelX, float[] kernelY, int[] kExtents, boolean entireImage, boolean sqrtXY)
    • AlgorithmConvolver

      public AlgorithmConvolver(ModelImage srcImage, float[] kernelX, float[] kernelY, float[] kernelZ, int[] kExtents, boolean entireImage)
    • AlgorithmConvolver

      public AlgorithmConvolver(ModelImage srcImage, float[] kernelX, float[] kernelY, float[] kernelXX, float[] kernelXY, float[] kernelYY, int[] kExtents, boolean entireImage)
    • AlgorithmConvolver

      public AlgorithmConvolver(ModelImage srcImage, float[] kernelX, float[] kernelY, float[] kernelXX, float[] kernelXY, float[] kernelYY, float[] kernelXXX, float[] kernelXXY, float[] kernelXYY, float[] kernelYYY, int[] kExtents, boolean entireImage)
    • AlgorithmConvolver

      public AlgorithmConvolver(ModelImage srcImage, float[] kernelX, float[] kernelY, float[] kernelZ, float[] kernelXX, float[] kernelXY, float[] kernelYY, float[] kernelXZ, float[] kernelYZ, float[] kernelZZ, boolean entireImage, int[] kExtents)
    • AlgorithmConvolver

      public AlgorithmConvolver(ModelImage srcImage, float[] kernelX, float[] kernelY, float[] kernelZ, float[] kernelXX, float[] kernelXY, float[] kernelYY, float[] kernelXZ, float[] kernelYZ, float[] kernelZZ, float[] kernelXXX, float[] kernelXXY, float[] kernelXYY, float[] kernelYYY, float[] kernelXXZ, float[] kernelXZZ, float[] kernelXYZ, float[] kernelYYZ, float[] kernelYZZ, float[] kernelZZZ, int[] kExtents, boolean entireImage)
    • AlgorithmConvolver

      public AlgorithmConvolver(ModelImage srcImage, float[] kernelX, float[] kernelY, float[] kernelZ, float[] kernelX2, float[] kernelY2, int[] kExtents, boolean entireImage, boolean combined2D3D)
  • Method Details

    • isRed

      public boolean isRed()
    • setRed

      public void setRed(boolean red)
    • isBlue

      public boolean isBlue()
    • setBlue

      public void setBlue(boolean blue)
    • isGreen

      public boolean isGreen()
    • setGreen

      public void setGreen(boolean green)
    • setColorChannels

      public void setColorChannels(boolean red, boolean green, boolean blue)
    • convolve2DPt

      public static final float convolve2DPt(int pix, int[] iExtents, float[] image, int[] kExtents, float[] kernel)
      A static function that convolves a kernel with an image at a position.
      Parameters:
      pix - index indicating location of convolution
      iExtents - image dimensions
      image - image data
      kExtents - kernel dimensions
      kernel - kernel data
      Returns:
      the value of the pixel after convolution with the kernel
    • convolveBilateral2DPt

      public static final float convolveBilateral2DPt(int pix, int[] iExtents, float[] image, int[] kExtents, float[] kernel, double intensityGaussianDenom)
      A static function that convolves a kernel with an image at a position. The intensity difference between the center pixel and the indexed pixel is used in a Gaussian in the weighing. The intensity Gaussian is (1.0/(Math.sqrt(2.0 * Math.PI) * intensitySigma))* exp(-intensityDifference**2/intenDenom) Since the same (1.0/(Math.sqrt(2.0 * Math.PI) * intensitySigma) term would appear in every weight term, it would cancel out by appearing in both the numerator and denominator in (sum / norm) and so can be omitted.
      Parameters:
      pix - index indicating location of convolution
      iExtents - image dimensions
      image - image data
      kExtents - kernel dimensions
      kernel - kernel data
      intensityGaussianDenom -
      Returns:
      the value of the pixel after convolution with the kernel
    • convolve2DPtSqrtXY

      public static final float convolve2DPtSqrtXY(int pix, int[] iExtents, float[] image, int[] kExtents, float[] kernelX, float[] kernelY)
      A static function that convolves a kernel with an image at a position.
      Parameters:
      pix - index indicating location of convolution
      iExtents - image dimensions
      image - image data
      kExtents - kernel dimensions
      kernelX - kernel data
      kernelY - kernel data
      Returns:
      the value of the pixel after convolution with the kernel
    • convolve2DPtNMS

      public static final float convolve2DPtNMS(int pix, int[] iExtents, float[] image, int[] kExtents, float[] kernelX, float[] kernelY, float[] kernelXX, float[] kernelXY, float[] kernelYY)
      A static function that convolves a kernel with an image at a position.
      Parameters:
      pix - index indicating location of convolution
      iExtents - image dimensions
      image - image data
      kExtents - kernel dimensions
      kernelX - kernel data
      kernelY - kernel data
      kernelXX - kernel data
      kernelXY - kernel data
      kernelYY - kernel data
      Returns:
      the value of the pixel after convolution with the kernel
    • convolve2DPtNMSE

      public static final float convolve2DPtNMSE(int pix, int[] iExtents, float[] image, int[] kExtents, float[] kernelX, float[] kernelY, float[] kernelXXX, float[] kernelXXY, float[] kernelXYY, float[] kernelYYY)
      A static function that convolves a kernel with an image at a position.
      Parameters:
      pix - index indicating location of convolution
      iExtents - image dimensions
      image - image data
      kExtents - kernel dimensions
      kernelX - kernel data
      kernelY - kernel data
      kernelXXX - kernel data
      kernelXXY - kernel data
      kernelXYY - kernel data
      kernelYYY - kernel data
      Returns:
      the value of the pixel after convolution with the kernel
    • convolve2DPt

      public static final float convolve2DPt(WildMagic.LibFoundation.Mathematics.Vector2f pt, int[] iExtents, float[] image, int[] kExtents, float[] kernel)
      A static function that convolves a kernel with an image at a position.
      Parameters:
      pt - floating point indicating location of convolution
      iExtents - image dimensions
      image - image data
      kExtents - kernel dimensions
      kernel - kernel data
      Returns:
      the value of the pixel after convolution with the kernel
    • convolve2DPt

      public static final double convolve2DPt(WildMagic.LibFoundation.Mathematics.Vector2d pt, int[] iExtents, double[] image, int[] kExtents, double[] kernel)
      A static function that convolves a kernel with an image at a position.
      Parameters:
      pt - floating point indicating location of convolution
      iExtents - image dimensions
      image - image data
      kExtents - kernel dimensions
      kernel - kernel data
      Returns:
      the value of the pixel after convolution with the kernel
    • convolve2DPtMed

      public static final float convolve2DPtMed(int pix, int[] iExtents, float[] image, int[] kExtents, float[] kernel)
      A static function that convolves a kernel with an image at a position. This version seems to just be used by AlgorithmLapMedianess.
      Parameters:
      pix - index indicating location of convolution
      iExtents - image dimensions
      image - image data
      kExtents - kernel dimensions
      kernel - kernel data
      Returns:
      the value of the pixel after convolution with the kernel
      See Also:
    • convolve2DRGBPt

      public static final float convolve2DRGBPt(int pix, int[] iExtents, float[] image, int[] kExtents, float[] kernel)
      A static function that convolves a kernel with an RGB image at a position.
      Parameters:
      pix - index indicating location of convolution
      iExtents - image dimensions
      image - image data
      kExtents - kernel dimensions
      kernel - kernel data
      Returns:
      the value of the pixel after convolution with the kernel
    • convolveBilateral2DCIELabPt

      public static final float[] convolveBilateral2DCIELabPt(int pix, int[] iExtents, float[] image, int[] kExtents, float[] kernel, double intensityGaussianDenom)
      A static function that convolves a kernel with an CIELab image at a position. The CIE76 intensity difference between the center pixel and the indexed pixel is used in a Gaussian in the weighing. The intensity Gaussian is (1.0/(Math.sqrt(2.0 * Math.PI) * intensitySigma))* exp(-intensityDifference**2/intenDenom) Since the same (1.0/(Math.sqrt(2.0 * Math.PI) * intensitySigma) term would appear in every weight term, it would cancel out by appearing in both the numerator and denominator in (sum / norm) and so can be omitted.
      Parameters:
      pix - index indicating location of convolution
      iExtents - image dimensions
      image - image data
      kExtents - kernel dimensions
      kernel - kernel data
      intensityGaussianDenom -
      Returns:
      the L*,a*,b* of the pixel after convolution with the kernel
    • convolve2DRGBPtSqrtXY

      public static final float convolve2DRGBPtSqrtXY(int pix, int[] iExtents, float[] image, int[] kExtents, float[] kernelX, float[] kernelY)
      A static function that convolves a kernel with an RGB image at a position.
      Parameters:
      pix - index indicating location of convolution
      iExtents - image dimensions
      image - image data
      kExtents - kernel dimensions
      kernelX - kernel data
      kernelY - kernel data
      Returns:
      the value of the pixel after convolution with the kernel
    • convolve3DPt

      public static final float convolve3DPt(int pix, int[] iExtents, float[] image, int[] kExtents, float[] kernel)
      A static function that convolves a kernel with an image at a position.
      Parameters:
      pix - index indicating location of convolution
      iExtents - image dimensions
      image - image data
      kExtents - kernel dimensions
      kernel - kernel data
      Returns:
      the value of the pixel after convolution with the kernel
    • convolveBilateral3DPt

      public static final float convolveBilateral3DPt(int pix, int[] iExtents, float[] image, int[] kExtents, float[] kernel, double intensityGaussianDenom)
      A static function that convolves a kernel with an image at a position. The intensity difference between the center pixel and the indexed pixel is used in a Gaussian in the weighing. The intensity Gaussian is (1.0/(Math.sqrt(2.0 * Math.PI) * intensitySigma))* exp(-intensityDifference**2/intenDenom) Since the same (1.0/(Math.sqrt(2.0 * Math.PI) * intensitySigma) term would appear in every weight term, it would cancel out by appearing in both the numerator and denominator in (sum / norm) and so can be omitted.
      Parameters:
      pix - index indicating location of convolution
      iExtents - image dimensions
      image - image data
      kExtents - kernel dimensions
      kernel - kernel data
      intensityGaussianDenom -
      Returns:
      the value of the pixel after convolution with the kernel
    • convolve3DPtXYZ

      public static final float convolve3DPtXYZ(int pix, int[] iExtents, float[] image, int[] kExtents, float[] kernelX, float[] kernelY, float[] kernelZ)
      A static function that convolves a kernel with an image at a position.
      Parameters:
      pix - index indicating location of convolution
      iExtents - image dimensions
      image - image data
      kExtents - kernel dimensions
      kernelX - kernel data
      kernelY - kernel data
      kernelZ - kernel data
      Returns:
      the value of the pixel after convolution with the kernel
    • convolve3DPtNMS

      public static final float convolve3DPtNMS(int pix, int[] iExtents, float[] image, int[] kExtents, float[] kernelX, float[] kernelY, float[] kernelZ, float[] kernelXX, float[] kernelXY, float[] kernelYY, float[] kernelXZ, float[] kernelYZ, float[] kernelZZ)
      A static function that convolves a kernel with an image at a position.
      Parameters:
      pix - index indicating location of convolution
      iExtents - image dimensions
      image - image data
      kExtents - kernel dimensions
      kernelX - kernel data
      kernelY - kernel data
      kernelZ - kernel data
      kernelXX - kernel data
      kernelXY - kernel data
      kernelYY - kernel data
      kernelXZ - kernel data
      kernelYZ - kernel data
      kernelZZ - kernel data
      Returns:
      the value of the pixel after convolution with the kernel
    • convolve3DPtNMSE

      public static final float convolve3DPtNMSE(int pix, int[] iExtents, float[] image, int[] kExtents, float[] kernelX, float[] kernelY, float[] kernelZ, float[] kernelXXX, float[] kernelXXY, float[] kernelXYY, float[] kernelYYY, float[] kernelXXZ, float[] kernelXZZ, float[] kernelXYZ, float[] kernelYYZ, float[] kernelYZZ, float[] kernelZZZ)
      A static function that convolves a kernel with an image at a position.
      Parameters:
      pix - index indicating location of convolution
      iExtents - image dimensions
      image - image data
      kExtents - kernel dimensions
      kernelX - kernel data
      kernelY - kernel data
      kernelZ - kernel data
      kernelXXX - kernel data
      kernelXXY - kernel data
      kernelXYY - kernel data
      kernelYYY - kernel data
      kernelXXZ - kernel data
      kernelXZZ - kernel data
      kernelXYZ - kernel data
      kernelYZZ - kernel data
      kernelZZZ - kernel data
      Returns:
      the value of the pixel after convolution with the kernel
    • convolveBlock3D

      public static final void convolveBlock3D(int start, int end, int lpv, float[] iImage, int[] iExtents, int[] kExtents, float[] kernel, ModelImage oImage)
      Parameters:
      start -
      end -
      iImage -
      iExtents -
      kExtents -
      kernel -
      oImage -
      lpp - length per voxel, for example 4 for RGB image.
    • convolve3DPt

      public static final float convolve3DPt(float[] pt, int[] iExtents, float[] image, int[] kExtents, float[] kernel)
      A static function that convolves a kernel with an image at a position.
      Parameters:
      pt - floating point indicating location of convolution
      iExtents - image dimensions
      image - image data
      kExtents - kernel dimensions
      kernel - kernel data
      Returns:
      the value of the pixel after convolution with the kernel
    • convolve3DPtMed

      public static final float convolve3DPtMed(int pix, int[] iExtents, float[] image, int[] kExtents, float[] kernel)
      A static function that convolves a kernel with an image at a position. This version seems to just be used by AlgorithmLapMedianess.
      Parameters:
      pix - index indicating location of convolution
      iExtents - image dimensions
      image - image data
      kExtents - kernel dimensions
      kernel - kernel data
      Returns:
      the value of the pixel after convolution with the kernel
      See Also:
    • convolve3DRGBPt

      public static final float convolve3DRGBPt(int pix, int[] iExtents, float[] image, int[] kExtents, float[] kernel)
      A static function that convolves a kernel with an RGB image at a position.
      Parameters:
      pix - index indicating location of convolution
      iExtents - image dimensions
      image - image data
      kExtents - kernel dimensions
      kernel - kernel data
      Returns:
      the value of the pixel after convolution with the kernel
    • convolveBilateral3DCIELabPt

      public static final float[] convolveBilateral3DCIELabPt(int pix, int[] iExtents, float[] image, int[] kExtents, float[] kernel, double intensityGaussianDenom)
      A static function that convolves a kernel with a CIELab image at a position. The CIE76 intensity difference between the center pixel and the indexed pixel is used in a Gaussian in the weighing. The intensity Gaussian is (1.0/(Math.sqrt(2.0 * Math.PI) * intensitySigma))* exp(-intensityDifference**2/intenDenom) Since the same (1.0/(Math.sqrt(2.0 * Math.PI) * intensitySigma) term would appear in every weight term, it would cancel out by appearing in both the numerator and denominator in (sum / norm) and so can be omitted.
      Parameters:
      pix - index indicating location of convolution
      iExtents - image dimensions
      image - image data
      kExtents - kernel dimensions
      kernel - kernel data
      intensityGaussianDenom -
      Returns:
      the L*,a*,b* of the pixel after convolution with the kernel
    • convolve3DRGBPtXYZ

      public static final float convolve3DRGBPtXYZ(int pix, int[] iExtents, float[] image, int[] kExtents, float[] kernelX, float[] kernelY, float[] kernelZ)
      A static function that convolves a kernel with an RGB image at a position.
      Parameters:
      pix - index indicating location of convolution
      iExtents - image dimensions
      image - image data
      kExtents - kernel dimensions
      kernelX - kernel data
      kernelY - kernel data
      kernelZ - kernel data
      Returns:
      the value of the pixel after convolution with the kernel
    • convolveWhole2DPt

      public static final float convolveWhole2DPt(int pix, int[] iExtents, float[] image, int[] kExtents, float[] kernel)
      A static function that convolves a kernel with an image at a position. The convolution is performed only if the whole kernel fits inside the image.
      Parameters:
      pix - index indicating location of convolution
      iExtents - image dimensions
      image - image data
      kExtents - kernel dimensions
      kernel - kernel data
      Returns:
      the value of the pixel after convolution with the kernel or 0 if the kernel does not fit wholly within the image
    • convolveWhole3DPt

      public static final float convolveWhole3DPt(int pix, int[] iExtents, float[] image, int[] kExtents, float[] kernel)
      A static function that convolves a kernel with an image at a position The convolution is performed only if the whole kernel fits inside the image.
      Parameters:
      pix - index indicating location of convolution
      iExtents - image dimensions
      image - image data
      kExtents - kernel dimensions
      kernel - kernel data
      Returns:
      the value of the pixel after convolution with the kernel or 0 if the kernel does not fit wholly within the image
    • convolve3DPt

      public static final float convolve3DPt(WildMagic.LibFoundation.Mathematics.Vector3f kPt, ModelImage kImage, int[] kExtents, float[] kernel)
      A static function that convolves a kernel with an image at a position.
      Parameters:
      kExtents - kernel dimensions
      kernel - kernel data
      Returns:
      the value of the pixel after convolution with the kernel
    • convolve2D

      private final void convolve2D(int startSlice, int endSlice)
    • convolve2DBilateral

      private final void convolve2DBilateral(int startSlice, int endSlice)
    • convolve2DXY

      private final void convolve2DXY(int startSlice, int endSlice)
    • convolve2DSqrtXY

      private final void convolve2DSqrtXY(int startSlice, int endSlice)
    • convolve2DNMS

      private final void convolve2DNMS(int startSlice, int endSlice)
    • convolve2DNMSE

      private final void convolve2DNMSE(int startSlice, int endSlice)
    • convolve3D

      private final void convolve3D(int start, int end, float[] iImage, int index)
    • convolve3DBilateral

      private final void convolve3DBilateral(int start, int end, float[] iImage, int index)
    • convolve2D3D

      private final void convolve2D3D(int start, int end, float[] iImage, int index, int min3DLength, int max3DLength)
    • convolve3DXYZ

      private final void convolve3DXYZ(int start, int end, float[] iImage, int index)
    • convolve3DNMS

      private final void convolve3DNMS(int start, int end, float[] iImage, int index)
    • convolve3DNMSE

      private final void convolve3DNMSE(int start, int end, float[] iImage, int index)
    • finalize

      public void finalize()
      Prepares this class for destruction.
      Overrides:
      finalize in class AlgorithmBase
    • run2D

      public void run2D()
      Begins the execution of the 2D convolver.
    • run3D

      public void run3D()
      Begins the execution of the 3D convolver.
    • run4D

      public void run4D()
    • runAlgorithm

      public void runAlgorithm()
      Begins execution of the convolver.
      Specified by:
      runAlgorithm in class AlgorithmBase
    • getBilinear

      private static float getBilinear(int i, float dx, float dy, int[] iExtents, float[] image)
      Performs bilinear interpolation of image data.
      Parameters:
      i - index into image
      dx - change in x from integer
      dy - change in y from integer
      iExtents - dimensions of image
      image - image data
      Returns:
      the bilinearly interpolated value
    • getBilinear

      private static double getBilinear(int i, double dx, double dy, int[] iExtents, double[] image)
      Performs bilinear interpolation of image data.
      Parameters:
      i - index into image
      dx - change in x from integer
      dy - change in y from integer
      iExtents - dimensions of image
      image - image data
      Returns:
      the bilinearly interpolated value
    • getTrilinear

      private static float getTrilinear(int i1, float dx, float dy, float dz, int[] iExtents, float[] image)
      Performs trilinear interpolation of image data.
      Parameters:
      i1 - index into image
      dx - change in x from integer
      dy - change in y from integer
      dz - change in z from integer
      iExtents - dimensions of image
      image - image data
      Returns:
      the trilinearly interpolated data value
    • getTrilinearC

      public static byte[] getTrilinearC(int i1, float dx, float dy, float dz, int[] iExtents, byte[] image)
      Performs trilinear interpolation of image data.
      Parameters:
      i1 - index into image
      dx - change in x from integer
      dy - change in y from integer
      dz - change in z from integer
      iExtents - dimensions of image
      image - image data
      Returns:
      the trilinearly interpolated data value
    • getOutputBuffer

      public float[] getOutputBuffer()
      Returns the output buffer
      Returns:
      buffer that contains the data after convolution