| 1 | import numpy as np |
| 2 | |
| 3 | import imgviz |
| 4 | |
| 5 | |
| 6 | def test_centerize(): |
| 7 | img = np.random.uniform(0, 255, size=(15, 25, 3)).round().astype(np.uint8) |
| 8 | |
| 9 | dst = imgviz.centerize(img, shape=(25, 25), cval=0) |
| 10 | assert dst.shape == (25, 25, 3) |
| 11 | assert dst.dtype == img.dtype |
| 12 | assert (dst[:5] == 0).all() |
| 13 | assert (dst[-5:] == 0).all() |
| 14 | np.testing.assert_allclose(dst[5:-5], img) |
| 15 | |
| 16 | dst = imgviz.centerize(img, shape=(15, 35), cval=0) |
| 17 | assert dst.shape == (15, 35, 3) |
| 18 | assert dst.dtype == img.dtype |
| 19 | assert (dst[:, :5] == 0).all() |
| 20 | assert (dst[:, -5:] == 0).all() |
| 21 | np.testing.assert_allclose(dst[:, 5:-5], img) |