BitmapBase

class BitmapBase[source]

Bases: supervisely.geometry.geometry.Geometry

BitmapBase is a base class of Bitmap geometry. BitmapBase class object is immutable.

Parameters
data : np.ndarray

Bitmap mask data.

origin : PointLocation, optional

PointLocation: top, left corner of Bitmap. Position of the Bitmap within image.

expected_data_dims : int, optional

Number of dimensions of data numpy array.

sly_id : int, optional

Bitmap ID in Supervisely server.

class_id : int, optional

ID of ObjClass to which Bitmap belongs.

labeler_login : str, optional

Login of the user who created Bitmap.

updated_at : str, optional

Date and Time when Bitmap was modified last. Date Format: Year:Month:Day:Hour:Minute:Seconds. Example: ‘2021-01-22T19:37:50.158Z’.

created_at : str, optional

Date and Time when Bitmap was created. Date Format is the same as in “updated_at” parameter.

Usage example

Example of creating and using see in Bitmap.

Methods

allowed_transforms

base64_2_data

rtype

ndarray

clone

Clone from GEOMETRYYY

config_from_json

config_to_json

convert

crop

param rect

Rectangle

data_2_base64

rtype

str

draw

param bitmap

np.ndarray

draw_contour

Draws the figure contour on a given bitmap canvas :param bitmap: np.ndarray :param color: [R, G, B] :param thickness: (int) :param config: drawing config specific to a concrete subclass, e.g.

fliplr

Flip current Bitmap in horizontal.

flipud

Flip current Bitmap in vertical.

from_json

Convert a json dict to BitmapBase.

geometry_name

return

string with name of geometry

get_mask

Returns 2D boolean mask of the geometry.

name

Same as geometry_name(), but shorter.

relative_crop

Crops object like "crop" method, but return results with coordinates relative to rect :param rect: :return: list of Geometry

resize

param in_size

(rows, cols)

rotate

Rotates around image center -> New Geometry :param rotator: ImageRotator :return: Geometry

scale

Scale current Bitmap.

to_bbox

Create Rectangle object from current Bitmap.

to_json

Convert the BitmapBase to a json dict.

translate

Translate current Bitmap.

validate

Attributes

area

return

float

data

Get mask data of Bitmap.

origin

Position of the Bitmap within image.

static base64_2_data(s)[source]
Return type

ndarray

clone()

Clone from GEOMETRYYY

crop(rect)
Parameters
rect

Rectangle

Returns

list of Geometry

static data_2_base64(data)[source]
Return type

str

draw(bitmap, color, thickness=1, config=None)
Parameters
bitmap

np.ndarray

color

[R, G, B]

thickness

used only in Polyline and Point

config

drawing config specific to a concrete subclass, e.g. per edge colors

draw_contour(bitmap, color, thickness=1, config=None)

Draws the figure contour on a given bitmap canvas :param bitmap: np.ndarray :param color: [R, G, B] :param thickness: (int) :param config: drawing config specific to a concrete subclass, e.g. per edge colors

fliplr(img_size)[source]

Flip current Bitmap in horizontal.

Parameters
img_size : Tuple[int, int]

Annotation.img_size which belongs Bitmap.

Returns

BitmapBase object

Return type

BitmapBase

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

Flip current Bitmap in vertical.

Parameters
img_size : Tuple[int, int]

Annotation.img_size which belongs Bitmap.

Returns

BitmapBase object

Return type

BitmapBase

Usage Example
# Remember that Bitmap class object is immutable, and we need to assign new instance of Bitmap to a new variable
height, width = 300, 400
flipud_figure = figure.flipud((height, width))
classmethod from_json(json_data)[source]

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

Parameters
data : dict

Bitmap in json format as a dict.

Returns

BitmapBase object

Return type

BitmapBase

Usage example
import supervisely as sly

figure_json = {
    "bitmap": {
        "origin": [1, 1],
        "data": "eJzrDPBz5+WS4mJgYOD19HAJAtLMIMwIInOeqf8BUmwBPiGuQPr///9Lb86/C2QxlgT5BTM4PLuRBuTwebo4hlTMSa44sKHhISMDuxpTYrr03F6gDIOnq5/LOqeEJgDM5ht6"
    },
    "shape": "bitmap",
    "geometryType": "bitmap"
}

figure = sly.Bitmap.from_json(figure_json)
static geometry_name()
Returns

string with name of geometry

get_mask(img_size)

Returns 2D boolean mask of the geometry. With shape as img_size (height, width) and filled with True values inside the geometry and False values outside. dtype = np.bool shape = img_size

Parameters
img_size : Tuple[int, int]

size of the image (height, width)

Returns

2D boolean mask of the geometry

Return type

np.ndarray

classmethod name()

Same as geometry_name(), but shorter. In order to make the code more concise.

Returns

string with name of geometry

relative_crop(rect)

Crops object like “crop” method, but return results with coordinates relative to rect :param rect: :return: list of Geometry

resize(in_size, out_size)
Parameters
in_size

(rows, cols)

out_size

(128, 256) (128, KEEP_ASPECT_RATIO) (KEEP_ASPECT_RATIO, 256)

Returns

Geometry

rotate(rotator)

Rotates around image center -> New Geometry :param rotator: ImageRotator :return: Geometry

scale(factor)[source]

Scale current Bitmap.

Parameters
factor : float

Scale parameter.

Returns

BitmapBase object

Return type

BitmapBase

Usage Example
# Remember that Bitmap class object is immutable, and we need to assign new instance of Bitmap to a new variable
scale_figure = figure.scale(0.75)
to_bbox()[source]

Create Rectangle object from current Bitmap.

Returns

Rectangle object

Return type

Rectangle

Usage Example
rectangle = figure.to_bbox()
to_json()[source]

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

Returns

Json format as a dict

Return type

dict

Usage example
import supervisely as sly

mask = np.array([[0, 0, 0, 0, 0],
                 [0, 1, 1, 1, 0],
                 [0, 1, 0, 1, 0],
                 [0, 1, 1, 1, 0],
                 [0, 0, 0, 0, 0]], dtype=np.bool_)

figure = sly.Bitmap(mask)
figure_json = figure.to_json()
print(json.dumps(figure_json, indent=4))
# Output: {
#    "bitmap": {
#        "origin": [1, 1],
#        "data": "eJzrDPBz5+WS4mJgYOD19HAJAtLMIMwIInOeqf8BUmwBPiGuQPr///9Lb86/C2QxlgT5BTM4PLuRBuTwebo4hlTMSa44sKHhISMDuxpTYrr03F6gDIOnq5/LOqeEJgDM5ht6"
#    },
#    "shape": "bitmap",
#    "geometryType": "bitmap"
# }
translate(drow, dcol)[source]

Translate current Bitmap.

Parameters
drow : int

Horizontal shift.

dcol : int

Vertical shift.

Returns

BitmapBase object

Return type

BitmapBase

Usage Example
# Remember that Bitmap class object is immutable, and we need to assign new instance of Bitmap to a new variable
translate_figure = figure.translate(150, 250)
property area
Returns

float

property data

Get mask data of Bitmap.

Returns

Data of Bitmap.

Return type

np.ndarray

property origin

Position of the Bitmap within image.

Returns

Top, left corner of Bitmap.

Return type

PointLocation