@@ -1311,14 +1311,11 @@ def test_rotate_fill(self):
1311
1311
1312
1312
def test_affine (self ):
1313
1313
input_img = np .zeros ((40 , 40 , 3 ), dtype = np .uint8 )
1314
- pts = []
1315
1314
cnt = [20 , 20 ]
1316
1315
for pt in [(16 , 16 ), (20 , 16 ), (20 , 20 )]:
1317
1316
for i in range (- 5 , 5 ):
1318
1317
for j in range (- 5 , 5 ):
1319
1318
input_img [pt [0 ] + i , pt [1 ] + j , :] = [255 , 155 , 55 ]
1320
- pts .append ((pt [0 ] + i , pt [1 ] + j ))
1321
- pts = list (set (pts ))
1322
1319
1323
1320
with self .assertRaises (TypeError ):
1324
1321
F .affine (input_img , 10 )
@@ -1373,9 +1370,12 @@ def _test_transformation(a, t, s, sh):
1373
1370
inv_true_matrix = np .linalg .inv (true_matrix )
1374
1371
for y in range (true_result .shape [0 ]):
1375
1372
for x in range (true_result .shape [1 ]):
1376
- res = np .dot (inv_true_matrix , [x , y , 1 ])
1377
- _x = int (res [0 ] + 0.5 )
1378
- _y = int (res [1 ] + 0.5 )
1373
+ # Same as for PIL:
1374
+ # https://github.com/python-pillow/Pillow/blob/71f8ec6a0cfc1008076a023c0756542539d057ab/
1375
+ # src/libImaging/Geometry.c#L1060
1376
+ input_pt = np .array ([x + 0.5 , y + 0.5 , 1.0 ])
1377
+ res = np .floor (np .dot (inv_true_matrix , input_pt )).astype (np .int )
1378
+ _x , _y = res [:2 ]
1379
1379
if 0 <= _x < input_img .shape [1 ] and 0 <= _y < input_img .shape [0 ]:
1380
1380
true_result [y , x , :] = input_img [_y , _x , :]
1381
1381
@@ -1408,7 +1408,7 @@ def _test_transformation(a, t, s, sh):
1408
1408
# Test rotation, scale, translation, shear
1409
1409
for a in range (- 90 , 90 , 25 ):
1410
1410
for t1 in range (- 10 , 10 , 5 ):
1411
- for s in [0.75 , 0.98 , 1.0 , 1.1 , 1.2 ]:
1411
+ for s in [0.75 , 0.98 , 1.0 , 1.2 , 1.4 ]:
1412
1412
for sh in range (- 15 , 15 , 5 ):
1413
1413
_test_transformation (a = a , t = (t1 , t1 ), s = s , sh = (sh , sh ))
1414
1414
0 commit comments