- Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathpyramid.py
More file actions
Latest commit
83 lines (62 loc) · 2.11 KB
/
Copy pathpyramid.py
File metadata and controls
83 lines (62 loc) · 2.11 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
#*********************************************************************
#* pyramid.py
#*
#*********************************************************************
fromerrorimport*
fromconvolveimport*
importnumpyasnp
#*********************************************************************
#*
#*
classKLTPyramid:
def__init__(self, ncols, nrows, subsampling, nlevels):
ifsubsampling!=2andsubsampling!=4and \
subsampling!=8andsubsampling!=16andsubsampling!=32:
KLTError("(_KLTCreatePyramid) Pyramid's subsampling must "+ \
"be either 2, 4, 8, 16, or 32")
# Set parameters
self.subsampling=subsampling;
self.nLevels=nlevels;
self.img= []
self.ncols= []
self.nrows= []
# Allocate memory for each level of pyramid and assign pointers
foriinrange(nlevels):
self.img.append(None)
self.ncols.append(ncols)
self.nrows.append(nrows)
ncols/=subsampling
nrows/=subsampling
defCompute(self, img, sigma_fact):
nrows=img.shape[0]
ncols=img.shape[1]
subsampling=self.subsampling
subhalf=subsampling/2
sigma=subsampling*sigma_fact; # empirically determined
#int oldncols;
#int i, x, y;
ifsubsampling!=2andsubsampling!=4and \
subsampling!=8andsubsampling!=16andsubsampling!=32:
KLTError("(_KLTComputePyramid) Pyramid's subsampling must "+ \
"be either 2, 4, 8, 16, or 32")
assertself.ncols[0] ==ncols
assertself.nrows[0] ==nrows
# Copy original image to level 0 of pyramid
self.img[0] =img
currimg=img
foriinrange(1,self.nLevels):
tmpimg=KLTComputeSmoothedImage(currimg, sigma)
#tmpimgL = tmpimg.load()
# Subsample
oldncols=ncols
ncols=int(ncols/subsampling)
nrows=int(nrows/subsampling)
#subsampImg = Image.new("F",(ncols,nrows))
subsampImg=np.empty((nrows,ncols), np.float32)
#subsampImgL = subsampImg.load()
foryinrange(nrows):
forxinrange(ncols):
subsampImg[y,x] =tmpimg[int(subsampling*y+subhalf), int(subsampling*x+subhalf)]
self.img[i] =subsampImg
# Reassign current image
currimg=self.img[i]