Skip to content

Commit 17df356

Browse files
djkapnerfcollman
authored andcommitted
adding return_all option to affine transform (#124)
1 parent 4c41492 commit 17df356

File tree

2 files changed

+22
-7
lines changed

2 files changed

+22
-7
lines changed

renderapi/transform/leaf/affine_models.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ def load_M(self):
119119
self.M[1, 2] = self.B1
120120

121121
@staticmethod
122-
def fit(A, B):
122+
def fit(A, B, return_all=False):
123123
"""function to fit this transform given the corresponding sets of points A & B
124124
125125
Parameters
@@ -151,6 +151,8 @@ def fit(A, B):
151151
Y[2 * i + 1] = B[i, 1]
152152

153153
(Tvec, residuals, rank, s) = np.linalg.lstsq(M, Y)
154+
if return_all:
155+
return Tvec, residuals, rank, s
154156
return Tvec
155157

156158
def estimate(self, A, B, return_params=True, **kwargs):

test/test_transform.py

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -104,12 +104,18 @@ def test_affine_fail():
104104

105105

106106
def test_affine_random():
107-
am = renderapi.transform.AffineModel(M00=.9,
108-
M10=-0.2,
109-
M01=0.3,
110-
M11=.85,
111-
B0=245.3,
112-
B1=-234.1)
107+
M00 = .9
108+
M10 = -0.2
109+
M01 = 0.3
110+
M11 = .85
111+
B0 = 245.3
112+
B1 = -234.1
113+
am = renderapi.transform.AffineModel(M00=M00,
114+
M10=M10,
115+
M01=M01,
116+
M11=M11,
117+
B0=B0,
118+
B1=B1)
113119

114120
points_in = np.random.rand(10, 2)
115121
points_out = am.tform(points_in)
@@ -119,6 +125,13 @@ def test_affine_random():
119125

120126
assert(np.sum(np.abs(am.M.ravel() - am_fit.M.ravel())) < (.001 * 6))
121127

128+
# return_all test
129+
tvec, res, rank, s = am.fit(points_in, points_out, return_all=True)
130+
compare_tvec = np.array([M00, M01, M10, M11, B0, B1])
131+
tvec = tvec.flatten()
132+
assert(np.linalg.norm(tvec - compare_tvec) < EPSILON)
133+
assert(res < EPSILON)
134+
122135

123136
def test_invert_Affine():
124137
am = renderapi.transform.AffineModel(M00=.9,

0 commit comments

Comments
 (0)