Image

Function Usage

  • Constructs an empty Image object.
  • Converts the ndarray of NumPy on the host to an Image object.

Prototype

1
Image()
1
Image(b: ndarray, format: image_format, imageSizeInfo: Tuple = DEFAULT_IMAGE_SIZE_INFO)

Input Parameters

Parameter

Type

Description

b

ndarray

Constructs the NumPy array of an image. The type of each element is np.uint8 and has three dimensions, indicating the height, width, and number of channels (HWC) of the image.

format

image_format

Image color gamut format. The following color gamut types are supported:

  • base.yuv_400
  • base.rgb
  • base.bgr
  • base.rgba
  • base.bgra
  • base.argb
  • base.abgr

The number of channels (C) in the b (input ndarray) shape must be the same as the color gamut type. The following describes the number of channels corresponding to each color gamut type.

  • yuv_400: 1
  • bgr and rgb: 3
  • rgba, bgra, argb, and abgr: 4

imageSizeInfo

Tuple(Size, Size)

Combination of the valid width/height of the image and the aligned width/height. The valid width/height cannot exceed the aligned width/height. The height and width inputs are as follows:

tuple (valid width/height, aligned width/height)
  • The valid width/height range is [6, 8192].
  • The aligned width/height range is [16, 8192]. The width is a multiple of 16, and the height is a multiple of 2.
  • The height/width in the b (input ndarray) shape must be the same as the valid width/height or aligned width/height.
  • The default value is DEFAULT_IMAGE_SIZE_INFO. The valid width/height and the aligned width/height are both (0, 0). If this parameter is set to the default value, the valid width/height and the aligned width/height are automatically obtained based on the b shape.
  • Read the ndarray for image conversion from OpenCV. If it is in the WHC shape (width, height, number of channels), it needs to be transposed into HWC (height, width, number of channels) before construction.
  • After a tensor obtained by calling get_tensor/to_tensor/get_original_tensor is converted into a ndarray, the shape of the tensor is NHWC (number, height, width, and channel) or NHW (number, height, and width). In this case, transpose the tensor format into HWC before construction.

Response Parameters

Image object