Start tv_denoising implementation

This commit is contained in:
2023-06-25 14:33:26 +02:00
parent ba78f9242d
commit 4f65f39bbe

31
src/tv_denoising.cu Normal file
View File

@@ -0,0 +1,31 @@
#include <cuda.h>
#include <cuda_runtime.h>
#include <device_launch_parameters.h>
#include <opencv2/opencv.hpp>
extern "C" void TVDenoising(cv::Mat& image, float lambda, int maxIterations)
{
// Convert the image to float precision
cv::Mat floatImage;
image.convertTo(floatImage, CV_32F);
// Get image dimensions
int width = image.cols;
int height = image.rows;
// Calculate the number of blocks and threads per block
dim3 blockSize(16, 16);
dim3 gridSize((width + blockSize.x - 1) / blockSize.x, (height + blockSize.y - 1) / blockSize.y);
// Allocate GPU memory for the image
float* d_image;
cudaMalloc(&d_image, width * height * sizeof(float));
// Copy the image data from host to device
cudaMemcpy(d_image, floatImage.ptr<float>(0), width * height * sizeof(float), cudaMemcpyHostToDevice);
// Free the GPU memory
cudaFree(d_image);
}