BitmapBase¶
-
class BitmapBase(data, origin=
None, expected_data_dims=None, sly_id=None, class_id=None, labeler_login=None, updated_at=None, created_at=None)[source]¶ Bases:
GeometryBase class for bitmap-like geometries (Bitmap, AlphaMask, MultichannelBitmap); mask + origin. Immutable.
BitmapBase is a base class of
Bitmapgeometry.BitmapBaseclass object is immutable.Example of creating and using see in
Bitmap.- Parameters:
- data : np.ndarray¶
Bitmap mask data.
- origin=
None¶ 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.
Methods
Returns the allowed transforms for the Geometry.
base64_2_dataClone from GEOMETRYYY
Convert geometry config from json format
Convert geometry config to json format
Convert geometry to another geometry shape.
Crop the geometry with given rectangle.
data_2_base64Draws 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.
Get the name of the geometry.
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.
Rotates around image center -> New Geometry :param rotator: Class for image rotation.
Scale current Bitmap.
Create
Rectangleobject from current Bitmap.Convert the BitmapBase to a json dict.
Translate current Bitmap.
Validate geometry.
Attributes
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)[source]¶
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 geometry_name()¶
Get the name of the geometry.
- Returns:
name of the geometry
- Return type:
- Returns:
string with name of geometry
- clone()¶
Clone from GEOMETRYYY
-
convert(new_geometry, contour_radius=
0, approx_epsilon=None)¶ Convert geometry to another geometry shape.
-
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:
- 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)[source]¶
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
- resize(in_size, out_size)¶
- Parameters:
- Returns:
Geometry after resize.
- Return type:
- Raises:
NotImplementedError – if method is not implemented in subclass
- rotate(rotator)¶
Rotates around image center -> New Geometry :param rotator: Class for image rotation. :type rotator:
ImageRotator:returns: Geometry after rotation. :rtype:Geometry
- scale(factor)[source]¶
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()[source]¶
Create
Rectangleobject from current Bitmap.- Returns:
Rectangle from bitmap.
- Return type:
- 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:
- 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:
- 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)
- validate(obj_class_shape, settings)¶
Validate geometry.
- Parameters:
- Raises:
ValueError – if geometry validation error
- property area¶
- Returns:
float
- 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: