-
Notifications
You must be signed in to change notification settings - Fork 106
/
main.cpp
131 lines (112 loc) · 4.08 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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
/*=========================================================================
*
* Curvature Filter
*
**************************************************************************
@phdthesis{gong:phd,
title={Spectrally regularized surfaces},
author={Gong, Yuanhao},
year={2015},
school={ETH Zurich, Nr. 22616},
note={http://dx.doi.org/10.3929/ethz-a-010438292}}
*=========================================================================*/
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <iostream>
#include <fstream>
#include <assert.h>
#include <time.h>
#include <cmath>
//only needed by studying curvature statistics
#if defined(statistics)
#include <dirent.h>
#endif
using namespace cv;
using namespace std;
//default filter and iteration number
int ItNum = 10;
int Type = 2;
float lambda = 1.0f;
float DataFitOrder = 1.0f;
#include "CF.h"
//If use these filters to solve a complex data fitting term, define the data fitting as the blackbox function
float BlackBox(int row, int col, Mat& U, Mat & img_orig, float & d)
{
//this is an example of adaptive norm
float diff = fabs(U.at<float>(row,col)+d - img_orig.at<float>(row,col));
float order = 2 - (fabs(U.at<float>(row+1,col) - U.at<float>(row,col)) + fabs(U.at<float>(row,col+1) - U.at<float>(row,col)));
return pow(diff, order);
}
int main(int argc, char** argv)
{
CF DualMesh;
if ((argc<4) || (argc>6))
{
cout<<endl;
cout<<" -------------------- Curvature Filter ------------------------- "<<endl;
cout<<" Please cite Yuanhao's PhD thesis and related papers. Thank you! "<<endl;
cout<<" --------------------------------------------------------------- \n\n";
cout<<"usage: main imageName filterType Iterations.\nFor example: ./cf lena.bmp m 30\n";
cout<<" or "<<endl;
cout<<"usage: main imageName filterType MaxItNum lambda DataFitOrder.\nFor example: ./cf lena.bmp m 30 1.2 1.5\n";
cout<<"************************************************\n";
cout<<"Possible Filter Type: t (Total Variation) \n";
cout<<" m (Mean Curvature) \n";
cout<<" d (Difference Curvature, not ready) \n";
cout<<" g (Gaussian Curvature) \n";
cout<<" b (Bernstein Filter) \n";
return -1;
}
DualMesh.read(argv[1]);
char * filterType = argv[2];
switch(*filterType)
{
case 't':
{ Type = 0; break; }
case 'm':
{ Type = 1; break; }
case 'g':
{ Type = 2; break; }
case 'd':
{ Type = 3; break; }
case 'b':
{ Type = 4; break; }
default:
{ cout<<"Filter Type is NOT correct."<<endl; return -1; }
}
ItNum = atoi(argv[3]);
double mytime;
//just smooth the image by the filter
if (argc==4)
{
DualMesh.Filter(Type, mytime, ItNum);
cout<<"runtime is "<<mytime<<" milliseconds."<<endl;
DualMesh.write();
DualMesh.read(argv[1]);
DualMesh.FilterNoSplit(Type, mytime, ItNum);
cout<<"runtime (noSplit) is "<<mytime<<" milliseconds."<<endl;
DualMesh.write("CF_NoSplit.png");
}
//solve a variational model (data fitting term is blackbox)
if (argc==5)
{
lambda = (float)atof(argv[4]);
DualMesh.read(argv[1]);
DualMesh.BlackBoxSolver(Type, mytime, ItNum, lambda, BlackBox);
cout<<"runtime is "<<mytime<<" milliseconds."<<endl;
DualMesh.write("CF_BlackBox.png");
}
//solve a variational model
if (argc==6)
{
lambda = (float)atof(argv[4]);
DataFitOrder = (float)atof(argv[5]);
//filter solver for the variational models
DualMesh.read(argv[1]);
DualMesh.Solver(Type, mytime, ItNum, lambda, DataFitOrder);
cout<<"runtime is "<<mytime<<" milliseconds."<<endl;
DualMesh.write("CF_Solver.png");
}
return 0;
}