|
|
@ -41,7 +41,8 @@ |
|
|
|
#include "test_precomp.hpp" |
|
|
|
#include "test_precomp.hpp" |
|
|
|
#include "opencv2/highgui.hpp" |
|
|
|
#include "opencv2/highgui.hpp" |
|
|
|
|
|
|
|
|
|
|
|
void make_noisy(const cv::Mat& img, cv::Mat& noisy, double sigma, double pepper_salt_ratio,cv::RNG& rng){ |
|
|
|
void make_noisy(const cv::Mat& img, cv::Mat& noisy, double sigma, double pepper_salt_ratio,cv::RNG& rng) |
|
|
|
|
|
|
|
{ |
|
|
|
noisy.create(img.size(), img.type()); |
|
|
|
noisy.create(img.size(), img.type()); |
|
|
|
cv::Mat noise(img.size(), img.type()), mask(img.size(), CV_8U); |
|
|
|
cv::Mat noise(img.size(), img.type()), mask(img.size(), CV_8U); |
|
|
|
rng.fill(noise,cv::RNG::NORMAL,128.0,sigma); |
|
|
|
rng.fill(noise,cv::RNG::NORMAL,128.0,sigma); |
|
|
@ -54,34 +55,36 @@ void make_noisy(const cv::Mat& img, cv::Mat& noisy, double sigma, double pepper_ |
|
|
|
noise.setTo(128, mask); |
|
|
|
noise.setTo(128, mask); |
|
|
|
cv::addWeighted(noisy, 1, noise, 1, -128, noisy); |
|
|
|
cv::addWeighted(noisy, 1, noise, 1, -128, noisy); |
|
|
|
} |
|
|
|
} |
|
|
|
void make_spotty(cv::Mat& img,cv::RNG& rng, int r=3,int n=1000){ |
|
|
|
|
|
|
|
for(int i=0;i<n;i++){ |
|
|
|
void make_spotty(cv::Mat& img,cv::RNG& rng, int r=3,int n=1000) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
for(int i=0;i<n;i++) |
|
|
|
|
|
|
|
{ |
|
|
|
int x=rng(img.cols-r),y=rng(img.rows-r); |
|
|
|
int x=rng(img.cols-r),y=rng(img.rows-r); |
|
|
|
if(rng(2)==0){ |
|
|
|
if(rng(2)==0) |
|
|
|
img(cv::Range(y,y+r),cv::Range(x,x+r))=(uchar)0; |
|
|
|
img(cv::Range(y,y+r),cv::Range(x,x+r))=(uchar)0; |
|
|
|
}else{ |
|
|
|
else |
|
|
|
img(cv::Range(y,y+r),cv::Range(x,x+r))=(uchar)255; |
|
|
|
img(cv::Range(y,y+r),cv::Range(x,x+r))=(uchar)255; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
bool validate_pixel(const cv::Mat& image,int x,int y,uchar val){ |
|
|
|
bool validate_pixel(const cv::Mat& image,int x,int y,uchar val) |
|
|
|
|
|
|
|
{ |
|
|
|
printf("test: image(%d,%d)=%d vs %d - %s\n",x,y,(int)image.at<uchar>(x,y),val,(val==image.at<uchar>(x,y))?"true":"false"); |
|
|
|
printf("test: image(%d,%d)=%d vs %d - %s\n",x,y,(int)image.at<uchar>(x,y),val,(val==image.at<uchar>(x,y))?"true":"false"); |
|
|
|
return (image.at<uchar>(x,y)==val); |
|
|
|
return (image.at<uchar>(x,y)==val); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
TEST(Optim_denoise_tvl1, regression_basic){ |
|
|
|
TEST(Optim_denoise_tvl1, regression_basic) |
|
|
|
|
|
|
|
{ |
|
|
|
cv::RNG rng(42); |
|
|
|
cv::RNG rng(42); |
|
|
|
cv::Mat img = cv::imread("lena.jpg", 0), noisy,res; |
|
|
|
cv::Mat img = cv::imread(cvtest::TS::ptr()->get_data_path() + "shared/lena.png", 0), noisy, res; |
|
|
|
if(img.rows!=512 || img.cols!=512){ |
|
|
|
|
|
|
|
printf("\tplease, put lena.jpg from samples/c in the current folder\n"); |
|
|
|
ASSERT_FALSE(img.empty()) << "Error: can't open 'lena.png'"; |
|
|
|
printf("\tnow, the test will fail...\n"); |
|
|
|
|
|
|
|
ASSERT_TRUE(false); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const int obs_num=5; |
|
|
|
const int obs_num=5; |
|
|
|
std::vector<cv::Mat> images(obs_num,cv::Mat()); |
|
|
|
std::vector<cv::Mat> images(obs_num, cv::Mat()); |
|
|
|
for(int i=0;i<(int)images.size();i++){ |
|
|
|
for(int i=0;i<(int)images.size();i++) |
|
|
|
|
|
|
|
{ |
|
|
|
make_noisy(img,images[i], 20, 0.02,rng); |
|
|
|
make_noisy(img,images[i], 20, 0.02,rng); |
|
|
|
//make_spotty(images[i],rng);
|
|
|
|
//make_spotty(images[i],rng);
|
|
|
|
} |
|
|
|
} |
|
|
|