Unverified Commit 43ca0e57 authored by Kai Chen's avatar Kai Chen Committed by GitHub
Browse files

fix the shape assertion in impad (#172)

parent 10fa1eea
......@@ -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
......
# Copyright (c) Open-MMLab. All rights reserved.
__version__ = '0.2.15'
__version__ = '0.2.16'
......@@ -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, :])
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment