0.1.39
Loading...
Searching...
No Matches
pyhelios.annotation Namespace Reference

Classes

class  YOLOBox
 A bounding box in the normalized form of the YOLO annotation format. More...
 

Functions

None _check_context (context, str func_name)
 
Tuple[int, int] _check_resolution (resolution, str func_name)
 
np.ndarray _check_pixel_map (pixel_uuids, int width, int height, str func_name)
 
Tuple[List[str], List[int]] _check_labels (data_labels, class_ids, str func_name)
 
str _check_filename (value, str name, str func_name)
 
List[YOLOBox] labelBoundingBoxes (Context context, pixel_uuids, int2 resolution, Union[str, List[str]] data_labels, Union[int, List[int]] class_ids, bool use_object_data=False)
 Compute a bounding box for each labeled object visible in a pixel-to-primitive map.
 
None writeLabelBoundingBoxes (Context context, pixel_uuids, int2 resolution, Union[str, List[str]] data_labels, Union[int, List[int]] class_ids, str image_file, str classes_txt_file="classes.txt", str image_path="./", bool use_object_data=False)
 Write YOLO bounding boxes and a class file for the labeled objects visible in a pixel-to-primitive map.
 
Dict[int, np.ndarray] labelMasks (Context context, pixel_uuids, int2 resolution, str data_label, bool use_object_data=False)
 Build a binary mask for each distinct value of a data label visible in a pixel-to-primitive map.
 
None writeLabelSegmentationMasks (Context context, pixel_uuids, int2 resolution, Union[str, List[str]] data_labels, Union[int, List[int]] class_ids, str json_filename, str image_file, Optional[List[str]] data_attribute_labels=None, bool append_file=False, bool use_object_data=False)
 Write COCO JSON segmentation masks for the labeled objects visible in a pixel-to-primitive map.
 

Function Documentation

◆ _check_context()

None pyhelios.annotation._check_context ( context,
str func_name )
protected

Definition at line 71 of file annotation.py.

◆ _check_filename()

str pyhelios.annotation._check_filename ( value,
str name,
str func_name )
protected

Definition at line 128 of file annotation.py.

◆ _check_labels()

Tuple[List[str], List[int]] pyhelios.annotation._check_labels ( data_labels,
class_ids,
str func_name )
protected

Definition at line 101 of file annotation.py.

◆ _check_pixel_map()

np.ndarray pyhelios.annotation._check_pixel_map ( pixel_uuids,
int width,
int height,
str func_name )
protected

Definition at line 85 of file annotation.py.

◆ _check_resolution()

Tuple[int, int] pyhelios.annotation._check_resolution ( resolution,
str func_name )
protected

Definition at line 77 of file annotation.py.

◆ labelBoundingBoxes()

List[YOLOBox] pyhelios.annotation.labelBoundingBoxes ( Context context,
pixel_uuids,
int2 resolution,
Union[str, List[str]] data_labels,
Union[int, List[int]] class_ids,
bool use_object_data = False )

Compute a bounding box for each labeled object visible in a pixel-to-primitive map.

One box is produced per distinct pair of class index and label value. A box encloses whole every pixel in which the object is visible: it runs from the left edge of the first pixel column to the right edge of the last, and from the top edge of the first pixel row to the bottom edge of the last, so an object visible in a single pixel has a box one pixel in size.

Parameters
contextContext holding the primitives named by the map and their label data.
pixel_uuidsPixel-to-primitive map (UUID + 1 per pixel, 0 for none), row-major with row 0 at the top of the image.
resolutionImage dimensions in pixels, as int2(width, height).
data_labelsName of a primitive or object data label, or a list of them.
class_idsClass index for the objects of each data label (an int for a single label, or a list in the same order as data_labels).
use_object_dataIf True, labels are read from the data of each primitive's parent object; if False (default), from primitive data.
Returns
List of :class:YOLOBox, ordered by class index and then label value.
Exceptions
ValueErrorIf ``context`` is not a Context, ``resolution`` is not an int2, or the map does not have width * height elements.
TypeErrorIf the labels, class IDs or map have the wrong type.
NotImplementedErrorIf the native library predates helios-core v1.3.91.

Definition at line 162 of file annotation.py.

◆ labelMasks()

Dict[int, np.ndarray] pyhelios.annotation.labelMasks ( Context context,
pixel_uuids,
int2 resolution,
str data_label,
bool use_object_data = False )

