Ask Your Question
0

CUDA version of fastNlMeansDenoising not matching CPU version?

asked 2020-07-27 12:58:15 -0500

e1513377 gravatar image

updated 2020-07-27 16:07:29 -0500

I have the following code

#include <cmath>
#include <omp.h>
#include <opencv2/opencv.hpp>
#include <opencv2/imgcodecs.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/photo.hpp>
#include <opencv2/photo/cuda.hpp>
#include <opencv2/core/core.hpp>
#include <opencv2/cudev/ptr2d/gpumat.hpp>
#include <iostream>

using namespace std;
using namespace cv;

int main(int argc, char** argv)
{
    std::string str0 = "lenna";
    cv::Mat BW0mat = imread(str0 + ".bmp", cv::IMREAD_GRAYSCALE);

    cv::Mat NLMmat0;
    cv::fastNlMeansDenoising(BW0mat, NLMmat0, 11, 13, 33);

    cuda::GpuMat imageGPU;
    cuda::GpuMat reslutGPU;
    Mat NLMgpu;
    imageGPU.upload(BW0mat);
    cuda::fastNlMeansDenoising(imageGPU, reslutGPU, 11, 33, 13);
    reslutGPU.download(NLMgpu);

    NLMmat0.convertTo(NLMmat0, CV_64FC1, 1.0 / 255.0);
    NLMgpu.convertTo(NLMgpu, CV_64FC1, 1.0 / 255.0);

    for (int i = 0; i < NLMmat0.rows; i++) {
        for (int j = 0; j < NLMmat0.cols; j++) {
            if (NLMmat0.at<double>(i, j) != NLMgpu.at<double>(i, j))
            {
                std::cout << "i :" << i << ", j: " << j << ", cpu: " << NLMmat0.at<double>(i, j) << ", gpu: " << NLMgpu.at<double>(i, j) << "\n";
            }
        }
    }

    return 0;
}

The last loop outputs differences in the values between the CPU and GPU version of fastNlMeansDenoising. Why are these values not identical?

edit retag flag offensive close merge delete

Comments

Are you compiling with --use_fast_math enabled? How different are the results, which version of OpenCv and CUDA are you using?

cudawarped gravatar imagecudawarped ( 2020-07-28 03:13:20 -0500 )edit

I'm using VS so I don't think I compiled with --use_fast_math. I'm using CUDA 11 and OpenCV 4.4. The results are about 1-3% apart per pixel

e1513377 gravatar imagee1513377 ( 2020-07-28 11:16:01 -0500 )edit

I would expect some variance as it is very unlikely that the algorithm will have been implemented in exactly the same way on both the CPU and GPU, is it visually obvious? Is one worse than the other? I will try myself when I have some time with the OpenCV/CUDA versions you specified.

cudawarped gravatar imagecudawarped ( 2020-07-28 12:14:56 -0500 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2020-07-28 03:17:30 -0500

I have same problem of CUDA version of fastNlMeansDenoising not matching CPU version so please solve its

edit flag offensive delete link more

Comments

What was the magnitude of the difference, which OpenCV and CUDA version were you using did you compile with --use_fast_math?

cudawarped gravatar imagecudawarped ( 2020-07-28 03:49:15 -0500 )edit
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2020-07-27 12:58:15 -0500

Seen: 29 times

Last updated: Jul 27