Skip to content
This repository has been archived by the owner on Nov 17, 2023. It is now read-only.

Commit

Permalink
address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Anirudh Acharya committed Oct 19, 2018
1 parent 56075af commit d34d040
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 9 deletions.
29 changes: 23 additions & 6 deletions python/mxnet/image/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
def imread(filename, *args, **kwargs):
"""Read and decode an image to an NDArray.
Note: `imread` uses OpenCV (not the CV2 Python library).
.. note:: `imread` uses OpenCV (not the CV2 Python library).
MXNet must have been built with USE_OPENCV=1 for `imdecode` to work.
Parameters
Expand Down Expand Up @@ -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
----------
Expand All @@ -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.
Expand Down Expand Up @@ -127,7 +144,7 @@ def imresize(src, w, h, interp):
def imdecode(buf, *args, **kwargs):
"""Decode an image to an NDArray.
Note: `imdecode` uses OpenCV (not the CV2 Python library).
.. note:: `imdecode` uses OpenCV (not the CV2 Python library).
MXNet must have been built with USE_OPENCV=1 for `imdecode` to work.
Parameters
Expand Down Expand Up @@ -274,7 +291,7 @@ def _get_interp_method(interp, sizes=()):
def resize_short(src, size, interp=2):
"""Resizes shorter edge to size.
Note: `resize_short` uses OpenCV (not the CV2 Python library).
.. note:: `resize_short` uses OpenCV (not the CV2 Python library).
MXNet must have been built with OpenCV for `resize_short` to work.
Resizes the original image by setting the shorter edge to size
Expand Down
8 changes: 5 additions & 3 deletions tests/python/unittest/test_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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)])
Expand All @@ -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)])
Expand Down

0 comments on commit d34d040

Please sign in to comment.