Skip to content

pixano.features.schemas.annotations.bbox

BBox(created_at=None, updated_at=None, **data)

Bases: Annotation

Bounding box using coordinates in xyxy or xywh format.

Attributes:

Name Type Description
coords list[float]

List of coordinates in given format.

format str

Coordinates format, 'xyxy' or 'xywh'.

is_normalized bool

True if coordinates are normalized to image size.

confidence float

Bounding box confidence if predicted. -1 if not predicted.

Source code in pixano/features/schemas/base_schema.py
def __init__(self, /, created_at: datetime | None = None, updated_at: datetime | None = None, **data: Any):
    """Create a new model by parsing and validating input data from keyword arguments.

    Raises [`ValidationError`][pydantic_core.ValidationError] if the input data cannot be
    validated to form a valid model.

    `self` is explicitly positional-only to allow `self` as a field name.

    Args:
        created_at: The creation date of the object.
        updated_at: The last modification date of the object.
        data: The data of the object validated by Pydantic.
    """
    created_at, updated_at = validate_and_init_create_at_and_update_at(created_at, updated_at)
    data.update({"created_at": created_at, "updated_at": updated_at})
    super().__init__(**data)

xywh_coords property

Return the bounding box xywh coordinates.

Returns:

Type Description
list[float]

Coordinates in xywh format.

xyxy_coords property

Return the bounding box xyxy coordinates.

Returns:

Type Description
list[float]

Coordinates in xyxy format.

denormalize(height, width)

Return the bounding box with coordinates denormalized relatively to the image size.

Parameters:

Name Type Description Default
height int

Image height.

required
width int

Image width.

required

Returns:

Type Description
Self

Bounding box with coordinates denormalized relatively to the image size.

Source code in pixano/features/schemas/annotations/bbox.py
def denormalize(self, height: int, width: int) -> Self:
    """Return the bounding box with coordinates denormalized relatively to the image size.

    Args:
        height: Image height.
        width: Image width.

    Returns:
        Bounding box with coordinates denormalized relatively to the image size.
    """
    return BBox(
        coords=bbox_utils.denormalize_coords(self.coords, height, width),
        format=self.format,
        is_normalized=False,
        confidence=self.confidence,
    )

from_mask(mask, **kwargs) staticmethod

Create a bounding box using a NumPy array mask.

Parameters:

Name Type Description Default
mask ndarray

NumPy array mask.

required
kwargs Any

Additional arguments.

{}

Returns:

Type Description
BBox

The bounding box.

Source code in pixano/features/schemas/annotations/bbox.py
@staticmethod
def from_mask(mask: np.ndarray, **kwargs: Any) -> "BBox":
    """Create a bounding box using a NumPy array mask.

    Args:
        mask: NumPy array mask.
        kwargs: Additional arguments.

    Returns:
        The bounding box.
    """
    return BBox.from_xywh(
        xywh=bbox_utils.mask_to_bbox(mask),
        is_normalized=True,
        **kwargs,
    )

from_rle(rle, **kwargs) staticmethod

Create a bounding box using a RLE mask.

Parameters:

Name Type Description Default
rle CompressedRLE

RLE mask.

required
kwargs Any

Additional arguments.

{}

Returns:

Type Description
BBox

The bounding box.

Source code in pixano/features/schemas/annotations/bbox.py
@staticmethod
def from_rle(
    rle: CompressedRLE,
    **kwargs: Any,
) -> "BBox":
    """Create a bounding box using a RLE mask.

    Args:
        rle: RLE mask.
        kwargs: Additional arguments.

    Returns:
        The bounding box.
    """
    return BBox.from_mask(mask=rle.to_mask(), **kwargs)

from_xywh(xywh, **kwargs) staticmethod

Create a bounding box using normalized xywh coordinates.

Parameters:

Name Type Description Default
xywh list[float]

List of coordinates in xywh format.

required
kwargs Any

Additional arguments.

{}

Returns:

Type Description
BBox

The bounding box.

Source code in pixano/features/schemas/annotations/bbox.py
@staticmethod
def from_xywh(
    xywh: list[float],
    **kwargs: Any,
) -> "BBox":
    """Create a bounding box using normalized xywh coordinates.

    Args:
        xywh: List of coordinates in xywh format.
        kwargs: Additional arguments.

    Returns:
        The bounding box.
    """
    return BBox(
        coords=xywh,
        format="xywh",
        **kwargs,
    )

from_xyxy(xyxy, **kwargs) staticmethod

Create a bounding box using normalized xyxy coordinates.

Parameters:

Name Type Description Default
xyxy list[float]

List of coordinates in xyxy format.

required
kwargs Any

Additional arguments.

{}

Returns:

Type Description
BBox

The bounding box.