Build a binary mask for each distinct value of a data label visible in a pixel-to-primitive map.

Parameters
contextContext holding the primitives named by the map and their label data.
pixel_uuidsPixel-to-primitive map (UUID + 1 per pixel, 0 for none), row-major with row 0 at the top of the image.
resolutionImage dimensions in pixels, as int2(width, height).
data_labelName of the primitive or object data label, of type uint or int.
use_object_dataIf True, the label is read from object data; if False (default), from primitive data.
Returns
Dict mapping each label value to a boolean NumPy array of shape (height, width), indexed [row, column] with row 0 at the top of the image.
Exceptions
ValueErrorOn invalid arguments (see :func:`labelBoundingBoxes`).
NotImplementedErrorIf the native library predates helios-core v1.3.91.

Definition at line 237 of file annotation.py.

◆ writeLabelBoundingBoxes()

None pyhelios.annotation.writeLabelBoundingBoxes ( Context context,
pixel_uuids,
int2 resolution,
Union[str, List[str]] data_labels,
Union[int, List[int]] class_ids,
str image_file,
str classes_txt_file = "classes.txt",
str image_path = "./",
bool use_object_data = False )

Write YOLO bounding boxes and a class file for the labeled objects visible in a pixel-to-primitive map.

The boxes (see :func:labelBoundingBoxes) are written to a file named after the image, with its extension replaced by .txt, in the directory image_path. The class file holds one class_id data_label pair per line.

Parameters
contextContext holding the primitives named by the map and their label data.
pixel_uuidsPixel-to-primitive map (UUID + 1 per pixel, 0 for none), row-major with row 0 at the top of the image.
resolutionImage dimensions in pixels, as int2(width, height).
data_labelsName of a primitive or object data label, or a list of them.
class_idsClass index for the objects of each data label.
image_fileName of the image these boxes annotate. Only its stem is used, to name the output file; the image itself need not exist.
classes_txt_fileName of the class file to write within image_path (default "classes.txt").
image_pathDirectory to write the output files to (default: current directory).
use_object_dataIf True, labels are read from object data; if False (default), from primitive data.
Exceptions
ValueErrorOn invalid arguments (see :func:`labelBoundingBoxes`).
HeliosRuntimeErrorIf ``image_path`` is not a writable directory or a file cannot be written.
NotImplementedErrorIf the native library predates helios-core v1.3.91.

Definition at line 200 of file annotation.py.

◆ writeLabelSegmentationMasks()

None pyhelios.annotation.writeLabelSegmentationMasks ( Context context,
pixel_uuids,
int2 resolution,
Union[str, List[str]] data_labels,
Union[int, List[int]] class_ids,
str json_filename,
str image_file,
Optional[List[str]] data_attribute_labels = None,
bool append_file = False,
bool use_object_data = False )

Write COCO JSON segmentation masks for the labeled objects visible in a pixel-to-primitive map.

Each connected region of pixels sharing one value of a data label becomes one annotation, so an object split in two by an occluder yields two annotations. Pixels touching only at a corner are connected. The bbox of an annotation is (x, y, width, height) in pixels, enclosing whole every pixel of the region. A region of only one or two pixels is too small to outline and is not written. Each data label becomes a COCO category.

Parameters
contextContext holding the primitives named by the map and their label data.
pixel_uuidsPixel-to-primitive map (UUID + 1 per pixel, 0 for none), row-major with row 0 at the top of the image.
resolutionImage dimensions in pixels, as int2(width, height).
data_labelsName of a primitive or object data label, or a list of them.
class_idsCOCO category ID for each data label.
json_filenamePath of the COCO JSON file to write. ".json" is appended if missing.
image_filePath of the image these masks annotate, which must exist.
data_attribute_labelsOptional primitive or object data labels of type int, uint, float or double whose mean over the pixels of each mask is written to that annotation's "attributes". A label that exists as both is read from primitive data; labels that do not exist are ignored.
append_fileIf True, annotations are added to an existing file at json_filename; if False (default), a new file is written.
use_object_dataIf True, labels are read from object data; if False (default), from primitive data.
Exceptions
ValueErrorOn invalid arguments (see :func:`labelBoundingBoxes`).
HeliosRuntimeErrorIf ``image_file`` does not exist or the JSON file cannot be written.
NotImplementedErrorIf the native library predates helios-core v1.3.91.

Definition at line 281 of file annotation.py.