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:L195

flip_top_bottom([data, out, name])

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

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:L215

random_color_jitter([data, brightness, …])

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

random_contrast([data, min_factor, …])

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

random_flip_left_right([data, out, name])

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

random_flip_top_bottom([data, out, name])

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

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

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

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

Randomly add PCA noise.

random_saturation([data, min_factor, …])

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

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:L254

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:L65

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:L195

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:L205

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:L167

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:L215

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:L246

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:L222

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_flip_left_right(data=None, out=None, name=None, **kwargs)

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

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.random_flip_top_bottom(data=None, out=None, name=None, **kwargs)

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

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.random_hue(data=None, min_factor=_Null, max_factor=_Null, out=None, name=None, **kwargs)

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

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:L262

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_saturation(data=None, min_factor=_Null, max_factor=_Null, out=None, name=None, **kwargs)

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

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:L70

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:L92

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