image_transform
Image transform abstractions and helpers.
- robotblockset.cameras.image_transform.HWCImageType
an image with shape (H,W,C)
- class robotblockset.cameras.image_transform.ImageTransform(input_shape: Tuple[int, int, int] | Tuple[int, int])[source]
Bases:
ABC- property shape: Tuple[int, int, int] | Tuple[int, int]
The shape of the transformed image.
- Returns:
ImageShapeType
- Return type:
The shape of the transformed image.
- transform_image(image: ndarray) ndarray[source]
Apply the image transform to an image to get a new image.
- Parameters:
image (HWCImageType) – The original image, it will be unaffected by the transform.
- Raises:
NotImplementedError – Subclasses must implement this method.:
- Returns:
HWCImageType
- Return type:
The new, transformed image.
- class robotblockset.cameras.image_transform.ComposedTransform(transforms: List[ImageTransform])[source]
Bases:
ImageTransform- property shape: Tuple[int, int, int] | Tuple[int, int]
The shape of the transformed image.
- Returns:
ImageShapeType
- Return type:
The shape of the transformed image.
- transform_image(image: ndarray) ndarray[source]
Apply the image transform to an image to get a new image.
- Parameters:
image (HWCImageType) – The original image, it will be unaffected by the transform.
- Raises:
NotImplementedError – Subclasses must implement this method.:
- Returns:
HWCImageType
- Return type:
The new, transformed image.
- robotblockset.cameras.image_transform.crop(image: ndarray, x: int, y: int, w: int, h: int) ndarray[source]
Crop a rectangular region from an image.
- Parameters:
image (HWCImageType) – Image to crop.
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.
- class robotblockset.cameras.image_transform.Crop(input_shape: Tuple[int, int, int] | Tuple[int, int], x: int, y: int, w: int, h: int)[source]
Bases:
ImageTransform- property shape: Tuple[int, int, int] | Tuple[int, int]
The shape of the transformed image.
- Returns:
ImageShapeType
- Return type:
The shape of the transformed image.
- transform_image(image: ndarray) ndarray[source]
Apply the image transform to an image to get a new image.
- Parameters:
image (HWCImageType) – The original image, it will be unaffected by the transform.
- Raises:
NotImplementedError – Subclasses must implement this method.:
- Returns:
HWCImageType
- Return type:
The new, transformed image.
- class robotblockset.cameras.image_transform.Resize(input_shape: Tuple[int, int, int] | Tuple[int, int], h: int, w: int, round_transformed_points: bool = True)[source]
Bases:
ImageTransformCreate a new Resize transform.
- Note: Transforming a point to or from a resized image can lead to non-integer coordinates. Pixel coordinates
are however often expected to be integers, e.g. by the OpenCV draw functions. So by default, this class will round transformed points to the nearest integer. If you want to avoid the errors introduced by rounding, you can set round_transformed_points to False to get the exact transformed points as floats.
- Parameters:
input_shape (ImageShapeType) – Shape of the images that will be resized.
h (int) – Height of the resized image.
w (int) – Width of the resized image.
round_transformed_points (bool, optional) – Whether to round transformed points to the nearest integer.
- __init__(input_shape: Tuple[int, int, int] | Tuple[int, int], h: int, w: int, round_transformed_points: bool = True)[source]
Create a new Resize transform.
- Note: Transforming a point to or from a resized image can lead to non-integer coordinates. Pixel coordinates
are however often expected to be integers, e.g. by the OpenCV draw functions. So by default, this class will round transformed points to the nearest integer. If you want to avoid the errors introduced by rounding, you can set round_transformed_points to False to get the exact transformed points as floats.
- Parameters:
input_shape (ImageShapeType) – Shape of the images that will be resized.
h (int) – Height of the resized image.
w (int) – Width of the resized image.
round_transformed_points (bool, optional) – Whether to round transformed points to the nearest integer.
- property shape: Tuple[int, int, int] | Tuple[int, int]
The shape of the transformed image.
- Returns:
ImageShapeType
- Return type:
The shape of the transformed image.
- transform_image(image: ndarray) ndarray[source]
Apply the image transform to an image to get a new image.
- Parameters:
image (HWCImageType) – The original image, it will be unaffected by the transform.
- Raises:
NotImplementedError – Subclasses must implement this method.:
- Returns:
HWCImageType
- Return type:
The new, transformed image.
- class robotblockset.cameras.image_transform.Rotate90(input_shape: Tuple[int, int, int] | Tuple[int, int], num_rotations: int = 1)[source]
Bases:
ImageTransformRotate an image by multiples of 90 degrees.
Create a new Rotate transform.
- Parameters:
num_rotations (int, optional) – the number of 90-degree rotations to apply. Positive values rotate counter-clockwise.
- __init__(input_shape: Tuple[int, int, int] | Tuple[int, int], num_rotations: int = 1)[source]
Create a new Rotate transform.
- Parameters:
num_rotations (int, optional) – the number of 90-degree rotations to apply. Positive values rotate counter-clockwise.
- property shape: Tuple[int, int, int] | Tuple[int, int]
The shape of the transformed image.
- Returns:
ImageShapeType
- Return type:
The shape of the transformed image.
- transform_image(image: ndarray) ndarray[source]
Apply the image transform to an image to get a new image.
- Parameters:
image (HWCImageType) – The original image, it will be unaffected by the transform.
- Raises:
NotImplementedError – Subclasses must implement this method.:
- Returns:
HWCImageType
- Return type:
The new, transformed image.
Attributes
an image with shape (H,W,C) |
Functions
|
Crop a rectangular region from an image. |
Classes
|
|
|
|
|
|
|
Create a new Resize transform. |
|
Rotate an image by multiples of 90 degrees. |