PointLocation

class PointLocation(row, col)[source]

Bases: JsonSerializable

2D pixel coordinate (row, col); used for point positions and polygon vertices. Immutable.

PointLocation in (row, col) position. PointLocation object is immutable.

Parameters:
row : int or float

Position of PointLocation on height.

col : int or float

Position of PointLocation on width.

Usage Example:
import supervisely as sly

row = 100
col = 200
loc = sly.PointLocation(row, col)

Methods

clone

Makes a copy of the PointLocation object.

fliplr

Flips current PointLocation object in horizontal.

flipud

Flips current PointLocation object in vertical.

from_json

Convert a json dict to PointLocation.

resize

Resize current PointLocation object.

rotate

Rotates current PointLocation object.

scale

Scale current PointLocation.

scale_frow_fcol

Calculates new parameters of PointLocation after scaling in horizontal and vertical.

to_json

Convert the PointLocation to a json dict.

translate

Translate current PointLocation object.

Attributes

col

Position of PointLocation on width.

row

Position of PointLocation on height.

classmethod from_json(data)[source]

Convert a json dict to PointLocation. Read more about Supervisely format.

Parameters:
data : dict

PointLocation in json format as a dict.

Returns:

PointLocation from json.

Return type:

PointLocation

Usage Example:
import supervisely as sly

loc_json = {
    "points": {
        "exterior": [
            [
                200,
                100
            ]
        ],
        "interior": []
    }
}
loc = sly.PointLocation.from_json(loc_json)
clone()[source]

Makes a copy of the PointLocation object.

Returns:

Copied PointLocation.

Return type:

PointLocation

Usage Example:
# Remember that PointLocation class object is immutable, and we need to assign new instance of PointLocation to a new variable
new_loc = loc.clone()
fliplr(img_size)[source]

Flips current PointLocation object in horizontal.

Parameters:
img_size : Tuple[int, int]

Input image size (height, width) to which belongs PointLocation.

Returns:

Flipped PointLocation.

Return type:

PointLocation

Usage Example:
# Remember that PointLocation class object is immutable, and we need to assign new instance of PointLocation to a new variable
height, width = 300, 400
fliplr_loc = loc.fliplr((height, width))
flipud(img_size)[source]

Flips current PointLocation object in vertical.

Parameters:
img_size : Tuple[int, int]

Input image size (height, width) to which belongs PointLocation.

Returns:

Flipped PointLocation.

Return type:

PointLocation

Usage Example:
# Remember that PointLocation class object is immutable, and we need to assign new instance of PointLocation to a new variable
height, width = 300, 400
flipud_loc = loc.flipud((height, width))
resize(in_size, out_size)[source]

Resize current PointLocation object.

Parameters:
in_size : Tuple[int, int]

Input image size (height, width) to which belongs PointLocation.

out_size : Tuple[int, int]

Desired output image size (height, width) to which belongs PointLocation.

Returns:

Resized PointLocation.

Return type:

PointLocation

Usage Example:
# Remember that PointLocation class object is immutable, and we need to assign new instance of PointLocation to a new variable
in_height, in_width = 300, 400
out_height, out_width = 600, 800
resize_loc = loc.resize((in_height, in_width), (out_height, out_width))
rotate(rotator)[source]

Rotates current PointLocation object.

Parameters:
rotator

Class for object rotation.

Returns:

Rotated PointLocation.

Return type:

PointLocation

Usage Example:
from supervisely.geometry.image_rotator import ImageRotator

# Remember that PointLocation class object is immutable, and we need to assign new instance of PointLocation to a new variable
height, width = 300, 400
rotator = ImageRotator((height, width), 25)
rotate_loc = loc.rotate(rotator)
scale(factor)[source]

Scale current PointLocation.

Parameters:
factor : float

Scale parameter.

Returns:

Scaled PointLocation.

Return type:

PointLocation

Usage Example:
# Remember that PointLocation class object is immutable, and we need to assign new instance of PointLocation to a new variable
scale_loc = loc.scale(0.75)
scale_frow_fcol(frow, fcol)[source]

Calculates new parameters of PointLocation after scaling in horizontal and vertical.

Parameters:
frow : float

Scale parameter for height.

fcol : float

Scale parameter for width.

Returns:

Scaled PointLocation.

Return type:

PointLocation

Usage Example:
# Remember that PointLocation class object is immutable, and we need to assign new instance of PointLocation to a new variable
loc_scale_rc = loc.scale_frow_fcol(0.1, 2.7)
to_json()[source]

Convert the PointLocation to a json dict. Read more about Supervisely format.

Returns:

Json format as a dict

Return type:

dict

Usage Example:
loc_json = loc.to_json()
print(loc_json)
# Output: {
#    "points": {
#        "exterior": [
#            [
#                200,
#                100
#            ]
#        ],
#        "interior": []
#    }
# }
translate(drow, dcol)[source]

Translate current PointLocation object.

Parameters:
drow : int

Horizontal shift.

dcol : int

Vertical shift.

Returns:

Translated PointLocation.

Return type:

PointLocation

Usage Example:
# Remember that PointLocation class object is immutable, and we need to assign new instance of PointLocation to a new variable
translate_loc = loc.translate(150, 350)
property col : int

Position of PointLocation on width.

Returns:

Width of PointLocation.

Return type:

int

Usage Example:
print(loc.col)
# Output: 200
property row : int

Position of PointLocation on height.

Returns:

Height of PointLocation.

Return type:

int

Usage Example:
print(loc.row)
# Output: 100