-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGaussianPyramid.cpp
More file actions
executable file
·110 lines (104 loc) · 2.87 KB
/
GaussianPyramid.cpp
File metadata and controls
executable file
·110 lines (104 loc) · 2.87 KB
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
#include "GaussianPyramid.h"
#include "math.h"
GaussianPyramid::GaussianPyramid(void)
{
ImPyramid=NULL;
}
GaussianPyramid::~GaussianPyramid(void)
{
if(ImPyramid!=NULL)
delete []ImPyramid;
}
//---------------------------------------------------------------------------------------
// function to construct the pyramid
// this is the slow way
//---------------------------------------------------------------------------------------
/*void GaussianPyramid::ConstructPyramid(const DImage &image, double ratio, int minWidth)
{
// the ratio cannot be arbitrary numbers
if(ratio>0.98 || ratio<0.4)
ratio=0.75;
// first decide how many levels
nLevels=log((double)minWidth/image.width())/log(ratio);
if(ImPyramid!=NULL)
delete []ImPyramid;
ImPyramid=new DImage[nLevels];
ImPyramid[0].copyData(image);
double baseSigma=(1/ratio-1);
for(int i=1;i<nLevels;i++)
{
DImage foo;
double sigma=baseSigma*i;
image.GaussianSmoothing(foo,sigma,sigma*2.5);
foo.imresize(ImPyramid[i],pow(ratio,i));
}
}//*/
//---------------------------------------------------------------------------------------
// function to construct the pyramid
// this is the fast way
//---------------------------------------------------------------------------------------
void GaussianPyramid::ConstructPyramid(const DImage &image, double ratio, int minWidth)
{
// the ratio cannot be arbitrary numbers
if(ratio>0.98 || ratio<0.4)
ratio=0.75;
// first decide how many levels
nLevels=log((double)minWidth/image.width())/log(ratio);
if(ImPyramid!=NULL)
delete []ImPyramid;
ImPyramid=new DImage[nLevels];
ImPyramid[0].copyData(image);
double baseSigma=(1/ratio-1);
int n=log(0.25)/log(ratio);
double nSigma=baseSigma*n;
for(int i=1;i<nLevels;i++)
{
DImage foo;
if(i<=n)
{
double sigma=baseSigma*i;
image.GaussianSmoothing(foo,sigma,sigma*3);
foo.imresize(ImPyramid[i],pow(ratio,i));
}
else
{
ImPyramid[i-n].GaussianSmoothing(foo,nSigma,nSigma*3);
double rate=(double)pow(ratio,i)*image.width()/foo.width();
foo.imresize(ImPyramid[i],rate);
}
}
}
void GaussianPyramid::ConstructPyramidLevels(const DImage &image, double ratio, int _nLevels)
{
// the ratio cannot be arbitrary numbers
if(ratio>0.98 || ratio<0.4)
ratio=0.75;
nLevels = _nLevels;
if(ImPyramid!=NULL)
delete []ImPyramid;
ImPyramid=new DImage[nLevels];
ImPyramid[0].copyData(image);
double baseSigma=(1/ratio-1);
int n=log(0.25)/log(ratio);
double nSigma=baseSigma*n;
for(int i=1;i<nLevels;i++)
{
DImage foo;
if(i<=n)
{
double sigma=baseSigma*i;
image.GaussianSmoothing(foo,sigma,sigma*3);
foo.imresize(ImPyramid[i],pow(ratio,i));
}
else
{
ImPyramid[i-n].GaussianSmoothing(foo,nSigma,nSigma*3);
double rate=(double)pow(ratio,i)*image.width()/foo.width();
foo.imresize(ImPyramid[i],rate);
}
}
}
void GaussianPyramid::displayTop(const char *filename)
{
ImPyramid[nLevels-1].imwrite(filename);
}