ImageRotator

class ImageRotator(imsize, angle_degrees_ccw)[source]

Bases: object

Rotates images and geometry figures around image center by a given angle.

Create rotator for given image size and angle.

Parameters:
imsize : Tuple[int, int] or List[int, int]

Image shape (height, width).

angle_degrees_ccw : int

Rotation angle in degrees (counter-clockwise).

Usage Example:
rotator = ImageRotator((300, 400), 25)
rotated = rotator.rotate_img(img, use_inter_nearest=True)

Methods

rotate_img

Calculates new parameters of image after rotation.

transform_point

Calculates new parameters of PointLocation after rotation.

rotate_img(img, use_inter_nearest)[source]

Calculates new parameters of image after rotation.

Parameters:
img : np.ndarray

Image to rotate.

use_inter_nearest : bool

If True uses cv2.INTER_NEAREST parameter in rotation, otherwise don’t.

Returns:

Rotated image

Return type:

np.ndarray

Usage Example:
height, width = 300, 400
rotator = ImageRotator((height, width), 25)
mask = np.zeros((height, width, 3), dtype=np.uint8)
rotate_mask = rotator.rotate_img(mask, True)
print(rotate_mask.shape)
# Output: (441, 489, 3)
transform_point(point)[source]

Calculates new parameters of PointLocation after rotation.

Parameters:
point

PointLocation to transform.

Returns:

PointLocation after transformation.

Return type:

PointLocation

Usage Example:
import supervisely as sly

point = sly.PointLocation(100, 200)
height, width = 300, 400
rotator = ImageRotator((height, width), 25)

rotate_point = rotator.transform_point(point)
rotate_point_json = rotate_point.to_json()
print(rotate_point_json)
# Output:
# {
#    "points": {
#        "exterior": [
#            [224, 175]
#        ],
#        "interior": []
#    }
# }