fix the shape assertion in impad (#172)

pull/173/head v0.2.16
Kai Chen 2020-01-11 17:53:35 +08:00 committed by GitHub
parent 10fa1eeaf4
commit 43ca0e57a9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 2 deletions

View File

@ -180,7 +180,7 @@ def impad(img, shape, pad_val=0):
if len(shape) < len(img.shape):
shape = shape + (img.shape[-1], )
assert len(shape) == len(img.shape)
for i in range(len(shape) - 1):
for i in range(len(shape)):
assert shape[i] >= img.shape[i]
pad = np.empty(shape, dtype=img.dtype)
pad[...] = pad_val

View File

@ -1,2 +1,2 @@
# Copyright (c) Open-MMLab. All rights reserved.
__version__ = '0.2.15'
__version__ = '0.2.16'

View File

@ -281,6 +281,16 @@ class TestImage(object):
self.assert_img_equal(patches[i], ref_patch)
def test_impad(self):
# grayscale image
img = np.random.rand(10, 10).astype(np.float32)
padded_img = mmcv.impad(img, (15, 12), 0)
assert_array_equal(img, padded_img[:10, :10])
assert_array_equal(
np.zeros((5, 12), dtype='float32'), padded_img[10:, :])
assert_array_equal(
np.zeros((15, 2), dtype='float32'), padded_img[:, 10:])
# RGB image
img = np.random.rand(10, 10, 3).astype(np.float32)
padded_img = mmcv.impad(img, (15, 12), 0)
assert_array_equal(img, padded_img[:10, :10, :])