def decode_mask(
    encoded: Sequence[float], /, *, image_width: int, image_height: int
) -> NDArray[bool]:
    """
    Decodes a "points" attribute of a LabeledShape/LabeledShapeRequest object of type "mask"
    into a 2D boolean array representing the mask.

    `image_width` and `image_height` must be set to the dimensions
    of the image that the mask applies to.
    The returned mask will have shape (image_height, image_width).
    """

    if len(encoded) < 5:
        raise ValueError("too few elements in encoded mask")

    if image_width <= 0 or image_height <= 0:
        raise ValueError("invalid image dimensions")

    def to_int(x: float) -> int:
        if isinstance(x, int):
            return x
        if isinstance(x, float) and x.is_integer():
            return int(x)
        raise ValueError(f"non-integer value in encoded mask: {x!r}")

    *run_lengths, x1, y1, x2, y2 = map(to_int, encoded)
    x2 += 1
    y2 += 1

    if not (0 <= x1 < x2 <= image_width and 0 <= y1 < y2 <= image_height):
        raise ValueError("invalid encoded bounding box")

    alternating_bools = (np.arange(len(run_lengths)) & 1) != 0
    mask = np.repeat(alternating_bools, run_lengths)
    if mask.size != (y2 - y1) * (x2 - x1):
        raise ValueError("encoded bitmap does not match encoded bounding box")

    full_mask = np.zeros((image_height, image_width), dtype=bool)
    full_mask[y1:y2, x1:x2] = mask.reshape((y2 - y1, x2 - x1))
    return full_mask

    Decodes a "points" attribute of a LabeledShape/LabeledShapeRequest object of type "mask"
    into a 2D boolean array representing the mask.

    `image_width` and `image_height` must be set to the dimensions
    of the image that the mask applies to.
    The returned mask will have shape (image_height, image_width).
    
cvat-sdk/cvat_sdk/masks.py