Slice¶
- class Slice[source]¶
Bases:
supervisely.video_annotation.frame.Frame
A class representing a single slice of a medical image. Slice object for
VolumeAnnotation
.Frame
object is immutable.- Parameters
- index : int
Index of the Slice.
- figures : Optional[List[VolumeFigure]]
List of
VolumeFigures
.
- Usage example
import supervisely as sly frame_index = 7 geometry = sly.Rectangle(0, 0, 100, 100) class_car = sly.ObjClass('car', sly.Rectangle) object_car = sly.VolumeObject(class_car) figure_car = sly.VolumeFigure(object_car, geometry, frame_index) frame = sly.Slice(frame_index, figures=[figure_car]) print(frame.to_json()) # Output: { # "figures": [ # { # "geometry": { # "points": { # "exterior": [ # [0, 0], # [100, 100] # ], # "interior": [] # } # }, # "geometryType": "rectangle", # "key": "eb0ab5f772054f70b6a9f5b583a47287", # "meta": { # "normal": { "x": 0, "y": 0, "z": 1 }, # "planeName": "axial", # "sliceIndex": 7 # }, # "objectKey": "dbd236a6a6f440139fd0299905fcc46e" # } # ], # "index": 7 # }
Methods
Makes a copy of Frame with new fields, if fields are given, otherwise it will use fields of the original Frame.
Deserialize a
Slice
object from a JSON representation.Get Frame key (index) value.
Convert the Frame to a json dict.
Checks if image with given size contains a figure.
Attributes
Frame figures.
Frame index.
- figure_type¶
alias of
supervisely.volume_annotation.volume_figure.VolumeFigure
-
clone(index=
None
, figures=None
)¶ Makes a copy of Frame with new fields, if fields are given, otherwise it will use fields of the original Frame.
- Parameters
- index : int, optional
Index of the Frame.
- figures : list, optional
List of
VideoFigures
.
- Returns
Frame object
- Return type
Frame
- Usage example
import supervisely as sly frame_index = 7 geometry = sly.Rectangle(0, 0, 100, 100) class_car = sly.ObjClass('car', sly.Rectangle) object_car = sly.VideoObject(class_car) figure_car = sly.VideoFigure(object_car, geometry, frame_index) frame = sly.Frame(frame_index, figures=[figure_car]) # Remember that Frame object is immutable, and we need to assign new instance of Frame to a new variable new_frame = frame.clone(index=100, figures=[]) print(new_frame.to_json()) # Output: { # "index": 100, # "figures": [] # }
-
classmethod from_json(data, objects, plane_name, slices_count=
None
, key_id_map=None
)[source]¶ Deserialize a
Slice
object from a JSON representation.- Parameters
- data : dict
The JSON representation of the
Slice
.- objects : VolumeObjectCollection
A collection of objects in volume.
- plane_name : str
The name of the plane.
- slices_count : Optional[int]
The total number of slices in the volume, if known.
- key_id_map : Optional[KeyIdMap]
A mapping of keys to IDs used for referencing objects.
- Returns
The deserialized
Slice
object.- Return type
- Raises
ValueError – If the slice index is negative or greater than the total number of slices.
- Usage example
import supervisely as sly slice_index = 7 geometry = sly.Rectangle(0, 0, 100, 100) class_car = sly.ObjClass('car', sly.Rectangle) object_car = sly.VolumeObject(class_car) objects = sly.VolumeObjectCollection([object_car]) figure_car = sly.VolumeFigure(object_car, geometry, sly.Plane.AXIAL, slice_index) slice = sly.Slice(slice_index, figures=[figure_car]) slice_json = slice.to_json() new_slice = sly.Slice.from_json(slice_json, objects, sly.Plane.AXIAL)
- key()¶
Get Frame key (index) value.
- Returns
Frame key (index) value
- Return type
- Usage example
import supervisely as sly frame_index = 7 geometry = sly.Rectangle(0, 0, 100, 100) class_car = sly.ObjClass('car', sly.Rectangle) object_car = sly.VideoObject(class_car) figure_car = sly.VideoFigure(object_car, geometry, frame_index) frame = sly.Frame(frame_index, figures=[figure_car]) print(frame.key()) # Output: 7
-
to_json(key_id_map=
None
)¶ Convert the Frame to a json dict. Read more about Supervisely format.
- Parameters
- key_id_map : KeyIdMap, optional
KeyIdMap object.
- Returns
Json format as a dict
- Return type
- Usage example
import supervisely as sly frame_index = 7 geometry = sly.Rectangle(0, 0, 100, 100) class_car = sly.ObjClass('car', sly.Rectangle) object_car = sly.VideoObject(class_car) figure_car = sly.VideoFigure(object_car, geometry, frame_index) frame = sly.Frame(frame_index, figures=[figure_car]) frame_json = frame.to_json() print(frame_json) # Output: { # "index": 7, # "figures": [ # { # "key": "39f3eb15791f4c72b7cdb98c17b3f0f1", # "objectKey": "319814af474941a98ca208c3fad5ed81", # "geometryType": "rectangle", # "geometry": { # "points": { # "exterior": [ # [ # 0, # 0 # ], # [ # 100, # 100 # ] # ], # "interior": [] # } # } # } # ] # }
-
validate_figures_bounds(img_size=
None
)¶ Checks if image with given size contains a figure.
- Parameters
- Raises
OutOfImageBoundsException
, if figure is out of image bounds- Returns
None
- Return type
NoneType
- Usage Example
import supervisely as sly frame_index = 7 geometry = sly.Rectangle(0, 0, 100, 100) class_car = sly.ObjClass('car', sly.Rectangle) object_car = sly.VideoObject(class_car) figure_car = sly.VideoFigure(object_car, geometry, frame_index) frame = sly.Frame(frame_index, figures=[figure_car]) image_size = (20, 200) frame.validate_figures_bounds(image_size) # raise OutOfImageBoundsException("Figure is out of image bounds")
- property figures¶
Frame figures.
- Returns
List of figures on Frame.
- Return type
- Usage example
frame_figures = frame.figures