From a3dce1ebc3ccf5a924b4f2fa9493e80726af223e Mon Sep 17 00:00:00 2001 From: Anirudh Acharya Date: Tue, 16 Oct 2018 14:08:08 -0700 Subject: [PATCH] address comments --- python/mxnet/image/image.py | 23 ++++++++++++++++++++--- tests/python/unittest/test_image.py | 8 +++++--- 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/python/mxnet/image/image.py b/python/mxnet/image/image.py index dece30ecb7f2..a90a6355105f 100644 --- a/python/mxnet/image/image.py +++ b/python/mxnet/image/image.py @@ -87,8 +87,8 @@ def imread(filename, *args, **kwargs): def imresize(src, w, h, interp): r"""Resize image with OpenCV. - Note: `imread` uses OpenCV (not the CV2 Python library). - MXNet must have been built with USE_OPENCV=1 for `imdecode` to work. + .. note:: `imresize` uses OpenCV (not the CV2 Python library). MXNet must have been built + with USE_OPENCV=1 for `imresize` to work. Parameters ---------- @@ -98,8 +98,25 @@ def imresize(src, w, h, interp): Width of resized image. h : int, required Height of resized image. - interp : int, optional, default='1' + interp : int, optional, default=1 Interpolation method (default=cv2.INTER_LINEAR). + Possible values: + 0: Nearest Neighbors Interpolation. + 1: Bilinear interpolation. + 2: Area-based (resampling using pixel area relation). It may be a + preferred method for image decimation, as it gives moire-free + results. But when the image is zoomed, it is similar to the Nearest + Neighbors method. (used by default). + 3: Bicubic interpolation over 4x4 pixel neighborhood. + 4: Lanczos interpolation over 8x8 pixel neighborhood. + 9: Cubic for enlarge, area for shrink, bilinear for others + 10: Random select from interpolation method metioned above. + Note: + When shrinking an image, it will generally look best with AREA-based + interpolation, whereas, when enlarging an image, it will generally look best + with Bicubic (slow) or Bilinear (faster but still looks OK). + More details can be found in the documentation of OpenCV, please refer to + http://docs.opencv.org/master/da/d54/group__imgproc__transform.html. out : NDArray, optional The output NDArray to hold the result. diff --git a/tests/python/unittest/test_image.py b/tests/python/unittest/test_image.py index 1e780149b427..5113f366cf92 100644 --- a/tests/python/unittest/test_image.py +++ b/tests/python/unittest/test_image.py @@ -84,7 +84,7 @@ def test_imdecode(self): try: import cv2 except ImportError: - return + raise unittest.SkipTest("Unable to import cv2.") for img in TestImage.IMAGES: with open(img, 'rb') as fp: str_image = fp.read() @@ -97,11 +97,12 @@ def test_scale_down(self): assert mx.image.scale_down((360, 1000), (480, 500)) == (360, 375) assert mx.image.scale_down((300, 400), (0, 0)) == (0, 0) + @with_seed() def test_resize_short(self): try: import cv2 except ImportError: - return + raise unittest.SkipTest("Unable to import cv2") for img in TestImage.IMAGES: cv_img = cv2.imread(img) mx_img = mx.nd.array(cv_img[:, :, (2, 1, 0)]) @@ -118,11 +119,12 @@ def test_resize_short(self): mx_resized = mx.image.resize_short(mx_img, new_size, interp) assert_almost_equal(mx_resized.asnumpy()[:, :, (2, 1, 0)], cv_resized, atol=3) + @with_seed() def test_imresize(self): try: import cv2 except ImportError: - return + raise unittest.SkipTest("Unable to import cv2") for img in TestImage.IMAGES: cv_img = cv2.imread(img) mx_img = mx.nd.array(cv_img[:, :, (2, 1, 0)])