mirror of https://github.com/open-mmlab/mmcv.git
parent
10fa1eeaf4
commit
43ca0e57a9
|
@ -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
|
||||
|
|
|
@ -1,2 +1,2 @@
|
|||
# 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, :])
|
||||
|
|
Loading…
Reference in New Issue