Class OpenCLAlgorithmDeconvolution
- java.lang.Object
-
- java.lang.Thread
-
- gov.nih.mipav.model.algorithms.AlgorithmBase
-
- gov.nih.mipav.model.algorithms.OpenCLAlgorithmBase
-
- gov.nih.mipav.model.algorithms.filters.OpenCL.filters.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 Summary
Fields Modifier and Type Field Description static int
AVERAGE_DECON
Average deconvolution is based on the arithmetical mean of the two estimates from A and B separatelyprivate org.jocl.cl_mem
brightnessBuffer
buffer for storing the original maximum of the OpenCL bufferprivate int[]
colorMask
Color flags.private org.jocl.cl_mem[]
derivativeX
derivative buffer in OpenCL for convolving along the x-axisprivate org.jocl.cl_mem[]
derivativeY
derivative buffer in OpenCL for convolving along the y-axisprivate org.jocl.cl_mem[]
derivativeZ
derivative buffer in OpenCL for convolving along the z-axisprivate int
iterations
number of iterations in the deconvolution:static int
JOINT_DECON
Default caseprivate int[][]
kExtents
extents for the gaussian kernelsprivate int[][]
kOrigins
center positions for the gaussian kernelsprivate long
maxWorkSize
Maximum number of work items in a work group on OpenCL.private int
method
static int
MULTIPLICATION_DECON
Multiplication deconvolution is based on the geometrical mean of the two estimates from A and B separatelyprivate org.jocl.cl_kernel
reductionKernel
OpenCL reduction kernel, calculates the max of and OpenCL buffer.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.private float[]
sigmas
Standard deviations of the Gaussian used to calculate the kernels.private float[]
sigmasB
second sigma values for dual-deconvolutionprivate ModelImage
srcImageB
second ModelImage for dual-deconvolutionprivate float[]
sum
private org.jocl.cl_mem
sumBuffer
buffer for storing the current max of an OpenCL bufferprivate boolean
useConversion
when true, the sigma values are multiplied by: 1.0 / (2*Math.sqrt(2*Math.log(2))) before the gaussian is generated.-
Fields inherited from class gov.nih.mipav.model.algorithms.OpenCLAlgorithmBase
cl, color, contextLibrary, depth, device, entireImage, height, m_iDeviceType, m_kGL, openCLTypeLibrary, time, width
-
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 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.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.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.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.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.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.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private void
deconvolution4D()
Calls Deconvolution for each volume in the time series image.private void
deconvolutionSep3D_2(int time)
Single - Image deconvolutionprivate void
deconvolutionSep3D_2A(int time)
Unused, for testing...private void
deconvolutionSep3D_Dual(int time)
Dual image deconvolution.void
finalize()
Prepares this class for destruction.private float[]
getKernel(float sigma)
Computes a 1D Gaussian kernel for the given sigma value.private long
getMaxMemoryUsed(float[] sigmas)
Determines the amount of memory used for the OpenCL buffers required for the gaussian kernels for the given sigmas.private void
initConvolutionBuffers(int index, float[] sigmas)
Creates the Convolution kernels (data arrays) in OpenCL.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).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.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)private void
reduce(org.jocl.cl_command_queue commandQueue)
Calls the reduction kernel to calculate the maximum of the estimateBuffer in OpenCL.void
runAlgorithm()
Starts the program.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 )-
Methods inherited from class gov.nih.mipav.model.algorithms.OpenCLAlgorithmBase
checkError, getInt, getInts, getLong, getLongs, getMaxMemoryUsed, getString, getString, initCL, isOCLAvailable, readKernelFile, roundUp, saveImage, saveImage, setBlue, setGreen, setRed, setTime
-
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
-
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.
-
JOINT_DECON
public static final int JOINT_DECON
Default case- See Also:
- Constant Field Values
-
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
-
finalize
public void finalize()
Prepares this class for destruction.- Overrides:
finalize
in classOpenCLAlgorithmBase
-
runAlgorithm
public void runAlgorithm()
Starts the program.- Specified by:
runAlgorithm
in classAlgorithmBase
-
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 bufferinputBufferB
- input B OpenCL bufferestimateBuffer
- 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
-
-
-