Table Of Contents
Table Of Contents

random_crop

mxnet.image.random_crop(src, size, interp=2)[source]

Randomly crop src with size (width, height). Upsample result if src is smaller than size.

Parameters:
  • src (Source image NDArray) –
  • size (Size of the crop formatted as (width, height). If the size is larger) – than the image, then the source image is upsampled to size and returned.
  • interp (int, optional, default=2) – Interpolation method. See resize_short for details.
Returns:

  • NDArray – An NDArray containing the cropped image.
  • Tuple – A tuple (x, y, width, height) where (x, y) is top-left position of the crop in the original image and (width, height) are the dimensions of the cropped image.

Example

>>> im = mx.nd.array(cv2.imread("flower.jpg"))
>>> cropped_im, rect  = mx.image.random_crop(im, (100, 100))
>>> print cropped_im
<NDArray 100x100x1 @cpu(0)>
>>> print rect
(20, 21, 100, 100)