TV Image Denoising CUDA
Algorithm
The TV (Total Variation) denoising algorithm is a popular technique used for reducing noise in images while preserving important details and edges. The algorithm operates on the principle that the noise in an image can be considered as high-frequency components, while the important features are typically low-frequency components. By minimizing the Total Variation of the image, which represents the sum of the absolute differences between adjacent pixels, the algorithm effectively reduces the high-frequency noise while preserving the low-frequency features.
Implementation Details
The TV Image Denoising CUDA program is implemented using C++ and CUDA. It makes use of the OpenCV library for image manipulation and CUDA runtime API for GPU acceleration.
The program consists of two main parts: the CUDA kernel function tvDenoisingKernel and the host function TVDenoising. Here's a brief explanation of each component:
tvDenoisingKernel
The tvDenoisingKernel is the CUDA kernel function responsible for performing the TV denoising operation on the image. It operates on a 2D grid of threads, where each thread handles a pixel in the image. The kernel performs the following steps for each pixel:
- Calculates the gradients using central differences for both the x and y directions.
- Synchronizes threads to ensure all gradient calculations are complete.
- Applies the TV denoising update rule to update the pixel value.
- Updates the global image array with the updated pixel values.
- Synchronizes threads to ensure all image updates are complete.
- Repeats the above steps for a specified number of iterations.
TVDenoising
The TVDenoising function is the host function responsible for coordinating the overall denoising process. It performs the following steps:
- Converts the input image to float precision.
- Retrieves the dimensions of the image.
- Calculates the number of blocks and threads per block for GPU parallel execution.
- Allocates GPU memory for the image.
- Copies the image data from the host to the device.
- Invokes the tvDenoisingKernel on the GPU.
- Copies the denoised image data back from the device to the host.
- Converts the denoised image back to the original data type.
- Frees the GPU memory.
Parameters
The TVDenoising function accepts the following parameters:
- image: A reference to the input image (cv::Mat) to be denoised.
- lambda: The regularization parameter for TV denoising. Higher values preserve more edges but may remove finer details (default: 0.02).
- maxIterations: The number of iterations for TV denoising. More iterations result in better denoising at the cost of increased computation time (default: 10).