ndarray.image

Image NDArray API of MXNet.

Functions

adjust_lighting([data, alpha, out, name])

Adjust the lighting level of the input.

crop([data, x, y, width, height, out, name])

Crop an image NDArray of shape (H x W x C) or (N x H x W x C) to the given size.

flip_left_right([data, out, name])

Defined in src/operator/image/image_random.cc:L196

flip_top_bottom([data, out, name])

Defined in src/operator/image/image_random.cc:L208

normalize([data, mean, std, out, name])

Normalize an tensor of shape (C x H x W) or (N x C x H x W) with mean and standard deviation.

random_brightness([data, min_factor, …])

Defined in src/operator/image/image_random.cc:L220

random_color_jitter([data, brightness, …])

Defined in src/operator/image/image_random.cc:L251

random_contrast([data, min_factor, …])

Defined in src/operator/image/image_random.cc:L227

random_crop([data, xrange, yrange, width, …])

Randomly crop an image NDArray of shape (H x W x C) or (N x H x W x C) to the given size.

random_flip_left_right([data, p, out, name])

Defined in src/operator/image/image_random.cc:L202

random_flip_top_bottom([data, p, out, name])

Defined in src/operator/image/image_random.cc:L214

random_hue([data, min_factor, max_factor, …])

Defined in src/operator/image/image_random.cc:L243

random_lighting([data, alpha_std, out, name])

Randomly add PCA noise.

random_resized_crop([data, xrange, yrange, …])

Randomly crop an image NDArray of shape (H x W x C) or (N x H x W x C) to the given size.

random_saturation([data, min_factor, …])

Defined in src/operator/image/image_random.cc:L235

resize([data, size, keep_ratio, interp, …])

Resize an image NDArray of shape (H x W x C) or (N x H x W x C) to the given size ..

to_tensor([data, out, name])

Converts an image NDArray of shape (H x W x C) or (N x H x W x C)

mxnet.ndarray.image.adjust_lighting(data=None, alpha=_Null, out=None, name=None, **kwargs)

Adjust the lighting level of the input. Follow the AlexNet style.

Defined in src/operator/image/image_random.cc:L259

Parameters
  • data (NDArray) – The input.

  • alpha (tuple of <float>, required) – The lighting alphas for the R, G, B channels.

  • out (NDArray, optional) – The output NDArray to hold the result.

Returns

out – The output of this function.

Return type

NDArray or list of NDArrays

mxnet.ndarray.image.crop(data=None, x=_Null, y=_Null, width=_Null, height=_Null, out=None, name=None, **kwargs)

Crop an image NDArray of shape (H x W x C) or (N x H x W x C) to the given size. .. rubric:: Example

Defined in src/operator/image/crop.cc:L68

Parameters
  • data (NDArray) – The input.

  • x (int, required) – Left boundary of the cropping area.

  • y (int, required) – Top boundary of the cropping area.

  • width (int, required) – Width of the cropping area.

  • height (int, required) – Height of the cropping area.

  • out (NDArray, optional) – The output NDArray to hold the result.

Returns

out – The output of this function.

Return type

NDArray or list of NDArrays

mxnet.ndarray.image.flip_left_right(data=None, out=None, name=None, **kwargs)

Defined in src/operator/image/image_random.cc:L196

Parameters
  • data (NDArray) – The input.

  • out (NDArray, optional) – The output NDArray to hold the result.

Returns

out – The output of this function.

Return type

NDArray or list of NDArrays

mxnet.ndarray.image.flip_top_bottom(data=None, out=None, name=None, **kwargs)

Defined in src/operator/image/image_random.cc:L208

Parameters
  • data (NDArray) – The input.

  • out (NDArray, optional) – The output NDArray to hold the result.

Returns

out – The output of this function.

Return type

NDArray or list of NDArrays

mxnet.ndarray.image.normalize(data=None, mean=_Null, std=_Null, out=None, name=None, **kwargs)
Normalize an tensor of shape (C x H x W) or (N x C x H x W) with mean and

standard deviation.