Source code in pixano/features/schemas/annotations/bbox.py
@staticmethod
def from_xyxy(
    xyxy: list[float],
    **kwargs: Any,
) -> "BBox":
    """Create a bounding box using normalized xyxy coordinates.

    Args:
        xyxy: List of coordinates in xyxy format.
        kwargs: Additional arguments.

    Returns:
        The bounding box.
    """
    return BBox(
        coords=xyxy,
        format="xyxy",
        **kwargs,
    )

none() classmethod

Utility function to get a None equivalent. Should be removed as soon as Lance manages None value.

Returns:

Type Description
Self

"None" BBox.

Source code in pixano/features/schemas/annotations/bbox.py
@classmethod
def none(cls) -> Self:
    """Utility function to get a `None` equivalent.
    Should be removed as soon as Lance manages `None` value.

    Returns:
        "None" `BBox`.
    """
    return cls(
        id="",
        item=ItemRef.none(),
        view=ViewRef.none(),
        entity=EntityRef.none(),
        coords=[0.0, 0.0, 0.0, 0.0],
        format="xywh",
        is_normalized=True,
        confidence=-1,
    )

normalize(height, width)

Return the bounding box with coordinates normalized relatively to the image size.

Parameters:

Name Type Description Default
height int

Image height.

required
width int

Image width.

required

Returns:

Type Description
Self

Bounding box with coordinates normalized relatively to the image size.

Source code in pixano/features/schemas/annotations/bbox.py
def normalize(self, height: int, width: int) -> Self:
    """Return the bounding box with coordinates normalized relatively to the image size.

    Args:
        height: Image height.
        width: Image width.

    Returns:
        Bounding box with coordinates normalized relatively to the image size.
    """
    return BBox(
        coords=bbox_utils.normalize_coords(self.coords, height, width),
        format=self.format,
        is_normalized=True,
        confidence=self.confidence,
    )

to_xywh()

Return the bounding box in xywh format.

Returns:

Type Description
Self

Bounding box in xyxy format.

Source code in pixano/features/schemas/annotations/bbox.py
def to_xywh(self) -> Self:
    """Return the bounding box in xywh format.

    Returns:
        Bounding box in xyxy format.
    """
    return BBox(
        coords=self.xywh_coords,
        format="xywh",
        is_normalized=self.is_normalized,
        confidence=self.confidence,
    )

to_xyxy()

Return the bounding box in xyxy format.

Returns:

Type Description
Self

Bounding box in xyxy format.

Source code in pixano/features/schemas/annotations/bbox.py
def to_xyxy(self) -> Self:
    """Return the bounding box in xyxy format.

    Returns:
        Bounding box in xyxy format.
    """
    return BBox(
        coords=self.xyxy_coords,
        format="xyxy",
        is_normalized=self.is_normalized,
        confidence=self.confidence,
    )

BBox3D(created_at=None, updated_at=None, **data)

Bases: Annotation

A 3D bounding Box.

Attributes:

Name Type Description
coords list[float]

List of coordinates in given format.

format str

Coordinates format, 'xyzxyz' or 'xyzwhd'.

heading list[float]

Orientation of the bounding box.

is_normalized bool

True if coordinates are normalized to image size.

confidence float

Bounding box confidence if predicted. -1 if not predicted.

Source code in pixano/features/schemas/base_schema.py
def __init__(self, /, created_at: datetime | None = None, updated_at: datetime | None = None, **data: Any):
    """Create a new model by parsing and validating input data from keyword arguments.

    Raises [`ValidationError`][pydantic_core.ValidationError] if the input data cannot be
    validated to form a valid model.

    `self` is explicitly positional-only to allow `self` as a field name.

    Args:
        created_at: The creation date of the object.
        updated_at: The last modification date of the object.
        data: The data of the object validated by Pydantic.
    """
    created_at, updated_at = validate_and_init_create_at_and_update_at(created_at, updated_at)
    data.update({"created_at": created_at, "updated_at": updated_at})
    super().__init__(**data)

none() classmethod

Utility function to get a None equivalent. Should be removed as soon as Lance manages None value.

Returns:

Type Description
Self

"None" BBox3D.

Source code in pixano/features/schemas/annotations/bbox.py
@classmethod
def none(cls) -> Self:
    """Utility function to get a `None` equivalent.
    Should be removed as soon as Lance manages `None` value.

    Returns:
        "None" BBox3D.
    """
    return cls(
        id="",
        item=ItemRef.none(),
        view=ViewRef.none(),
        entity=EntityRef.none(),
        coords=[0, 0, 0, 0, 0, 0],
        format="xyzwhd",
        heading=[0, 0, 0],
        is_normalized=True,
        confidence=-1,
    )

create_bbox(coords, format, is_normalized, confidence=-1, id='', item_ref=ItemRef.none(), view_ref=ViewRef.none(), entity_ref=EntityRef.none(), source_ref=SourceRef.none())

