image_transform
Composable transforms for image arrays and pixel coordinates.
The transforms support two-dimensional grayscale images and channel-last color
images. Each transform can be applied both to image data and to corresponding
(x, y) coordinates.
- robotblockset.cameras.image_transform.ImageArrayType
Grayscale
(H, W)or channel-last color(H, W, C)image array.
- robotblockset.cameras.image_transform.HWCImageType
Compatibility alias for
ImageArrayType.
- class robotblockset.cameras.image_transform.ImageTransform(input_shape: Tuple[int, int] | Tuple[int, int, int])[source]
Bases:
ABCBase interface for related image and point-coordinate transforms.
Initialize a transform for images with a known input shape.
- Parameters:
input_shape (ImageShapeType) – Grayscale
(height, width)or color(height, width, channels)input shape.
- __init__(input_shape: Tuple[int, int] | Tuple[int, int, int]) None[source]
Initialize a transform for images with a known input shape.
- Parameters:
input_shape (ImageShapeType) – Grayscale
(height, width)or color(height, width, channels)input shape.
- property shape: Tuple[int, int] | Tuple[int, int, int]
Return the shape of the transformed image.
- Returns:
Grayscale or channel-last output shape.
- Return type:
ImageShapeType
- Raises:
NotImplementedError – If a subclass does not implement the property.
- transform_image(image: ndarray) ndarray[source]
Apply the transform to an image array.
- Parameters:
image (ImageArrayType) – Source image. Implementations return a transformed image without intentionally modifying this array.
- Returns:
Transformed image array.
- Return type:
ImageArrayType
- Raises:
NotImplementedError – If a subclass does not implement the method.
- transform_point(point: Tuple[int | float, int | float]) Tuple[int | float, int | float][source]
Map a source-image point into transformed-image coordinates.
- Parameters:
point (ImagePointType) – Source
(x, y)coordinate.- Returns:
Coordinate in the transformed image.
- Return type:
ImagePointType
- Raises:
NotImplementedError – If a subclass does not implement the method.
- reverse_transform_point(point: Tuple[int | float, int | float]) Tuple[int | float, int | float][source]
Map a transformed-image point back to source-image coordinates.
- Parameters:
point (ImagePointType) – Transformed
(x, y)coordinate.- Returns:
Coordinate in the source image.
- Return type:
ImagePointType
- Raises:
NotImplementedError – If a subclass does not implement the method.
- class robotblockset.cameras.image_transform.ComposedTransform(transforms: Sequence[ImageTransform])[source]
Bases:
ImageTransformApply a non-empty sequence of image transforms in order.
Create a transform composition.
- Parameters:
transforms (Sequence[ImageTransform]) – Ordered, non-empty sequence of transforms.
- Raises:
ValueError – If
transformsis empty.
- __init__(transforms: Sequence[ImageTransform]) None[source]
Create a transform composition.
- Parameters:
transforms (Sequence[ImageTransform]) – Ordered, non-empty sequence of transforms.
- Raises:
ValueError – If
transformsis empty.
- property shape: Tuple[int, int] | Tuple[int, int, int]
Return the output shape of the final transform.
- robotblockset.cameras.image_transform.crop(image: ndarray, x: int, y: int, w: int, h: int) ndarray[source]
Return a copy of a rectangular image region.
- Parameters:
image (ImageArrayType) – Grayscale or channel-last source image.
x (int) – X-coordinate of the top-left crop corner.
y (int) – Y-coordinate of the top-left crop corner.
w (int) – Crop width in pixels.
h (int) – Crop height in pixels.
- Returns:
Copy of the selected region. Coordinates outside the image follow NumPy slicing semantics.
- Return type:
ImageArrayType
- class robotblockset.cameras.image_transform.Crop(input_shape: Tuple[int, int] | Tuple[int, int, int], x: int, y: int, w: int, h: int)[source]
Bases:
ImageTransformCrop an image and translate corresponding point coordinates.
Create a rectangular crop transform.
- Parameters:
input_shape (ImageShapeType) – Shape of the source image.
x (int) – X-coordinate of the crop’s top-left corner.
y (int) – Y-coordinate of the crop’s top-left corner.
w (int) – Crop width in pixels.
h (int) – Crop height in pixels.
- __init__(input_shape: Tuple[int, int] | Tuple[int, int, int], x: int, y: int, w: int, h: int) None[source]
Create a rectangular crop transform.
- Parameters:
input_shape (ImageShapeType) – Shape of the source image.
x (int) – X-coordinate of the crop’s top-left corner.
y (int) – Y-coordinate of the crop’s top-left corner.
w (int) – Crop width in pixels.
h (int) – Crop height in pixels.
- property shape: Tuple[int, int] | Tuple[int, int, int]
Return the declared crop shape.
- class robotblockset.cameras.image_transform.Resize(input_shape: Tuple[int, int] | Tuple[int, int, int], h: int, w: int, round_transformed_points: bool = True)[source]
Bases:
ImageTransformResize an image and scale corresponding point coordinates.
Create an image resize transform.
Transforming points to or from a resized image can produce fractional coordinates. By default these coordinates are rounded to the nearest integer. Set
round_transformed_pointstoFalseto preserve the floating-point result.- Parameters:
input_shape (ImageShapeType) – Shape of the source image.
h (int) – Output height in pixels.
w (int) – Output width in pixels.
round_transformed_points (bool, optional) – Whether point transformations return rounded coordinates. The default is
True.
- __init__(input_shape: Tuple[int, int] | Tuple[int, int, int], h: int, w: int, round_transformed_points: bool = True) None[source]
Create an image resize transform.
Transforming points to or from a resized image can produce fractional coordinates. By default these coordinates are rounded to the nearest integer. Set
round_transformed_pointstoFalseto preserve the floating-point result.- Parameters:
input_shape (ImageShapeType) – Shape of the source image.
h (int) – Output height in pixels.
w (int) – Output width in pixels.
round_transformed_points (bool, optional) – Whether point transformations return rounded coordinates. The default is
True.
- property shape: Tuple[int, int] | Tuple[int, int, int]
Return the resized image shape.
- transform_image(image: ndarray) ndarray[source]
Resize an image using OpenCV’s default interpolation.
- class robotblockset.cameras.image_transform.Rotate90(input_shape: Tuple[int, int] | Tuple[int, int, int], num_rotations: int = 1)[source]
Bases:
ImageTransformRotate images and corresponding points by multiples of 90 degrees.
Create a counter-clockwise right-angle rotation transform.
- Parameters:
input_shape (ImageShapeType) – Shape of the source image.
num_rotations (int, optional) – Number of counter-clockwise 90-degree rotations. Values are reduced modulo four. The default is
1.
- Raises:
TypeError – If
num_rotationsis not an integer.
- __init__(input_shape: Tuple[int, int] | Tuple[int, int, int], num_rotations: int = 1) None[source]
Create a counter-clockwise right-angle rotation transform.
- Parameters:
input_shape (ImageShapeType) – Shape of the source image.
num_rotations (int, optional) – Number of counter-clockwise 90-degree rotations. Values are reduced modulo four. The default is
1.
- Raises:
TypeError – If
num_rotationsis not an integer.
- property shape: Tuple[int, int] | Tuple[int, int, int]
Return the rotated image shape.
- transform_image(image: ndarray) ndarray[source]
Return a copied array rotated counter-clockwise by 90-degree steps.
Attributes
Grayscale |
|
Compatibility alias for |
Functions
|
Return a copy of a rectangular image region. |
Classes
|
Apply a non-empty sequence of image transforms in order. |
|
Crop an image and translate corresponding point coordinates. |
|
Base interface for related image and point-coordinate transforms. |
|
Resize an image and scale corresponding point coordinates. |
|
Rotate images and corresponding points by multiples of 90 degrees. |