GraphNodes¶
- class GraphNodes[source]¶
Bases:
supervisely.geometry.geometry.Geometry
GraphNodes geometry for a single
Label
.GraphNodes
class object is immutable.- Parameters
- nodes : dict
Dict or List containing nodes of graph
- sly_id : int, optional
GraphNodes ID in Supervisely server.
- class_id : int, optional
ID of
ObjClass
to which GraphNodes belongs.- labeler_login : str, optional
Login of the user who created GraphNodes.
- updated_at : str, optional
Date and Time when GraphNodes 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 GraphNodes was created. Date Format is the same as in “updated_at” parameter.
- Usage example
import supervisely as sly from supervisely.geometry.graph import Node, GraphNodes vertex_1 = Node(sly.PointLocation(5, 5)) vertex_2 = Node(sly.PointLocation(100, 100)) vertex_3 = Node(sly.PointLocation(200, 250)) nodes = {0: vertex_1, 1: vertex_2, 2: vertex_3} figure = GraphNodes(nodes)
Methods
Makes a copy of the GraphNodes.
Convert graph template from json format :type config:
Dict
:param config: dictionary(graph template) in json format :rtype:Dict
:return: dictionary(graph template)Convert graph template in json format :type config:
Dict
:param config: dictionary(graph template) :rtype:Dict
:return: dictionary(graph template) in json formatconvert
Crops current GraphNodes.
- param bitmap
np.ndarray
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.
Flips current GraphNodes in horizontal.
Flips current GraphNodes in vertical.
Convert a json dict to GraphNodes.
geometry_name
Returns 2D boolean mask of the geometry.
Same as geometry_name(), but shorter.
Crops current GraphNodes with given rectangle and shifts it on value of rectangle left top angle.
Resizes current GraphNodes.
Rotates current GraphNodes.
Scales current GraphNodes.
Create Rectangle object from current GraphNodes.
Convert the GraphNodes to list.
- param transform_fn
Function to convert GraphNodes.
- param transform_fn
Function to convert GraphNodes location.
Translates current GraphNodes.
Checks the graph for correctness and compliance with the template
Attributes
GraphNodes area.
items_json_field
Copy of GraphNodes nodes.
- clone()[source]¶
Makes a copy of the GraphNodes.
- Returns
GraphNodes object
- Return type
- Usage Example
# Remember that GraphNodes class object is immutable, and we need to assign new instance of PointLocation to a new variable new_figure = figure.clone()
- static config_from_json(config)[source]¶
Convert graph template from json format :type config:
Dict
:param config: dictionary(graph template) in json format :rtype:Dict
:return: dictionary(graph template)
- static config_to_json(config)[source]¶
Convert graph template in json format :type config:
Dict
:param config: dictionary(graph template) :rtype:Dict
:return: dictionary(graph template) in json format
- crop(rect)[source]¶
Crops current GraphNodes.
- Parameters
- rect : Rectangle
Rectangle object for crop.
- Returns
List of GraphNodes objects
- Return type
List[GraphNodes]
- Usage Example
import supervisely as sly crop_figures = figure.crop(sly.Rectangle(0, 0, 300, 350))
-
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]¶
Flips current GraphNodes in horizontal.
- Parameters
- Returns
GraphNodes object
- Return type
- Usage Example
# Remember that GraphNodes class object is immutable, and we need to assign new instance of Rectangle to a new variable height, width = 300, 400 fliplr_figure = figure.fliplr((height, width))
- flipud(img_size)[source]¶
Flips current GraphNodes in vertical.
- Parameters
- Returns
GraphNodes object
- Return type
- Usage Example
# Remember that GraphNodes class object is immutable, and we need to assign new instance of Rectangle to a new variable height, width = 300, 400 flipud_figure = figure.flipud((height, width))
- classmethod from_json(data)[source]¶
Convert a json dict to GraphNodes. Read more about Supervisely format.
- Parameters
- data : dict
GraphNodes in json format as a dict.
- Returns
GraphNodes object
- Return type
- Usage example
figure_json = { "nodes": { "0": { "loc": [5, 5] }, "1": { "loc": [100, 100] }, "2": { "loc": [250, 200] } } } from supervisely.geometry.graph import GraphNodes figure = GraphNodes.from_json(figure_json)
- 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
- 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)[source]¶
Crops current GraphNodes with given rectangle and shifts it on value of rectangle left top angle.
- Parameters
- rect : Rectangle
Rectangle object for crop.
- Returns
List of GraphNodes objects
- Return type
- Usage Example
import supervisely as sly rel_crop_figures = figure.relative_crop(sly.Rectangle(0, 0, 300, 350))
- resize(in_size, out_size)[source]¶
Resizes current GraphNodes.
- Parameters
- Returns
GraphNodes object
- Return type
- Usage Example
# Remember that GraphNodes class object is immutable, and we need to assign new instance of Rectangle to a new variable in_height, in_width = 300, 400 out_height, out_width = 600, 800 resize_figure = figure.resize((in_height, in_width), (out_height, out_width))
- rotate(rotator)[source]¶
Rotates current GraphNodes.
- Parameters
- rotator : ImageRotator
ImageRotator object for rotation.
- Returns
GraphNodes object
- Return type
- Usage Example
from supervisely.geometry.image_rotator import ImageRotator # Remember that GraphNodes class object is immutable, and we need to assign new instance of Rectangle to a new variable height, width = 300, 400 rotator = ImageRotator((height, width), 25) rotate_figure = figure.rotate(rotator)
- scale(factor)[source]¶
Scales current GraphNodes.
- Parameters
- factor : float
Scale parameter.
- Returns
GraphNodes object
- Return type
- Usage Example
# Remember that GraphNodes class object is immutable, and we need to assign new instance of Rectangle to a new variable scale_figure = figure.scale(0.75)
- to_bbox()[source]¶
Create Rectangle object from current GraphNodes.
- Returns
Rectangle object
- Return type
- Usage Example
rectangle = figure.to_bbox()
- to_json()[source]¶
Convert the GraphNodes to list. Read more about Supervisely format.
- Returns
Json format as a dict
- Return type
- Usage example
import supervisely as sly from supervisely.geometry.graph import Node, GraphNodes vertex_1 = Node(sly.PointLocation(5, 5)) vertex_2 = Node(sly.PointLocation(100, 100)) vertex_3 = Node(sly.PointLocation(200, 250)) nodes = {0: vertex_1, 1: vertex_2, 2: vertex_3} figure = GraphNodes(nodes) figure_json = figure.to_json() print(figure_json) # Output: { # "nodes": { # "0": { # "loc": [5, 5] # }, # "1": { # "loc": [100, 100] # }, # "2": { # "loc": [250, 200] # } # } # }
- transform(transform_fn)[source]¶
- Parameters
- transform_fn
Function to convert GraphNodes.
- Returns
GraphNodes object
- Return type
- transform_locations(transform_fn)[source]¶
- Parameters
- transform_fn
Function to convert GraphNodes location.
- Returns
GraphNodes object
- Return type
- translate(drow, dcol)[source]¶
Translates current GraphNodes.
- Parameters
- Returns
GraphNodes object
- Return type
- Usage Example
# Remember that GraphNodes class object is immutable, and we need to assign new instance of Rectangle to a new variable translate_figure = figure.translate(150, 250)
- validate(name, settings)[source]¶
Checks the graph for correctness and compliance with the template
- Return type
- property area¶
GraphNodes area.
- Returns
Area of current GraphNodes, always 0.0
- Return type
- Usage Example
print(figure.area) # Output: 0.0