def random_crop(src, size, interp=2):
    'Randomly crop `src` with `size` (width, height).\n    Upsample result if `src` is smaller than `size`.\n\n    Parameters\n    ----------\n    src: Source image `NDArray`\n    size: Size of the crop formatted as (width, height). If the `size` is larger\n           than the image, then the source image is upsampled to `size` and returned.\n    interp: int, optional, default=2\n        Interpolation method. See resize_short for details.\n    Returns\n    -------\n    NDArray\n        An `NDArray` containing the cropped image.\n    Tuple\n        A tuple (x, y, width, height) where (x, y) is top-left position of the crop in the\n        original image and (width, height) are the dimensions of the cropped image.\n\n    Example\n    -------\n    >>> im = mx.nd.array(cv2.imread("flower.jpg"))\n    >>> cropped_im, rect  = mx.image.random_crop(im, (100, 100))\n    >>> print cropped_im\n    <NDArray 100x100x1 @cpu(0)>\n    >>> print rect\n    (20, 21, 100, 100)\n    '
    (h, w, _) = src.shape
    (new_w, new_h) = scale_down((w, h), size)
    x0 = random.randint(0, (w - new_w))
    y0 = random.randint(0, (h - new_h))
    out = fixed_crop(src, x0, y0, new_w, new_h, size, interp)
    return (out, (x0, y0, new_w, new_h))
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)
def random_crop(src, size, interp=2):
    'Randomly crop `src` with `size` (width, height).\n    Upsample result if `src` is smaller than `size`.\n\n    Parameters\n    ----------\n    src: Source image `NDArray`\n    size: Size of the crop formatted as (width, height). If the `size` is larger\n           than the image, then the source image is upsampled to `size` and returned.\n    interp: int, optional, default=2\n        Interpolation method. See resize_short for details.\n    Returns\n    -------\n    NDArray\n        An `NDArray` containing the cropped image.\n    Tuple\n        A tuple (x, y, width, height) where (x, y) is top-left position of the crop in the\n        original image and (width, height) are the dimensions of the cropped image.\n\n    Example\n    -------\n    >>> im = mx.nd.array(cv2.imread("flower.jpg"))\n    >>> cropped_im, rect  = mx.image.random_crop(im, (100, 100))\n    >>> print cropped_im\n    <NDArray 100x100x1 @cpu(0)>\n    >>> print rect\n    (20, 21, 100, 100)\n    '
    (h, w, _) = src.shape
    (new_w, new_h) = scale_down((w, h), size)
    x0 = random.randint(0, (w - new_w))
    y0 = random.randint(0, (h - new_h))
    out = fixed_crop(src, x0, y0, new_w, new_h, size, interp)
    return (out, (x0, y0, new_w, new_h))