forked from richardboo/Wavelet_Image_Denoising
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathImageDenoise.h
45 lines (38 loc) · 1.49 KB
/
ImageDenoise.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#ifndef IMAGEDENOISE_H_INCLUDED
#define IMAGEDENOISE_H_INCLUDED
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <cmath>
Mat imdenoise (Mat B,float noise_mean)
{
int r = B.rows;
int c = B.cols;
float temp;
Mat Variance = Mat::zeros(r,c,CV_32F);
Mat Bdenoise = Mat::zeros(r,c,CV_32F);
//***************** ML Estimate of Variance ********************************************//
for (int i = 2; i < r-1; i++)
{
for (int j=2; j< c-1; j++)
{
temp = pow(B.at<float>(i-1,j-1),2) + pow(B.at<float>(i-1,j),2) + pow(B.at<float>(i-1,j+1),2) +
pow(B.at<float>(i,j-1),2) + pow(B.at<float>(i,j),2) + pow(B.at<float>(i,j+1),2) +
pow(B.at<float>(i+1,j-1),2) + pow(B.at<float>(i+1,j),2) + pow(B.at<float>(i+1,j+1),2);
Variance.at<float>(i,j) = (temp/9) - noise_mean;
if (Variance.at<float>(i,j) < 0 )
{
Variance.at<float>(i,j) = 0;
}
}
}
//************************** MMSE Estimate of Wavelet Coefficients ***********************************//
for (int i = 2; i < r-1; i++)
{
for (int j = 2; j < c-1; j++)
{
Bdenoise.at<float>(i,j) = (Variance.at<float>(i,j) / (Variance.at<float>(i,j) + noise_mean) ) * B.at<float>(i,j);
}
}
return Bdenoise;
}
#endif // IMAGEDENOISE_H_INCLUDED