The algorithm's output is somehow not getting better. Is it because of the wrong parameters or there is some issue with the filter itself. Its like the gray(input) image and the filtered image are almost same.
```#include
using namespace cv;
int main(int argc, char** argv)
{
Mat img, gray, gray1,gray2;
img = imread("/home/odroid/Pictures/images.jpeg");
cvtColor(img, gray, COLOR_BGR2GRAY);
float h = 1;
int templateWindowSize = 4;
int searchWindowSize = 16;
int blockMatchingStep1 = 2500;
int blockMatchingStep2 = 400;
int groupSize = 8;
int slidingStep = 1;
float beta = 2.0f;
int normType = cv::NORM_L2;
int step = cv::xphoto::BM3D_STEPALL;
int transformType = cv::xphoto::HAAR ;
//cv::Mat noise(gray.size(),gray.type());
//float m = (10,12,34);
//float sigma = (1,5,50);
// cv::randn(noise, m, sigma); //mean and variance
// gray += noise;
gray1 = Mat::zeros(img.size(), CV_8U);
imshow("src ", img);
cv::xphoto::bm3dDenoising (gray, gray1, gray2, h, templateWindowSize, searchWindowSize, blockMatchingStep1, blockMatchingStep2, groupSize, slidingStep, beta, normType, step, transformType);
imshow("gray", gray);
imshow("step1", gray1);
imshow("step2", gray2);
waitKey();
return 0;
}```
image
IMHO, noise is very large.
Take a look on used test data for this algorithm: https://github.com/opencv/opencv_extra/tree/3.4.2/testdata/cv/xphoto/bm3d_image_denoising
almost same
Are they the same or not?
How is is checked? What says absdiff()?
@alalek There is this post too : http://answers.opencv.org/question/196559/after-applying-cvxphotobm3ddenoising-imshow-is-giving-insertion-error/ and my answer is :
before calling bm3dDenoising, you must init gray1 (InputOupuArray array for in place computation):
gray1 = Mat::zeros(img.size(), CV_8UC1);
cv::xphoto::bm3dDenoising(gray, gray1, gray2, h, templateWindowSize, searchWindowSize, blockMatchingStep1, blockMatchingStep2, groupSize, slidingStep, beta, normType, step, transformType);
but I think there is a problem in code : you give BM3D_STEPALL then I think code should be :
case BM3D_STEPALL:
_basic.create(srcSize, type);
_dst.create(srcSize, type);
break;
Doc is here and BM3D_ALL does it mean you can get result BM3D_STEP1 and BM3D_STEP2 ?
What says absdiff()?
it is giving full black image , maybe there is no diff between the step2 output and gray image.
(using lena_noised_gaussian_sigma=10.png)
alalek:
It is not possible to see on display or via screenshot difference with 1-2 intensity changes.
You should use proper tool to analyse images:
countNonZero() Mat img, gray, gray1, gray2;
gray = imread("g:/lib/opencv/samples/data/lena.jpg",IMREAD_GRAYSCALE);
float h = 1;
int templateWindowSize = 4;
int searchWindowSize = 16;
int blockMatchingStep1 = 2500;
int blockMatchingStep2 = 400;
int groupSize = 8;
int slidingStep = 1;
float beta = 2.0f;
int normType = cv::NORM_L2;
int step = cv::xphoto::BM3D_STEPALL;
int transformType = cv::xphoto::HAAR;
imshow("b4_gray_image", gray); //1
gray1 = Mat::zeros(img.size(), CV_8UC1);
cv::xphoto::bm3dDenoising(gray, gray1, gray2, h, templateWindowSize, searchWindowSize, blockMatchingStep1, blockMatchingStep2, groupSize, slidingStep, beta, normType, step, transformType);
absdiff(gray1, gray2, dst);
imshow("dst2", dst*255); //4
!
absdiff(gray1, gray2, dst); imshow("dst2", dst*255);
its showing something like this[https://drive.google.com/open?id=1413wlkKQc_wvpnvGHgObki7zFlA-VaRy]
So results are not "the same", they are different.
Algorithm works somehow, but it can't "compensate" huge noise from provided input image.
Related PR has been merged: #1709