Skip to content

Commit 72bf87c

Browse files
committed
test formatting, change .image to .array
1 parent ee35b7a commit 72bf87c

3 files changed

Lines changed: 60 additions & 60 deletions

File tree

tests/test_camera.py

Lines changed: 46 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def test_parameters(self):
1616

1717
c = CentralCamera(f=0.2)
1818
nt.assert_array_almost_equal(c.f, (0.2, 0.2))
19-
self.assertEqual(c.camtype, 'perspective')
19+
self.assertEqual(c.camtype, "perspective")
2020
self.assertEqual(c.fu, 0.2)
2121
self.assertEqual(c.fv, 0.2)
2222

@@ -71,15 +71,15 @@ def test_parameters(self):
7171
self.assertEqual(c.u0, 200)
7272
self.assertEqual(c.v0, 300)
7373
nt.assert_array_almost_equal(c.pp, (200, 300))
74-
74+
7575
# Test setting focal length
7676
c = CentralCamera(f=0.015)
7777
try:
7878
c.f = 0.02
7979
self.assertAlmostEqual(c.f[0], 0.02)
8080
except:
8181
pass
82-
82+
8383
# Test setting principal point
8484
try:
8585
c.pp = (400, 300)
@@ -93,21 +93,21 @@ def test_pose(self):
9393
c = CentralCamera()
9494
self.assertTrue(c.pose == SE3())
9595

96-
x = SE3(1,2,3)
97-
y = SE3(4,5,6)
98-
96+
x = SE3(1, 2, 3)
97+
y = SE3(4, 5, 6)
98+
9999
# Test setting pose
100100
c.pose = x
101101
self.assertTrue(c.pose == x)
102-
102+
103103
# Test different pose
104104
c.pose = y
105105
self.assertTrue(c.pose == y)
106-
106+
107107
def test_project_point(self):
108108
"""Test projecting 3D points to image plane"""
109109
c = CentralCamera(f=0.015, rho=10e-6, imagesize=[1280, 1024])
110-
110+
111111
# Project a single point
112112
try:
113113
P = np.array([0.1, 0.2, 3.0])
@@ -116,55 +116,55 @@ def test_project_point(self):
116116
except:
117117
# Method might not exist
118118
pass
119-
119+
120120
# Project multiple points
121121
try:
122122
P_multi = np.array([[0.1, 0.2, 0.3], [0.2, 0.3, 0.4], [3.0, 3.0, 3.0]]).T
123123
p_multi = c.project_point(P_multi)
124124
self.assertEqual(p_multi.shape[1], 3)
125125
except:
126126
pass
127-
127+
128128
def test_K_matrix(self):
129129
"""Test camera calibration matrix"""
130130
c = CentralCamera(f=0.015, rho=10e-6, imagesize=[1280, 1024], pp=(640, 512))
131131
K = c.K
132-
132+
133133
# Check shape
134134
self.assertEqual(K.shape, (3, 3))
135-
135+
136136
# Check that K is upper triangular (mostly)
137137
self.assertNotEqual(K[0, 0], 0) # fu
138138
self.assertNotEqual(K[1, 1], 0) # fv
139139
self.assertNotEqual(K[0, 2], 0) # u0
140140
self.assertNotEqual(K[1, 2], 0) # v0
141-
self.assertEqual(K[2, 2], 1.0) # Bottom right should be 1
142-
141+
self.assertEqual(K[2, 2], 1.0) # Bottom right should be 1
142+
143143
def test_C_matrix(self):
144144
"""Test camera matrix"""
145145
c = CentralCamera(f=0.015, rho=10e-6)
146146
C = c.C()
147-
147+
148148
# Check shape
149149
self.assertEqual(C.shape, (3, 4))
150-
150+
151151
def test_different_camera_types(self):
152152
"""Test different camera models"""
153153
# Perspective camera
154154
c_persp = CentralCamera(f=0.015)
155-
self.assertEqual(c_persp.camtype, 'perspective')
156-
155+
self.assertEqual(c_persp.camtype, "perspective")
156+
157157
# Test camera with distortion parameters
158158
try:
159159
c_dist = CentralCamera(f=0.015, distortion=[0.1, 0.01])
160160
self.assertIsNotNone(c_dist.distortion)
161161
except:
162162
pass
163-
163+
164164
def test_ray_direction(self):
165165
"""Test computing ray directions"""
166166
c = CentralCamera(f=0.015, rho=10e-6, imagesize=[1280, 1024])
167-
167+
168168
try:
169169
# Test getting ray for a pixel
170170
ray = c.ray([640, 512])
@@ -173,12 +173,12 @@ def test_ray_direction(self):
173173
except:
174174
# Method might not exist
175175
pass
176-
176+
177177
@unittest.skip("move method doesn't work as expected")
178178
def test_move_camera(self):
179179
"""Test moving camera in space"""
180180
c = CentralCamera()
181-
181+
182182
# Move camera
183183
T = SE3(1, 2, 3)
184184
try:
@@ -200,20 +200,20 @@ def test_move_camera(self):
200200
self.assertTrue(c2.pose == x)
201201