Create a BBox instance.

Parameters:

Name Type Description Default
coords list[float]

List of coordinates in given format.

required
format Literal['xyxy', 'xywh']

Coordinates format, 'xyxy' or 'xywh'.

required
is_normalized bool

True if coordinates are normalized to image size.

required
confidence float

Bounding box confidence if predicted.

-1
id str

BBox ID.

''
item_ref ItemRef

Item reference.

none()
view_ref ViewRef

View reference.

none()
entity_ref EntityRef

Entity reference.

none()
source_ref SourceRef

Source reference.

none()

Returns:

Type Description
BBox

The created BBox instance.

Source code in pixano/features/schemas/annotations/bbox.py
def create_bbox(
    coords: list[float],
    format: Literal["xyxy", "xywh"],
    is_normalized: bool,
    confidence: float = -1,
    id: str = "",
    item_ref: ItemRef = ItemRef.none(),
    view_ref: ViewRef = ViewRef.none(),
    entity_ref: EntityRef = EntityRef.none(),
    source_ref: SourceRef = SourceRef.none(),
) -> BBox:
    """Create a `BBox` instance.

    Args:
        coords: List of coordinates in given format.
        format: Coordinates format, 'xyxy' or 'xywh'.
        is_normalized: True if coordinates are normalized to image size.
        confidence: Bounding box confidence if predicted.
        id: BBox ID.
        item_ref: Item reference.
        view_ref: View reference.
        entity_ref: Entity reference.
        source_ref: Source reference.

    Returns:
        The created `BBox` instance.
    """
    return BBox(
        id=id,
        item_ref=item_ref,
        view_ref=view_ref,
        entity_ref=entity_ref,
        source_ref=source_ref,
        coords=coords,
        format=str(format),
        is_normalized=is_normalized,
        confidence=confidence,
    )

create_bbox3d(coords, format, heading, is_normalized, confidence=-1.0, id='', item_ref=ItemRef.none(), view_ref=ViewRef.none(), entity_ref=EntityRef.none(), source_ref=SourceRef.none())

Create a BBox3D instance.

Parameters:

Name Type Description Default
coords list[float]

The 3D position coordinates.

required
format Literal['xyzxyz', 'xyzwhd']

Coordinates format, 'xyzxyz' or 'xyzwhd'.

required
heading list[float]

The orientation.

required
is_normalized bool

True if coordinates are normalized to image size.

required
confidence float

Bounding box confidence if predicted.

-1.0
id str

BBox3D ID.

''
item_ref ItemRef

Item reference.

none()
view_ref ViewRef

View reference.

none()
entity_ref EntityRef

Entity reference.

none()
source_ref SourceRef

Source reference.

none()

Returns:

Type Description
BBox3D

The created BBox3D instance.

Source code in pixano/features/schemas/annotations/bbox.py
def create_bbox3d(
    coords: list[float],
    format: Literal["xyzxyz", "xyzwhd"],
    heading: list[float],
    is_normalized: bool,
    confidence: float = -1.0,
    id: str = "",
    item_ref: ItemRef = ItemRef.none(),
    view_ref: ViewRef = ViewRef.none(),
    entity_ref: EntityRef = EntityRef.none(),
    source_ref: SourceRef = SourceRef.none(),
) -> BBox3D:
    """Create a `BBox3D` instance.

    Args:
        coords: The 3D position coordinates.
        format: Coordinates format, 'xyzxyz' or 'xyzwhd'.
        heading: The orientation.
        is_normalized: True if coordinates are normalized to image size.
        confidence: Bounding box confidence if predicted.
        id: BBox3D ID.
        item_ref: Item reference.
        view_ref: View reference.
        entity_ref: Entity reference.
        source_ref: Source reference.

    Returns:
        The created `BBox3D` instance.
    """
    return BBox3D(
        id=id,
        item_ref=item_ref,
        view_ref=view_ref,
        entity_ref=entity_ref,
        source_ref=source_ref,
        coords=coords,
        format=str(format),
        heading=heading,
        is_normalized=is_normalized,
        confidence=confidence,
    )

is_bbox(cls, strict=False)

Check if a class is a BBox or a subclass of BBox.

Source code in pixano/features/schemas/annotations/bbox.py
def is_bbox(cls: type, strict: bool = False) -> bool:
    """Check if a class is a `BBox` or a subclass of `BBox`."""
    return issubclass_strict(cls, BBox, strict)

is_bbox3d(cls, strict=False)

Check if a class is a BBox3D or subclass of BBox3D.

Source code in pixano/features/schemas/annotations/bbox.py
def is_bbox3d(cls: type, strict: bool = False) -> bool:
    """Check if a class is a `BBox3D` or subclass of `BBox3D`."""
    return issubclass_strict(cls, BBox3D, strict)