Skip to content

Commit

Permalink
Merge pull request cupy#3559 from pmixer/patch-1
Browse files Browse the repository at this point in the history
add piece of sample code for image resizing
  • Loading branch information
mergify[bot] authored Jul 14, 2020
2 parents 7f24cb5 + 7113cc6 commit 78a83d7
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion docs/source/reference/ndimage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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 <https://docs.opencv.org/master/da/d54/group__imgproc__transform.html#ga0203d9ee5fcd28d40dbc4a1ea4451983>`_ or `cv2.resize <https://docs.opencv.org/master/da/d54/group__imgproc__transform.html#ga47a974309e9102f5f08231edc7e7529d>`_.
If it is given, the function performs like `cv2.warpAffine <https://docs.opencv.org/master/da/d54/group__imgproc__transform.html#ga0203d9ee5fcd28d40dbc4a1ea4451983>`_ or `cv2.resize <https://docs.opencv.org/master/da/d54/group__imgproc__transform.html#ga47a974309e9102f5f08231edc7e7529d>`_. 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

0 comments on commit 78a83d7

Please sign in to comment.