From 7113cc697fe081385705fbdf78318ab2a3c48614 Mon Sep 17 00:00:00 2001 From: pmixer <13297503+pmixer@users.noreply.github.com> Date: Mon, 6 Jul 2020 23:54:26 -0400 Subject: [PATCH] add piece of sample code for image resizing --- docs/source/reference/ndimage.rst | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/docs/source/reference/ndimage.rst b/docs/source/reference/ndimage.rst index a8d98c05d0f..f8be723dec2 100644 --- a/docs/source/reference/ndimage.rst +++ b/docs/source/reference/ndimage.rst @@ -42,4 +42,25 @@ Measurements OpenCV mode ----------- :mod:`cupyx.scipy.ndimage` supports additional mode, ``opencv``. -If it is given, the function performs like `cv2.warpAffine `_ or `cv2.resize `_. +If it is given, the function performs like `cv2.warpAffine `_ or `cv2.resize `_. Example: + + +.. code:: python + + import cupyx.scipy.ndimage + import cupy as cp + import cv2 + + im = cv2.imread('TODO') # pls fill in your image path + + trans_mat = cp.eye(4) + trans_mat[0][0] = trans_mat[1][1] = 0.5 + + smaller_shape = (im.shape[0] // 2, im.shape[1] // 2, 3) + smaller = cp.zeros(smaller_shape) # preallocate memory for resized image + + cupyx.scipy.ndimage.affine_transform(im, trans_mat, output_shape=smaller_shape, + output=smaller, mode='opencv') + + cv2.imwrite('smaller.jpg', cp.asnumpy(smaller)) # smaller image saved locally +