MultichannelBitmap¶
-
class MultichannelBitmap(data, origin=
None, sly_id=None, class_id=None, labeler_login=None, updated_at=None, created_at=None)[source]¶ Bases:
BitmapBaseBitmap mask with multiple channels (e.g. multi-class segmentation). Immutable.
MultichannelBitmap is a geometry for a single
Label.MultichannelBitmapobject is immutable.- Parameters:
bitmap within the image :type origin:
PointLocation:param sly_id: MultichannelBitmap ID in Supervisely server. :type sly_id: int, optional :param class_id: ID of ObjClass to which MultichannelBitmap belongs. :type class_id: int, optional :param labeler_login: Login of the user who createdMultichannelBitmap. :type labeler_login: str, optional :param updated_at: Date and Time when MultichannelBitmap was modified last. Date Format: Year:Month:Day:Hour:Minute:Seconds. Example: ‘2021-01-22T19:37:50.158Z’. :type updated_at: str, optional :param created_at: Date and Time when MultichannelBitmap was created. Date Format is the same as in “updated_at” parameter. :type created_at: str, optional :raises TypeError: if origin is not aPointLocationobject :raises TypeError: if data is not a bool numpy array :raises ValueError: if data is not a 3-dimensional numpy arrayMethods
Returns the allowed transforms for the Geometry.
The function base64_2_data convert base64 encoded string to numpy
Clone from GEOMETRYYY
Convert geometry config from json format
Convert geometry config to json format
Convert geometry to another geometry shape.
Crops the current MultichannelBitmap object with a given rectangle
he function data_2_base64 convert numpy array to base64 encoded string :param data: numpy array :type data: np.ndarray :returns: string
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.
Flip current Bitmap in horizontal.
Flip current Bitmap in vertical.
Convert a json dict to BitmapBase.
Returns 2D boolean mask of the geometry.
Get the name of the geometry.
Crops object like "crop" method, but return results with coordinates relative to rect :param rect: Rectangle for crop.
Resize the current MultichannelBitmap to match a certain size
Rotates the MultichannelBitmap within the full image canvas and rotate the whole canvas with a given rotator (ImageRotator class object contain size of image and angle to rotate)
Scale current Bitmap.
Create
Rectangleobject from current Bitmap.Convert the BitmapBase to a json dict.
Translate current Bitmap.
Attributes
Returns the area of the current MultichannelBitmap.
Get mask data of Bitmap.
Position of the Bitmap within image.
- classmethod allowed_transforms()¶
Returns the allowed transforms for the Geometry.
- classmethod from_json(json_data)¶
Convert a json dict to BitmapBase. Read more about Supervisely format.
- Parameters:
- Returns:
Bitmap.
- Return type:
- 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)
- classmethod name()¶
Get the name of the geometry.
Same as
geometry_name(), but shorter. In order to make the code more concise.- Returns:
string with name of geometry
- static data_2_base64(data)[source]¶
he function data_2_base64 convert numpy array to base64 encoded string :param data: numpy array :type data: np.ndarray :returns: string
- clone()¶
Clone from GEOMETRYYY
-
convert(new_geometry, contour_radius=
0, approx_epsilon=None)¶ Convert geometry to another geometry shape.
- crop(rect)[source]¶
Crops the current MultichannelBitmap object with a given rectangle
- Parameters:
- rect¶
Rectangle for crop.
- Returns:
Cropped MultichannelBitmap.
- Return type:
-
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)¶
Flip current Bitmap in horizontal.
- Parameters:
- Returns:
Flipped bitmap in horizontal.
- Return type:
- 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)¶
Flip current Bitmap in vertical.
- Parameters:
- Returns:
Flipped bitmap in vertical.
- Return type:
- 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))
- 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
- relative_crop(rect)¶
Crops object like “crop” method, but return results with coordinates relative to rect :param rect: Rectangle for crop. :type rect:
Rectangle:returns: List of Geometry after relative crop. :rtype: List[Geometry]` :raises NotImplementedError: if method is not implemented in subclass
- rotate(rotator)[source]¶
Rotates the MultichannelBitmap within the full image canvas and rotate the whole canvas with a given rotator (ImageRotator class object contain size of image and angle to rotate)
- Parameters:
- rotator¶
Class for image rotation.
- Returns:
Rotated MultichannelBitmap.
- Return type:
- scale(factor)¶
Scale current Bitmap.
- Parameters:
- Returns:
Scaled bitmap.
- Return type:
- 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()¶
Create
Rectangleobject from current Bitmap.- Returns:
Rectangle from bitmap.
- Return type:
- Usage Example:
rectangle = figure.to_bbox()
- to_json()¶
Convert the BitmapBase to a json dict. Read more about Supervisely format.
- Returns:
Json format as a dict
- Return type:
- 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)¶
Translate current Bitmap.
- Parameters:
- Returns:
Translated bitmap.
- Return type:
- 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 the area of the current MultichannelBitmap.
- Returns:
Area of the MultichannelBitmap.
- Return type:
- property data : numpy.ndarray¶
Get mask data of Bitmap.
- Returns:
Data of
Bitmap.- Return type:
np.ndarray
- property origin : supervisely.geometry.point_location.PointLocation¶
Position of the Bitmap within image.
- Returns:
Top, left corner of
Bitmap.- Return type: