Class OpenCLAlgorithmDeconvolution

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

    public class OpenCLAlgorithmDeconvolution
    extends OpenCLAlgorithmBase
    OpenCL Algorithm computes Deconvolution for a 3D or 4D image.
    • Field Detail

      • colorMask

        private int[] colorMask
        Color flags.
      • sigmas

        private float[] sigmas
        Standard deviations of the Gaussian used to calculate the kernels.
      • iterations

        private int iterations
        number of iterations in the deconvolution:
      • useConversion

        private boolean useConversion
        when true, the sigma values are multiplied by: 1.0 / (2*Math.sqrt(2*Math.log(2))) before the gaussian is generated.
      • derivativeX

        private org.jocl.cl_mem[] derivativeX
        derivative buffer in OpenCL for convolving along the x-axis
      • derivativeY

        private org.jocl.cl_mem[] derivativeY
        derivative buffer in OpenCL for convolving along the y-axis
      • derivativeZ

        private org.jocl.cl_mem[] derivativeZ
        derivative buffer in OpenCL for convolving along the z-axis
      • kExtents

        private int[][] kExtents
        extents for the gaussian kernels
      • kOrigins

        private int[][] kOrigins
        center positions for the gaussian kernels
      • reductionKernel

        private org.jocl.cl_kernel reductionKernel
        OpenCL reduction kernel, calculates the max of and OpenCL buffer.
      • scaleKernel

        private org.jocl.cl_kernel scaleKernel
        OpenCL scale kernel, multiplies the image by buffer1[0] / buffer2[0], where all buffers are OpenCL buffers on the GPU / CPU.
      • sumBuffer

        private org.jocl.cl_mem sumBuffer
        buffer for storing the current max of an OpenCL buffer
      • brightnessBuffer

        private org.jocl.cl_mem brightnessBuffer
        buffer for storing the original maximum of the OpenCL buffer
      • sum

        private float[] sum
      • srcImageB

        private ModelImage srcImageB
        second ModelImage for dual-deconvolution
      • sigmasB

        private float[] sigmasB
        second sigma values for dual-deconvolution
      • maxWorkSize

        private long maxWorkSize
        Maximum number of work items in a work group on OpenCL.
      • AVERAGE_DECON

        public static final int AVERAGE_DECON
        Average deconvolution is based on the arithmetical mean of the two estimates from A and B separately
        See Also:
        Constant Field Values
      • MULTIPLICATION_DECON

        public static final int MULTIPLICATION_DECON
        Multiplication deconvolution is based on the geometrical mean of the two estimates from A and B separately
        See Also:
        Constant Field Values
      • method

        private int method
    • Constructor Detail

      • OpenCLAlgorithmDeconvolution

        public OpenCLAlgorithmDeconvolution​(ModelImage srcImg,
                                            int method,
                                            float[] sigmas,
                                            boolean maskFlag,
                                            int iterations,
                                            boolean conversion)
        New Deconvolution algorithm, applies the deconvolution based on the sigma values and iterations to the input image. Overwrites the input image.
        Parameters:
        srcImg -
        method -
        sigmas -
        maskFlag -
        iterations -
        conversion -
      • OpenCLAlgorithmDeconvolution

        public OpenCLAlgorithmDeconvolution​(ModelImage destImg,
                                            ModelImage srcImg,
                                            int method,
                                            float[] sigmas,
                                            boolean maskFlag,
                                            int iterations,
                                            boolean conversion)
        New Deconvolution algorithm, applies the deconvolution based on the sigma values and iterations to the input image. Stores the output in the destImage.
        Parameters:
        destImg -
        srcImg -
        method -
        sigmas -
        maskFlag -
        iterations -
        conversion -
      • OpenCLAlgorithmDeconvolution

        public OpenCLAlgorithmDeconvolution​(ModelImage destImg,
                                            ModelImage srcImg,
                                            int method,
                                            float[] sigmas,
                                            boolean maskFlag,
                                            int iterations,
                                            boolean conversion,
                                            long deviceType)
        New Deconvolution algorithm, applies the deconvolution based on the sigma values and iterations to the input image. Stores the output in the destImage. Enables the user to specify the device type (CL.CL_DEVICE_TYPE_GPU or CL.CL_DEVICE_TYPE_CPU)
        Parameters:
        destImg -
        srcImg -
        method -
        sigmas -
        maskFlag -
        iterations -
        conversion -
        deviceType -
      • OpenCLAlgorithmDeconvolution

        public OpenCLAlgorithmDeconvolution​(ModelImage srcImgA,
                                            ModelImage srcImgB,
                                            int method,
                                            float[] sigmasA,
                                            float[] sigmasB,
                                            boolean maskFlag,
                                            int iterations,
                                            boolean conversion)
        New Dual image Deconvolution algorithm, applies the deconvolution based on the sigma values and iterations to the input image. Overwrites the input imageA as output.
        Parameters:
        srcImgA -
        srcImgB -
        method -
        sigmasA -
        sigmasB -
        maskFlag -
        iterations -
        conversion -
      • OpenCLAlgorithmDeconvolution

        public OpenCLAlgorithmDeconvolution​(ModelImage destImg,
                                            ModelImage srcImgA,
                                            ModelImage srcImgB,
                                            int method,
                                            float[] sigmasA,
                                            float[] sigmasB,
                                            boolean maskFlag,
                                            int iterations,
                                            boolean conversion)
        New Dual image Deconvolution algorithm, applies the deconvolution based on the sigma values and iterations to the input image.
        Parameters:
        destImg -
        srcImgA -
        srcImgB -
        method -
        sigmasA -
        sigmasB -
        maskFlag -
        iterations -
        conversion -
      • OpenCLAlgorithmDeconvolution

        public OpenCLAlgorithmDeconvolution​(ModelImage destImg,
                                            ModelImage srcImgA,
                                            ModelImage srcImgB,
                                            int method,
                                            float[] sigmasA,
                                            float[] sigmasB,
                                            boolean maskFlag,
                                            int iterations,
                                            boolean conversion,
                                            long deviceType)
        New Dual image Deconvolution algorithm, applies the deconvolution based on the sigma values and iterations to the input image. Stores the output in the destImage. Enables the user to specify the device type (CL.CL_DEVICE_TYPE_GPU or CL.CL_DEVICE_TYPE_CPU)
        Parameters:
        destImg -
        srcImgA -
        srcImgB -
        method -
        sigmasA -
        sigmasB -
        maskFlag -
        iterations -
        conversion -
        deviceType -
    • Method Detail

      • deconvolution4D

        private void deconvolution4D()
        Calls Deconvolution for each volume in the time series image.
      • deconvolutionSep3D_2

        private void deconvolutionSep3D_2​(int time)
        Single - Image deconvolution
        Parameters:
        time -
      • deconvolutionSep3D_2A

        private void deconvolutionSep3D_2A​(int time)
        Unused, for testing...
        Parameters:
        time -
      • deconvolutionSep3D_Dual

        private void deconvolutionSep3D_Dual​(int time)
        Dual image deconvolution.
        Parameters:
        time -
      • getKernel

        private float[] getKernel​(float sigma)
        Computes a 1D Gaussian kernel for the given sigma value.
        Parameters:
        sigma -
        Returns:
      • getMaxMemoryUsed

        private long getMaxMemoryUsed​(float[] sigmas)
        Determines the amount of memory used for the OpenCL buffers required for the gaussian kernels for the given sigmas.
        Parameters:
        sigmas -
        Returns:
      • initConvolutionBuffers

        private void initConvolutionBuffers​(int index,
                                            float[] sigmas)
        Creates the Convolution kernels (data arrays) in OpenCL. Creates 3 1D arrays in OpenCL for the x-convolution kernel the y-convolution kernel, and the z-convolution kernel.
        Parameters:
        index - (0 for single-image deconvolution, 0,1 for dual-image)
        sigmas -
      • initEstimate

        private void initEstimate​(org.jocl.cl_command_queue commandQueue,
                                  long elementCount,
                                  org.jocl.cl_mem inputBufferA,
                                  org.jocl.cl_mem inputBufferB,
                                  org.jocl.cl_mem estimateBuffer)
        Creates the first estimate image for dual-image deconvolution estimate = 0.5 * (imageBufferA + imageBufferB). This is calculated in OpenCL and the results stored in the OpenCL buffer.
        Parameters:
        commandQueue -
        elementCount -
        inputBufferA - input A OpenCL buffer
        inputBufferB - input B OpenCL buffer
        estimateBuffer - output OpenCL buffer
      • initReductionKernel

        private float initReductionKernel​(org.jocl.cl_command_queue commandQueue,
                                          long elementCount,
                                          org.jocl.cl_mem inputBuffer)
        Inializes the reduction kernel to calculate the maximum of the estimateBuffer during the dual-image deconvolution. Returns the max of the initial buffer.
        Parameters:
        commandQueue -
        elementCount -
        inputBuffer - , the estimateBuffer
        Returns:
        maximum of the inputBuffer
      • initScaleKernel

        private void initScaleKernel​(org.jocl.cl_command_queue commandQueue,
                                     long elementCount,
                                     org.jocl.cl_mem inputBuffer)
        Initialize the scale OpenCL kernel which calculates estimateBuffer *= max(estimateBuffer)
        Parameters:
        commandQueue -
        elementCount -
        inputBuffer -
      • reduce

        private void reduce​(org.jocl.cl_command_queue commandQueue)
        Calls the reduction kernel to calculate the maximum of the estimateBuffer in OpenCL.
        Parameters:
        commandQueue -
      • scale

        private void scale​(org.jocl.cl_command_queue commandQueue,
                           long elementCount)
        Calls the scale kernel which computes estimateBuffer *= max(estimateBuffer) in OpenCL should be called after a call to reduce( commandQueue )
        Parameters:
        commandQueue -
        elementCount -