image_converter

Validate and convert three-channel RGB and BGR image arrays.

The canonical representation is a channel-last RGB NumPy array with floating values in the range [0.0, 1.0]. Conversion helpers also support channel-last integer RGB arrays, channel-last integer BGR arrays used by OpenCV, and channel-first floating NumPy arrays used by tensor-oriented workflows.

robotblockset.cameras.image_converter.is_image_array(image: object) TypeGuard[ndarray][source]

Return whether an object is a three-dimensional NumPy array.

This shape check does not validate channel placement, channel count, data type, or value range.

Parameters:

image (object) – Object to inspect.

Returns:

True when image is a NumPy array with three dimensions.

Return type:

TypeGuard[numpy.ndarray]

robotblockset.cameras.image_converter.is_float_image_array(image: object) TypeGuard[ndarray][source]

Return whether an object looks like a floating-point image array.

The object must be a non-empty, three-dimensional NumPy array with dtype float16, float32, or float64. Every value must be finite and in the expected [0.0, 1.0] range. Channel placement and channel count are not checked here.

Parameters:

image (object) – Object to inspect.

Returns:

True when the structural, dtype, finiteness, and range checks pass.

Return type:

TypeGuard[NumpyFloatImageType]

robotblockset.cameras.image_converter.is_int_image_array(image: object) TypeGuard[ndarray][source]

Return whether an object looks like an unsigned-integer image array.

The object must be a non-empty, three-dimensional NumPy array with dtype uint8, uint16, or uint32. Every value must be in the expected [0, 255] range. Channel placement and channel count are not checked here.

Parameters:

image (object) – Object to inspect.

Returns:

True when the structural, dtype, and range checks pass.

Return type:

TypeGuard[NumpyIntImageType]

class robotblockset.cameras.image_converter.ImageConverter(image_in_numpy_float_format: ndarray)[source]

Bases: object

Convert between supported three-channel NumPy image layouts.

The internal representation is channel-last RGB floating-point data in the range [0.0, 1.0]. Despite the torch method names, tensor-oriented inputs and outputs are channel-first NumPy arrays; torch.Tensor objects and CUDA-resident data are not supported.

Conversions use the internal floating-point representation as an intermediate format, favoring a small implementation over the fastest possible direct conversion between every pair of formats.

Initialize the converter from channel-last floating RGB data.

Parameters:

image_in_numpy_float_format (NumpyFloatImageType) – RGB image with shape (height, width, 3) and floating values in the expected [0.0, 1.0] range.

Raises:
  • TypeError – If the input is not recognized as a floating-point image array.

  • IndexError – If the last dimension does not contain exactly three channels.

Notes

The converter stores a copy of the input array.

__init__(image_in_numpy_float_format: ndarray) None[source]

Initialize the converter from channel-last floating RGB data.

Parameters:

image_in_numpy_float_format (NumpyFloatImageType) – RGB image with shape (height, width, 3) and floating values in the expected [0.0, 1.0] range.

Raises:
  • TypeError – If the input is not recognized as a floating-point image array.

  • IndexError – If the last dimension does not contain exactly three channels.

Notes

The converter stores a copy of the input array.

classmethod from_numpy_format(image: ndarray) ImageConverter[source]

Create a converter from a channel-last floating RGB image.

Parameters:

image (NumpyFloatImageType) – RGB image with shape (height, width, 3).

Returns:

Converter containing a copy of image.

Return type:

ImageConverter

Raises:
  • TypeError – If image is not recognized as a floating-point image array.

  • IndexError – If the last dimension does not contain exactly three channels.

classmethod from_numpy_int_format(image: ndarray) ImageConverter[source]

Create a converter from a channel-last integer RGB image.

Parameters:

image (NumpyIntImageType) – RGB image with shape (height, width, 3) and values expressed on the [0, 255] scale.

Returns:

Converter containing a floating-point copy of image.

Return type:

ImageConverter

Raises:
  • TypeError – If image is not recognized as an unsigned-integer image array.

  • IndexError – If the last dimension does not contain exactly three channels.

classmethod from_opencv_format(image: ndarray) ImageConverter[source]

Create a converter from a channel-last integer BGR image.

Parameters:

image (OpenCVIntImageType) – OpenCV-style BGR image with shape (height, width, 3) and values expressed on the [0, 255] scale.

Returns:

Converter containing a floating-point RGB copy of image.

Return type:

ImageConverter

Raises:
  • TypeError – If image is not recognized as an unsigned-integer image array.

  • IndexError – If the last dimension does not contain exactly three channels.

classmethod from_torch_format(image: ndarray) ImageConverter[source]

Create a converter from channel-first floating RGB data.

Parameters:

image (TorchFloatImageType) – Channel-first NumPy array with shape (3, height, width). This method does not accept a torch.Tensor.

Returns:

Converter containing a channel-last copy of image.

Return type:

ImageConverter

Raises:
  • TypeError – If image is not recognized as a floating-point image array.

  • IndexError – If the first dimension does not contain exactly three channels.

property image_in_numpy_format: ndarray

Return a copy of the channel-last floating RGB image.

property image_in_opencv_format: ndarray

Return the image as a channel-last uint8 BGR array.

property image_in_torch_format: ndarray

Return a channel-first copy of the floating RGB image.

property image_in_numpy_int_format: ndarray

Return the image as a channel-last uint8 RGB array.

Functions

is_float_image_array(image)

Return whether an object looks like a floating-point image array.

is_image_array(image)

Return whether an object is a three-dimensional NumPy array.

is_int_image_array(image)

Return whether an object looks like an unsigned-integer image array.

Classes

ImageConverter(image_in_numpy_float_format)

Convert between supported three-channel NumPy image layouts.