ImageRotator

class ImageRotator[source]

Bases: object

ImageRotator for rotating images and geometry figures.

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

Shape of the image (height, width)

angle_degrees_ccw : int

Angle to rotate image.

Usage example
height, width = 300, 400
rotator = ImageRotator((height, width), 25)

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

PointLocation object.

Returns

PointLocation object

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": []
#    }
# }