Class AlgorithmSeparableConvolver

  • All Implemented Interfaces:
    java.awt.event.ActionListener, java.awt.event.WindowListener, java.lang.Runnable, java.util.EventListener

    public class AlgorithmSeparableConvolver
    extends AlgorithmBase
    Convolves an image with a separable (symmetric) kernel and returns the result. The Gaussian and its derivatives are separable.

    Faster than the regualar convolver -- reg 2D: n^d*m^d, sep 2D: d*n^d*m ; d = img dimension, n = img size, m = kern size -- but requires more memory -- ~2 times more for 2D, ~3 times for 3D (plus significant extra memory required for algorithms which use this class (2 or 3 times more, depending on the dimension)).

    Also note that this convolver has a different interface which must be used than the static point convolution functions which most algorithms use from the AlgorithmConvolver.

    Color and voi mask code not tested (although the voi code is pretty straight-forward).

    Author:
    Evan McCreedy
    See Also:
    AlgorithmConvolver
    • Field Detail

      • cFactor

        private int cFactor
        Buffer size adjustment for color images.
      • colorImage

        private boolean colorImage
        Flag to indicate if the source image is color.
      • curPercent

        int curPercent
      • incIndex

        int incIndex
      • outputBuffer

        private double[] outputBuffer
        Holds the result image data.
      • entireImage

        private boolean entireImage
        Whether to convolve the whole image or just pixels inside a mask.
      • inputBuffer

        private double[] inputBuffer
        Holds the original image data.
      • inputMask

        private boolean[] inputMask
        Holds the original image mask data.
      • imgExtents

        private int[] imgExtents
        The dimensions of the both source and destination images.
      • kernelExtents

        private int[] kernelExtents
        The dimensions of the kernel.
      • kernelBuffer

        private float[][] kernelBuffer
      • red

        private boolean red
        Flags to indicate which color channels to process.
      • green

        private boolean green
        Flags to indicate which color channels to process.
      • blue

        private boolean blue
        Flags to indicate which color channels to process.
    • Constructor Detail

      • AlgorithmSeparableConvolver

        public AlgorithmSeparableConvolver​(float[] srcBuffer,
                                           int[] iExtents,
                                           float[][] kernBuffer,
                                           boolean colorImage)
        Sets destination, source, and kernel buffers. Call run() to convolve image.
        Parameters:
        srcBuffer - source image data buffer
        iExtents - source and destination image dimensions
        kernBuffer - kernel image data buffer (kernel must be symmetric)
        kExtents - kernel dimensions
        color - whether the image is color
        minProgressValue - the minimum progress value.
        maxProgressValue - the maximum progress value.
      • AlgorithmSeparableConvolver

        public AlgorithmSeparableConvolver​(float[] srcBuffer,
                                           int[] iExtents,
                                           float[] kernBuffers,
                                           int[] kExtents,
                                           boolean colorImage)
    • Method Detail

      • finalize

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

        private void convolve​(double[] imageBuffer,
                              float[] kernelBuffer,
                              double[] resultBuffer)
        Perform one-dimension convolution.
        Parameters:
        imageBuffer -
        kernelBuffer -
        resultBuffer -
      • convolveNoColor

        private void convolveNoColor​(double[] imageBuffer,
                                     float[] kernelBuffer,
                                     double[] resultBuffer,
                                     boolean[] maskBuffer)
        Perform one-dimension convolution.
        Parameters:
        imageBuffer -
        kernelBuffer -
        resultBuffer -
      • performMT

        public void performMT()
      • perform

        public void perform()
        Begins the excution of the 3D convolver.
      • convolveX

        private void convolveX​(int from,
                               int to)
      • convolveY

        private void convolveY​(int from,
                               int to)
      • convolveZ

        private void convolveZ​(int from,
                               int to)
      • beforeExecute

        public void beforeExecute()
      • execute

        public void execute()
      • afterExecute

        public void afterExecute()
      • runAlgorithm

        public void runAlgorithm()
        Starts the convolution of the source image with the provided kernel.
        Specified by:
        runAlgorithm in class AlgorithmBase
      • setColorChannels

        public void setColorChannels​(boolean _red,
                                     boolean _green,
                                     boolean _blue)
        Sets what color channels to convolve and tells the convolver that it is working on a color image.
        Parameters:
        _red - process the red channel
        _green - process the green channel
        _blue - process the blue channel
      • setMask

        public void setMask​(java.util.BitSet newMask)
        Sets the mask to convolve within.
        Overrides:
        setMask in class AlgorithmBase
        Parameters:
        newMask - mask to convolve within
      • getOutputBuffer

        public float[] getOutputBuffer()