202202
def test_str(self):
203-
c = CentralCamera(f=0.123, imagesize=(2000, 3000), name='fred')
203+
c = CentralCamera(f=0.123, imagesize=(2000, 3000), name="fred")
204204
s = str(c)
205205
self.assertIsInstance(s, str)
206-
self.assertTrue('fred' in s)
207-
self.assertTrue('CentralCamera' in s)
208-
self.assertTrue('2000' in s)
209-
self.assertTrue('3000' in s)
210-
self.assertTrue('0.123' in s)
206+
self.assertTrue("fred" in s)
207+
self.assertTrue("CentralCamera" in s)
208+
self.assertTrue("2000" in s)
209+
self.assertTrue("3000" in s)
210+
self.assertTrue("0.123" in s)
211211

212212
def test_project(self):
213213

214214
c = CentralCamera(f=1, rho=1, pp=(0, 0))
215215
p = c.project_point([0, 0, 5])
216-
self.assertTrue(p.shape == (2,1))
216+
self.assertTrue(p.shape == (2, 1))
217217
nt.assert_array_almost_equal(p.flatten(), [0, 0])
218218

219219
p = c.project_point([1, 0, 5])
@@ -243,7 +243,7 @@ def test_project(self):
243243
p = c.project_point([1, -1, 5], objpose=SE3(-1, 1, 0))
244244
nt.assert_array_almost_equal(p.flatten(), [0, 0])
245245

246-
c = CentralCamera(f=1, rho=1, pp=(1,1))
246+
c = CentralCamera(f=1, rho=1, pp=(1, 1))
247247

248248
p = c.project_point([0, -1, 5])
249249
nt.assert_array_almost_equal(p.flatten(), [1, 0.8])
@@ -288,62 +288,62 @@ def test_plucker(self):
288288

289289
line = c.ray(p)
290290
self.assertTrue(line.contains(P))
291-
291+
292292
def test_camera_attributes_access(self):
293293
"""Test accessing various camera attributes"""
294294
c = CentralCamera(f=0.015, rho=10e-6, imagesize=[1280, 1024], pp=(640, 512))
295-
295+
296296
# Test accessing imaging plane size
297297
self.assertEqual(c.width, 1280)
298298
self.assertEqual(c.height, 1024)
299-
299+
300300
# Test pixel size
301301
self.assertEqual(c.rhou, 10e-6)
302302
self.assertEqual(c.rhov, 10e-6)
303-
303+
304304
def test_camera_pose_transformations(self):
305305
"""Test camera pose and transformation"""
306306
c = CentralCamera()
307-
307+
308308
# Initial pose
309309
initial_pose = c.pose
310310
self.assertTrue(isinstance(initial_pose, SE3))
311-
311+
312312
# Set new pose
313313
new_pose = SE3(0.5, 0.5, 0.5)
314314
c.pose = new_pose
315315
self.assertTrue(c.pose == new_pose)
316-
316+
317317
def test_camera_matrix_access(self):
318318
"""Test accessing camera matrices"""
319319
c = CentralCamera(f=0.015, rho=10e-6, pp=(640, 512))
320-
320+
321321
try:
322322
# K matrix
323323
K = c.K
324324
self.assertEqual(K.shape, (3, 3))
325325
self.assertEqual(K[2, 2], 1.0)
326326
except:
327327
pass
328-
328+
329329
try:
330330
# C matrix
331331
C = c.C()
332332
self.assertEqual(C.shape, (3, 4))
333333
except:
334334
pass
335-
335+
336336
try:
337-
# P matrix
337+
# P matrix
338338
P = c.P()
339339
self.assertEqual(P.shape, (3, 4))
340340
except:
341341
pass
342-
342+
343343
def test_camera_clone_methods(self):
344344
"""Test camera cloning/copying"""
345345
c = CentralCamera(f=0.015, pose=SE3(1, 2, 3))
346-
346+
347347
try:
348348
# Some way to clone the camera
349349
c_copy = CentralCamera(f=0.015, pose=c.pose)
@@ -353,6 +353,6 @@ def test_camera_clone_methods(self):
353353

354354

