-
Notifications
You must be signed in to change notification settings - Fork 1
/
NoFeature.py
53 lines (42 loc) · 1.8 KB
/
NoFeature.py
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
__author__ = 'Tommy'
from FeatureBase import *
from ImageUtils import *
from SCVUtils import *
class NoFeature(FeatureBase):
def __init__(self, multi_approach='none'):
FeatureBase.__init__(self, multi_approach)
if self.multi_approach == 'none':
self.getSampledRegion = sample_region
else:
self.getSampledRegion = sample_region_vec
if self.multi_approach == 'none' or self.multi_approach == 'flatten':
self.getJacobian = self.getJacobianOfImage
else:
self.getJacobian = self.getJacobianOfImageVec
def getFeature(self, img, pts, warp, use_scv=False):
sampled_img = self.getSampledRegion(img, pts, warp, flatten=self.flatten)
if use_scv and self.scv_intensity_map is not None:
sampled_img = self.getSCVExpectation(sampled_img, self.scv_intensity_map)
return sampled_img
def getJacobianOfImage(self, img, pts, initial_warp, eps=1e-10):
n_pts = pts.shape[1] * self.n_channels
def f(p):
W = initial_warp * make_hom_sl3(p)
return self.getFeature(img, pts, W)
jacobian = np.empty((n_pts, 8))
for i in xrange(0, 8):
o = np.zeros(8)
o[i] = eps
jacobian[:, i] = (f(o) - f(-o)) / (2 * eps)
return np.asmatrix(jacobian)
def getJacobianOfImageVec(self, img, pts, initial_warp, eps=1e-10):
n_pts = pts.shape[1]
def f(p):
W = initial_warp * make_hom_sl3(p)
return self.getFeature(img, pts, W)
jacobian = np.empty((self.n_channels, n_pts, 8))
for i in xrange(0, 8):
o = np.zeros(8)
o[i] = eps
jacobian[:, :, i] = (f(o) - f(-o)) / (2 * eps)
return jacobian