-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
111 lines (109 loc) · 2.93 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
#include "imgproc.h"
using namespace std;
int main(){
cout<<"equalize histogram"<<endl;
{
Mat mat("src.bmp");
mat.save("gray.bmp");
mat.saveHistogram("h_gray.bmp");
mat.equalizeHistogram();
mat.save("eqhist.bmp");
mat.saveHistogram("h_eqed.bmp");
}
cout<<"threshold & morphology"<<endl;
{
MorphCore mc("ooo;oxo;ooo");
MorphCore mc2("ooooo;ooooo;ooxoo;ooooo;ooooo");
Mat mat("src.bmp");
mat.threshold(128);
mat.save("thre.bmp");
mat.dilate(mc).save("dilate3.bmp");
mat.erode(mc).save("erode3.bmp");
mat.open(mc).save("open3.bmp");
mat.close(mc).save("close3.bmp");
mat.dilate(mc2).save("dilate5.bmp");
mat.erode(mc2).save("erode5.bmp");
mat.open(mc2).save("open5.bmp");
mat.close(mc2).save("close5.bmp");
}
cout<<"filter"<<endl;
{
FilterCore wavgc("1 2 1;2 4 2;1 2 1",16);
Mat mat("src.bmp");
mat.medianFilter(3).save("med_filt3.bmp");
mat.averageFilter(3).save("avg_filt3.bmp");
mat.medianFilter(5).save("med_filt5.bmp");
mat.averageFilter(5).save("avg_filt5.bmp");
mat.filter(wavgc).save("wavg_filt.bmp");
}
cout<<"smoothen"<<endl;
{
FilterCore wavgc("1 2 1;2 4 2;1 2 1",16);
Mat mat("src.bmp");
mat.addGaussianNoise(0,16);
mat.save("g_noise.bmp");
mat.medianFilter(3).save("g_noise_med_filt.bmp");
mat.averageFilter(3).save("g_noise_avg_filt.bmp");
mat.filter(wavgc).save("g_noise_wavg_filt.bmp");
Mat mat2("src.bmp");
mat2.addPepperNoise(0.01);
mat2.save("p_noise.bmp");
mat2.medianFilter(3).save("p_noise_med_filt.bmp");
mat2.averageFilter(3).save("p_noise_avg_filt.bmp");
mat2.filter(wavgc).save("p_noise_wavg_filt.bmp");
}
cout<<"contour"<<endl;
{
Mat mat("src.bmp");
mat.sobel().save("sobel.bmp");
mat.priwitt().save("priwitt.bmp");
mat.laplacian().save("laplacian.bmp");
}
cout<<"freq"<<endl;
Mat mat("src.bmp");
MatF src(mat);
src.save("freq.bmp");
cout<<"ilpf"<<endl;
{
MatF matf(src);
matf.idealFilter(50);
matf.save("freq_ideal_lpf.bmp");
matf.toMat().save("f_ideal_lpf.bmp");
}
cout<<"ihpf"<<endl;
{
MatF matf(src);
matf.idealFilter(20,false);
matf.save("freq_ideal_hpf.bmp");
matf.toMat().save("f_ideal_hpf.bmp");
}
cout<<"bwlpf"<<endl;
{
MatF matf(src);
matf.butterworthFilter(2,20);
matf.save("freq_bw_lpf.bmp");
matf.toMat().save("f_bw_lpf.bmp");
}
cout<<"bwhpf"<<endl;
{
MatF matf(src);
matf.butterworthFilter(2,50,false);
matf.save("freq_bw_hpf.bmp");
matf.toMat().save("f_bw_hpf.bmp");
}
cout<<"glpf"<<endl;
{
MatF matf(src);
matf.gaussianFilter(2,20);
matf.save("freq_g_lpf.bmp");
matf.toMat().save("f_g_lpf.bmp");
}
cout<<"ghpf"<<endl;
{
MatF matf(src);
matf.gaussianFilter(2,50,false);
matf.save("freq_g_hpf.bmp");
matf.toMat().save("f_g_hpf.bmp");
}
return 0;
}