355355
# ----------------------------------------------------------------------- #
356-
if __name__ == '__main__':
356+
if __name__ == "__main__":
357357

358-
unittest.main()
358+
unittest.main()

tests/test_color.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,11 @@ def test_gamma(self):
4343

4444
a = Image(np.array([[0.4]]))
4545
g = a.gamma_encode(0.5)
46-
nt.assert_array_almost_equal(g.image * g.image, a.image)
46+
nt.assert_array_almost_equal(g.array * g.array, a.array)
4747

4848
a = Image(np.array([[64.0]]))
4949
g = a.gamma_encode(0.5)
50-
nt.assert_array_almost_equal(g.image * g.image, a.image)
50+
nt.assert_array_almost_equal(g.array * g.array, a.array)
5151

5252
# test for shape
5353
g = a.gamma("srgb")
@@ -56,7 +56,7 @@ def test_gamma(self):
5656
a = Image(np.random.rand(5, 5))
5757
g = a.gamma(0.5)
5858
nt.assert_array_almost_equal(g.shape, a.shape)
59-
nt.assert_array_almost_equal(g.gamma(2).image, a.image)
59+
nt.assert_array_almost_equal(g.gamma(2).array, a.array)
6060

6161
a = Image(np.random.rand(5, 5, 3))
6262
g = a.gamma(0.5)
@@ -74,7 +74,7 @@ def test_colorize(self):
7474
self.assertAlmostEqual(out.A[0, 0, 2], 0.1)
7575
# TODO mask functionality not yet implemented
7676

77-
@unittest.skip("Code has a bug: mono.image should be mono")
77+
@unittest.skip("Code has a bug: mono.array should be mono")
7878
def test_mono(self):
7979
# input an image that is not mono
8080
im = Image.Read("monalisa.png")

tests/test_processing.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ def test_float(self):
182182
im = Image(im)
183183
imf = im.to_float()
184184
nt.assert_array_almost_equal(imf.shape, im.shape)
185-
nt.assert_array_almost_equal(imf, im.image.astype(np.float32) / 65535.0)
185+
nt.assert_array_almost_equal(imf, im.array.astype(np.float32) / 65535.0)
186186

187187
def test_testpattern(self):
188188
tp = Image.Ramp(dir="x", size=20, cycles=2)
@@ -224,10 +224,10 @@ def test_testpattern(self):
224224
# TODO not yet converted to python:
225225
# tp = im.testpattern('line', 20, np.pi / 6, 10)
226226
# self.assertEqual(tp.shape, (20, 20))
227-
# self.assertEqual(tp.image[10, 0], 1)
228-
# self.assertEqual(tp.image[11, 1], 1)
229-
# self.assertEqual(tp.image[16, 11], 1)
230-
# self.assertEqual(np.sum(tp.image), 17)
227+
# self.assertEqual(tp.array[10, 0], 1)
228+
# self.assertEqual(tp.array[11, 1], 1)
229+
# self.assertEqual(tp.array[16, 11], 1)
230+
# self.assertEqual(np.sum(tp.array), 17)
231231

232232
def test_paste(self):
233233

@@ -246,28 +246,28 @@ def test_paste(self):
246246
]
247247
)
248248
cp = canvas.paste(im, (2, 1))
249-
nt.assert_array_almost_equal(cp.image, out)
249+
nt.assert_array_almost_equal(cp.array, out)
250250

251251
canvas = np.zeros((5, 5))
252252
canvas = Image(canvas)
253253
cp = canvas.paste(im, (3, 2), position="centre")
254-
nt.assert_array_almost_equal(cp.image, out)
254+
nt.assert_array_almost_equal(cp.array, out)
255255

256256
canvas = np.zeros((5, 5))
257257
canvas = Image(canvas)
258258
cp = canvas.paste(im, (2, 1), method="set")
259-
nt.assert_array_almost_equal(cp.image, out)
259+
nt.assert_array_almost_equal(cp.array, out)
260260

261261
canvas = np.zeros((5, 5))
262262
canvas = Image(canvas)
263263
cp = canvas.paste(im, (2, 1), method="mean")
264-
nt.assert_array_almost_equal(cp.image, out / 2)
264+
nt.assert_array_almost_equal(cp.array, out / 2)
265265

266266
canvas = np.zeros((5, 5))
267267
canvas = Image(canvas)
268268
cp = canvas.paste(im, (2, 1), method="add")
269269
cp2 = cp.paste(im, (2, 1), method="add")
270-
nt.assert_array_almost_equal(cp2.image, out * 2)
270+
nt.assert_array_almost_equal(cp2.array, out * 2)
271271

272272
def test_choose(self):
273273

0 commit comments

Comments
 (0)