Given mean (m1, …, mn) and std (s:sub:`1, …, sn)` for n channels, this transform normalizes each channel of the input tensor with:

\[ \begin{align}\begin{aligned} output[i] = (input[i] - m\ :sub:`i`\ ) / s\ :sub:`i`\\If mean or std is scalar, the same value will be applied to all channels.\\Default value for mean is 0.0 and stand deviation is 1.0.\end{aligned}\end{align} \]

Example

Defined in src/operator/image/image_random.cc:L168

Parameters
  • data (NDArray) – Input ndarray

  • mean (tuple of <float>, optional, default=[0,0,0,0]) – Sequence of means for each channel. Default value is 0.

  • std (tuple of <float>, optional, default=[1,1,1,1]) – Sequence of standard deviations for each channel. Default value is 1.

  • out (NDArray, optional) – The output NDArray to hold the result.

Returns

out – The output of this function.

Return type

NDArray or list of NDArrays

mxnet.ndarray.image.random_brightness(data=None, min_factor=_Null, max_factor=_Null, out=None, name=None, **kwargs)

Defined in src/operator/image/image_random.cc:L220

Parameters
  • data (NDArray) – The input.

  • min_factor (float, required) – Minimum factor.

  • max_factor (float, required) – Maximum factor.

  • out (NDArray, optional) – The output NDArray to hold the result.

Returns

out – The output of this function.

Return type

NDArray or list of NDArrays

mxnet.ndarray.image.random_color_jitter(data=None, brightness=_Null, contrast=_Null, saturation=_Null, hue=_Null, out=None, name=None, **kwargs)

Defined in src/operator/image/image_random.cc:L251

Parameters
  • data (NDArray) – The input.

  • brightness (float, required) – How much to jitter brightness.

  • contrast (float, required) – How much to jitter contrast.

  • saturation (float, required) – How much to jitter saturation.

  • hue (float, required) – How much to jitter hue.

  • out (NDArray, optional) – The output NDArray to hold the result.

Returns

out – The output of this function.

Return type

NDArray or list of NDArrays

mxnet.ndarray.image.random_contrast(data=None, min_factor=_Null, max_factor=_Null, out=None, name=None, **kwargs)

Defined in src/operator/image/image_random.cc:L227

Parameters
  • data (NDArray) – The input.

  • min_factor (float, required) – Minimum factor.

  • max_factor (float, required) – Maximum factor.

  • out (NDArray, optional) – The output NDArray to hold the result.

Returns

out – The output of this function.

Return type

NDArray or list of NDArrays

mxnet.ndarray.image.random_crop(data=None, xrange=_Null, yrange=_Null, width=_Null, height=_Null, interp=_Null, out=None, name=None, **kwargs)

Randomly crop an image NDArray of shape (H x W x C) or (N x H x W x C) to the given size. Upsample result if src is smaller than size. .. rubric:: Example

Defined in src/operator/image/crop.cc:L96

Parameters
  • data (NDArray) – The input.

  • xrange (tuple of <float>, optional, default=[0,1]) – Left boundaries of the cropping area.

  • yrange (tuple of <float>, optional, default=[0,1]) – Top boundaries of the cropping area.

  • width (int, required) – The target image width

  • height (int, required) – The target image height.

  • interp (int, optional, default='1') – Interpolation method for resizing. By default uses bilinear interpolationOptions are INTER_NEAREST - a nearest-neighbor interpolationINTER_LINEAR - a bilinear interpolationINTER_AREA - resampling using pixel area relationINTER_CUBIC - a bicubic interpolation over 4x4 pixel neighborhoodINTER_LANCZOS4 - a Lanczos interpolation over 8x8 pixel neighborhoodNote that the GPU version only support bilinear interpolation(1)

  • out (NDArray, optional) – The output NDArray to hold the result.

Returns

out – The output of this function.

Return type

NDArray or list of NDArrays

mxnet.ndarray.image.random_flip_left_right(data=None, p=_Null, out=None, name=None, **kwargs)

Defined in src/operator/image/image_random.cc:L202

Parameters
  • data (NDArray) – The input.

  • p (float, optional, default=0.5) – The probablity of flipping the image.

  • out (NDArray, optional) – The output NDArray to hold the result.

Returns

out – The output of this function.

Return type

NDArray or list of NDArrays

mxnet.ndarray.image.random_flip_top_bottom(data=None, p=_Null, out=None, name=None, **kwargs)

Defined in src/operator/image/image_random.cc:L214

Parameters
  • data (NDArray) – The input.

  • p (float, optional, default=0.5) – The probablity of flipping the image.

  • out (NDArray, optional) – The output NDArray to hold the result.

Returns

out – The output of this function.

Return type

NDArray or list of NDArrays

mxnet.ndarray.image.random_hue(data=None, min_factor=_Null, max_factor=_Null, out=None, name=None, **kwargs)

Defined in src/operator/image/image_random.cc:L243

Parameters
  • data (NDArray) – The input.

  • min_factor (float, required) – Minimum factor.

  • max_factor (float, required) – Maximum factor.

  • out (NDArray, optional) – The output NDArray to hold the result.

Returns

out – The output of this function.

Return type

NDArray or list of NDArrays

mxnet.ndarray.image.random_lighting(data=None, alpha_std=_Null, out=None, name=None, **kwargs)

Randomly add PCA noise. Follow the AlexNet style.

Defined in src/operator/image/image_random.cc:L267

Parameters
  • data (NDArray) – The input.

  • alpha_std (float, optional, default=0.0500000007) – Level of the lighting noise.

  • out (NDArray, optional) – The output NDArray to hold the result.

Returns

out – The output of this function.

Return type

NDArray or list of NDArrays

mxnet.ndarray.image.random_resized_crop(data=None, xrange=_Null, yrange=_Null, width=_Null, height=_Null, interp=_Null, out=None, name=None, **kwargs)

Randomly crop an image NDArray of shape (H x W x C) or (N x H x W x C) to the given size. Randomize area and aspect ratio. Upsample result if src is smaller than size. .. rubric:: Example

Defined in src/operator/image/crop.cc:L131

Parameters
  • data (NDArray) – The input.

  • xrange (tuple of <float>, optional, default=[0,1]) – Left boundaries of the cropping area.

  • yrange (tuple of <float>, optional, default=[0,1]) – Top boundaries of the cropping area.

  • width (int, required) – The target image width

  • height (int, required) – The target image height.

  • interp (int, optional, default='1') – Interpolation method for resizing. By default uses bilinear interpolationOptions are INTER_NEAREST - a nearest-neighbor interpolationINTER_LINEAR - a bilinear interpolationINTER_AREA - resampling using pixel area relationINTER_CUBIC - a bicubic interpolation over 4x4 pixel neighborhoodINTER_LANCZOS4 - a Lanczos interpolation over 8x8 pixel neighborhoodNote that the GPU version only support bilinear interpolation(1)

  • out (NDArray, optional) – The output NDArray to hold the result.

Returns

out – The output of this function.

Return type

NDArray or list of NDArrays

mxnet.ndarray.image.random_saturation(data=None, min_factor=_Null, max_factor=_Null, out=None, name=None, **kwargs)

Defined in src/operator/image/image_random.cc:L235

Parameters
  • data (NDArray) – The input.

  • min_factor (float, required) – Minimum factor.

  • max_factor (float, required) – Maximum factor.

  • out (NDArray, optional) – The output NDArray to hold the result.

Returns

out – The output of this function.

Return type

NDArray or list of NDArrays

mxnet.ndarray.image.resize(data=None, size=_Null, keep_ratio=_Null, interp=_Null, out=None, name=None, **kwargs)

Resize an image NDArray of shape (H x W x C) or (N x H x W x C) to the given size .. rubric:: Example

Defined in src/operator/image/resize.cc:L71

Parameters
  • data (NDArray) – The input.

  • size (Shape(tuple), optional, default=[]) – Size of new image. Could be (width, height) or (size)

  • keep_ratio (boolean, optional, default=0) – Whether to resize the short edge or both edges to size, if size is give as an integer.

  • interp (int, optional, default='1') – Interpolation method for resizing. By default uses bilinear interpolationOptions are INTER_NEAREST - a nearest-neighbor interpolationINTER_LINEAR - a bilinear interpolationINTER_AREA - resampling using pixel area relationINTER_CUBIC - a bicubic interpolation over 4x4 pixel neighborhoodINTER_LANCZOS4 - a Lanczos interpolation over 8x8 pixel neighborhoodNote that the GPU version only support bilinear interpolation(1)

  • out (NDArray, optional) – The output NDArray to hold the result.

Returns

out – The output of this function.

Return type

NDArray or list of NDArrays

mxnet.ndarray.image.to_tensor(data=None, out=None, name=None, **kwargs)

Converts an image NDArray of shape (H x W x C) or (N x H x W x C) with values in the range [0, 255] to a tensor NDArray of shape (C x H x W) or (N x C x H x W) with values in the range [0, 1]

Example

Defined in src/operator/image/image_random.cc:L93

Parameters
  • data (NDArray) – Input ndarray

  • out (NDArray, optional) – The output NDArray to hold the result.

Returns

out – The output of this function.

Return type

NDArray or list of NDArrays