forked from vinograd47/AdaptiveManifoldFilter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
103 lines (88 loc) · 3.25 KB
/
main.cpp
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#include <iostream>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/contrib/contrib.hpp>
#include <opencv2/photo/photo.hpp>
#include "adaptive_manifold_filter.hpp"
using namespace std;
using namespace cv;
int main(int argc, const char* argv[])
{
CommandLineParser cmd(argc, argv,
"{ i | input | | Input image }"
"{ o | output | | Output image }"
"{ j | joint | | Image for joint filtering (optional) }"
"{ s | sigma_s | 16.0 | Filter spatial standard deviation }"
"{ r | sigma_r | 0.2 | Filter range standard deviation }"
"{ t | tree_height | -1 | Height of the manifold tree (default = -1 : automatically computed) }"
"{ i | num_pca_iterations | 1 | Number of iterations to computed the eigenvector v1 }"
"{ h | help | | Print help message }"
);
if (cmd.get<bool>("help"))
{
cout << "This sample demonstrates adaptive manifold filter algorithm" << endl;
cmd.printParams();
return 0;
}
const string inputImageName = cmd.get<string>("input");
const string outputImageName = cmd.get<string>("output");
const string jointImageName = cmd.get<string>("joint");
const double sigma_s = cmd.get<double>("sigma_s");
const double sigma_r = cmd.get<double>("sigma_r");
const int tree_height = cmd.get<int>("tree_height");
const int num_pca_iterations = cmd.get<int>("num_pca_iterations");
if (inputImageName.empty())
{
cerr << "Missing input image" << endl;
cmd.printParams();
return -1;
}
Mat img = imread(inputImageName);
if (img.empty())
{
cerr << "Can't open image - " << inputImageName << endl;
return -1;
}
Mat jointImg;
if (!jointImageName.empty())
{
jointImg = imread(jointImageName);
if (jointImg.empty())
{
cerr << "Can't open image - " << inputImageName << endl;
return -1;
}
}
Ptr<AdaptiveManifoldFilter> filter = AdaptiveManifoldFilter::create();
filter->set("sigma_s", sigma_s);
filter->set("sigma_r", sigma_r);
filter->set("tree_height", tree_height);
filter->set("num_pca_iterations", num_pca_iterations);
Mat dst, tilde_dst;
filter->apply(img, dst, tilde_dst, jointImg);
TickMeter tm;
tm.start();
filter->apply(img, dst, tilde_dst, jointImg);
tm.stop();
cout << "Time : " << tm.getTimeMilli() << " ms" << endl;
Mat nlm_dst;
fastNlMeansDenoisingColored(img, nlm_dst, 10.0, 10.0);
tm.reset(); tm.start();
fastNlMeansDenoisingColored(img, nlm_dst, 10.0, 10.0);
tm.stop();
cout << "NLM : " << tm.getTimeMilli() << " ms" << endl;
if (!outputImageName.empty())
{
const string::size_type dotPos = outputImageName.find_last_of('.');
const string name = outputImageName.substr(0, dotPos);
const string ext = outputImageName.substr(dotPos + 1);
imwrite(outputImageName, dst);
imwrite(name + "_tilde." + ext, tilde_dst);
}
imshow("Input", img);
imshow("Output", dst);
imshow("Tilde Output", tilde_dst);
imshow("NLM", nlm_dst);
waitKey();
return 0;
}