Skip to content

Label utils module

The module kili.utils.labels provides a set of helpers to convert point, bounding box, polygon and segmentation labels.

Info

In Kili json response format, a normalized vertex is a dictionary with keys x and y and values between 0 and 1. The origin is always the top left corner of the image. The x-axis is horizontal and the y-axis is vertical with the y-axis pointing down. You can find more information about the Kili data format here.

Points

kili.utils.labels.point

Helpers to create point annotations.

normalized_point_to_point(point, img_width=None, img_height=None, origin_location='bottom_left')

Convert a Kili normalized vertex to a 2D point.

It is the inverse of the method point_to_normalized_point.

A point is a dict with keys "x" and "y", and corresponding values in pixels (int or float).

Conventions for the input point:

  • The origin is the top left corner of the image.
  • x-axis is horizontal and goes from left to right.
  • y-axis is vertical and goes from top to bottom.

Conventions for the output point:

  • The origin is defined by the origin_location argument.
  • x-axis is horizontal and goes from left to right.
  • y-axis is vertical. If origin_location is "top_left", it goes from top to bottom. If origin_location is "bottom_left", it goes from bottom to top.

If the image width and height are provided, the output point coordinates will be scaled to the image size. If not, the method will return a point with normalized coordinates.

Parameters:

Name Type Description Default
point Dict[str, float]

Point to convert.

required
img_width Union[int, float]

Width of the image the point is defined in.

None
img_height Union[int, float]

Height of the image the point is defined in.

None
origin_location typing_extensions.Literal['top_left', 'bottom_left']

Location of the origin of output point coordinate system. Can be either top_left or bottom_left.

'bottom_left'

Returns:

Type Description
Dict[typing_extensions.Literal['x', 'y'], float]

A dict with keys "x" and "y", and corresponding values in pixels.

Source code in kili/utils/labels/point.py
def normalized_point_to_point(
    point: Dict[str, float],
    img_width: Optional[Union[int, float]] = None,
    img_height: Optional[Union[int, float]] = None,
    origin_location: Literal["top_left", "bottom_left"] = "bottom_left",
) -> Dict[Literal["x", "y"], float]:
    # pylint: disable=line-too-long
    """Convert a Kili normalized vertex to a 2D point.

    It is the inverse of the method `point_to_normalized_point`.

    A point is a dict with keys `"x"` and `"y"`, and corresponding values in pixels (`int` or `float`).

    Conventions for the input point:

    - The origin is the top left corner of the image.
    - x-axis is horizontal and goes from left to right.
    - y-axis is vertical and goes from top to bottom.

    Conventions for the output point:

    - The origin is defined by the `origin_location` argument.
    - x-axis is horizontal and goes from left to right.
    - y-axis is vertical. If `origin_location` is `"top_left"`, it goes from top to bottom. If `origin_location` is `"bottom_left"`, it goes from bottom to top.

    If the image width and height are provided, the output point coordinates will be scaled to the image size.
    If not, the method will return a point with normalized coordinates.

    Args:
        point: Point to convert.
        img_width: Width of the image the point is defined in.
        img_height: Height of the image the point is defined in.
        origin_location: Location of the origin of output point coordinate system. Can be either `top_left` or `bottom_left`.

    Returns:
        A dict with keys `"x"` and `"y"`, and corresponding values in pixels.
    """
    if (img_width is None) != (img_height is None):
        raise ValueError("img_width and img_height must be both None or both not None.")

    if origin_location == "bottom_left":
        point = {"x": point["x"], "y": 1 - point["y"]}

    img_height = img_height or 1
    img_width = img_width or 1

    return {"x": point["x"] * img_width, "y": point["y"] * img_height}

point_to_normalized_point(point, img_width=None, img_height=None, origin_location='bottom_left')

Converts a 2D point to a Kili normalized vertex.

The output can be used to create object detection annotations. See the documentation for more details.

A point is a dict with keys "x" and "y", and corresponding values in pixels (int or float).

Conventions for the input point:

  • The origin is defined by the origin_location argument.
  • x-axis is horizontal and goes from left to right.
  • y-axis is vertical. If origin_location is "top_left", it goes from top to bottom. If origin_location is "bottom_left", it goes from bottom to top.

Conventions for the output point:

  • The origin is the top left corner of the image.
  • x-axis is horizontal and goes from left to right.
  • y-axis is vertical and goes from top to bottom.

If the image width and height are provided, the input point coordinates will be normalized to [0, 1]. If not, the method expects the input point coordinates to be already normalized.

Parameters:

Name Type Description Default
point Dict[str, Union[int, float]]

Point to convert.

required
img_width Union[int, float]

Width of the image the point is defined in.

None
img_height Union[int, float]

Height of the image the point is defined in.

None
origin_location typing_extensions.Literal['top_left', 'bottom_left']

Location of the origin of input point coordinate system. Can be either top_left or bottom_left.

'bottom_left'

Returns:

Type Description
Dict[typing_extensions.Literal['x', 'y'], float]

A dict with keys "x" and "y", and corresponding normalized values.

Example

from kili.utils.labels.point import point_to_normalized_point

normalized_point = point_to_normalized_point({"x": 5, "y": 40}, img_width=100, img_height=100)

json_response = {
    "OBJECT_DETECTION_JOB": {
        "annotations": [
            {
                "point": normalized_point,
                "categories": [{"name": "CLASS_A"}],
                "type": "marker",
            }
        ]
    }
}
Source code in kili/utils/labels/point.py
def point_to_normalized_point(
    point: Dict[str, Union[int, float]],
    img_width: Optional[Union[int, float]] = None,
    img_height: Optional[Union[int, float]] = None,
    origin_location: Literal["top_left", "bottom_left"] = "bottom_left",
) -> Dict[Literal["x", "y"], float]:
    # pylint: disable=line-too-long
    """Converts a 2D point to a Kili normalized vertex.

    The output can be used to create object detection annotations. See the [documentation](https://docs.kili-technology.com/reference/export-object-entity-detection-and-relation) for more details.

    A point is a dict with keys `"x"` and `"y"`, and corresponding values in pixels (`int` or `float`).

    Conventions for the input point:

    - The origin is defined by the `origin_location` argument.
    - x-axis is horizontal and goes from left to right.
    - y-axis is vertical. If `origin_location` is `"top_left"`, it goes from top to bottom. If `origin_location` is `"bottom_left"`, it goes from bottom to top.

    Conventions for the output point:

    - The origin is the top left corner of the image.
    - x-axis is horizontal and goes from left to right.
    - y-axis is vertical and goes from top to bottom.

    If the image width and height are provided, the input point coordinates will be normalized to `[0, 1]`.
    If not, the method expects the input point coordinates to be already normalized.

    Args:
        point: Point to convert.
        img_width: Width of the image the point is defined in.
        img_height: Height of the image the point is defined in.
        origin_location: Location of the origin of input point coordinate system. Can be either `top_left` or `bottom_left`.

    Returns:
        A dict with keys `"x"` and `"y"`, and corresponding normalized values.

    !!! Example
        ```python
        from kili.utils.labels.point import point_to_normalized_point

        normalized_point = point_to_normalized_point({"x": 5, "y": 40}, img_width=100, img_height=100)

        json_response = {
            "OBJECT_DETECTION_JOB": {
                "annotations": [
                    {
                        "point": normalized_point,
                        "categories": [{"name": "CLASS_A"}],
                        "type": "marker",
                    }
                ]
            }
        }
        ```
    """
    if (img_width is None) != (img_height is None):
        raise ValueError("img_width and img_height must be both None or both not None.")

    if img_width is not None and img_height is not None:
        point = {
            "x": point["x"] / img_width,
            "y": point["y"] / img_height,
        }

    if origin_location == "bottom_left":
        point = {"x": point["x"], "y": 1 - point["y"]}

    assert 0 <= point["x"] <= 1, f"Point x coordinate {point['x']} should be in [0, 1]."
    assert 0 <= point["y"] <= 1, f"Point y coordinate {point['y']} should be in [0, 1]."

    return {"x": point["x"], "y": point["y"]}

Bounding boxes

kili.utils.labels.bbox

Helpers to create boundingPoly rectangle annotations.

bbox_points_to_normalized_vertices(*, bottom_left, bottom_right, top_right, top_left, img_width=None, img_height=None, origin_location='bottom_left')

Converts a bounding box defined by its 4 points to normalized vertices.

The output can be used to create a boundingPoly rectangle annotation. See the documentation for more details.

A point is a dict with keys "x" and "y", and corresponding values in pixels (int or float).

Conventions for the input points:

  • The origin is defined by the origin_location argument.
  • x-axis is horizontal and goes from left to right.
  • y-axis is vertical. If origin_location is "top_left", it goes from top to bottom. If origin_location is "bottom_left", it goes from bottom to top.

Conventions for the output vertices:

  • The origin is the top left corner of the image.
  • x-axis is horizontal and goes from left to right.
  • y-axis is vertical and goes from top to bottom.

If the image width and height are provided, the input point coordinates will be normalized to [0, 1]. If not, the method expects the input points' coordinates to be already normalized.

Parameters:

Name Type Description Default
bottom_left Dict[str, Union[int, float]]

Bottom left point of the bounding box.

required
bottom_right Dict[str, Union[int, float]]

Bottom right point of the bounding box.

required
top_right Dict[str, Union[int, float]]

Top right point of the bounding box.

required
top_left Dict[str, Union[int, float]]

Top left point of the bounding box.

required
img_width Union[int, float]

Width of the image the bounding box is defined in.

None
img_height Union[int, float]

Height of the image the bounding box is defined in.

None
origin_location typing_extensions.Literal['top_left', 'bottom_left']

Location of the origin of input point coordinate system. Can be either top_left or bottom_left.

'bottom_left'

Returns:

Type Description
List[Dict[typing_extensions.Literal['x', 'y'], float]]

A list of normalized vertices.

Example

from kili.utils.labels.bbox import bbox_points_to_normalized_vertices

inputs = {
    bottom_left = {"x": 0, "y": 0},
    bottom_right = {"x": 10, "y": 0},
    top_right = {"x": 10, "y": 10},
    top_left = {"x": 0, "y": 10},
    img_width = 100,
    img_height = 100,
}
normalized_vertices = bbox_points_to_normalized_vertices(**inputs)
json_response = {
    "OBJECT_DETECTION_JOB": {
        "annotations": [
            {
                "boundingPoly": [{"normalizedVertices": normalized_vertices}],
                "categories": [{"name": "CLASS_A"}],
                "type": "rectangle",
            }
        ]
    }
}
Source code in kili/utils/labels/bbox.py
def bbox_points_to_normalized_vertices(
    *,
    bottom_left: Dict[str, Union[int, float]],
    bottom_right: Dict[str, Union[int, float]],
    top_right: Dict[str, Union[int, float]],
    top_left: Dict[str, Union[int, float]],
    img_width: Optional[Union[int, float]] = None,
    img_height: Optional[Union[int, float]] = None,
    origin_location: Literal["top_left", "bottom_left"] = "bottom_left",
) -> List[Dict[Literal["x", "y"], float]]:
    # pylint: disable=line-too-long
    """Converts a bounding box defined by its 4 points to normalized vertices.

    The output can be used to create a boundingPoly rectangle annotation. See the [documentation](https://docs.kili-technology.com/reference/export-object-entity-detection-and-relation#standard-object-detection) for more details.

    A point is a dict with keys `"x"` and `"y"`, and corresponding values in pixels (`int` or `float`).

    Conventions for the input points:

    - The origin is defined by the `origin_location` argument.
    - x-axis is horizontal and goes from left to right.
    - y-axis is vertical. If `origin_location` is `"top_left"`, it goes from top to bottom. If `origin_location` is `"bottom_left"`, it goes from bottom to top.

    Conventions for the output vertices:

    - The origin is the top left corner of the image.
    - x-axis is horizontal and goes from left to right.
    - y-axis is vertical and goes from top to bottom.

    If the image width and height are provided, the input point coordinates will be normalized to `[0, 1]`.
    If not, the method expects the input points' coordinates to be already normalized.

    Args:
        bottom_left: Bottom left point of the bounding box.
        bottom_right: Bottom right point of the bounding box.
        top_right: Top right point of the bounding box.
        top_left: Top left point of the bounding box.
        img_width: Width of the image the bounding box is defined in.
        img_height: Height of the image the bounding box is defined in.
        origin_location: Location of the origin of input point coordinate system. Can be either `top_left` or `bottom_left`.

    Returns:
        A list of normalized vertices.

    !!! Example
        ```python
        from kili.utils.labels.bbox import bbox_points_to_normalized_vertices

        inputs = {
            bottom_left = {"x": 0, "y": 0},
            bottom_right = {"x": 10, "y": 0},
            top_right = {"x": 10, "y": 10},
            top_left = {"x": 0, "y": 10},
            img_width = 100,
            img_height = 100,
        }
        normalized_vertices = bbox_points_to_normalized_vertices(**inputs)
        json_response = {
            "OBJECT_DETECTION_JOB": {
                "annotations": [
                    {
                        "boundingPoly": [{"normalizedVertices": normalized_vertices}],
                        "categories": [{"name": "CLASS_A"}],
                        "type": "rectangle",
                    }
                ]
            }
        }
        ```
    """
    assert bottom_left["x"] <= bottom_right["x"], "bottom_left.x must be <= bottom_right.x"
    assert top_left["x"] <= top_right["x"], "top_left.x must be <= top_right.x"
    if origin_location == "bottom_left":
        assert bottom_left["y"] <= top_left["y"], "bottom_left.y must be <= top_left.y"
        assert bottom_right["y"] <= top_right["y"], "bottom_right.y must be <= top_right.y"
    elif origin_location == "top_left":
        assert bottom_left["y"] >= top_left["y"], "bottom_left.y must be >= top_left.y"
        assert bottom_right["y"] >= top_right["y"], "bottom_right.y must be >= top_right.y"

    if (img_width is None) != (img_height is None):
        raise ValueError("img_width and img_height must be both None or both not None.")

    vertices = [
        point_to_normalized_point(
            point, img_width=img_width, img_height=img_height, origin_location=origin_location
        )
        for point in (bottom_left, top_left, top_right, bottom_right)
    ]

    return vertices

normalized_vertices_to_bbox_points(normalized_vertices, img_width=None, img_height=None, origin_location='bottom_left')

Converts a rectangle normalizedVertices annotation to a bounding box defined by 4 points.

It is the inverse of the method bbox_points_to_normalized_vertices.

A point is a dict with keys "x" and "y", and corresponding values in pixels (int or float).

Conventions for the input vertices:

  • The origin is the top left corner of the image.
  • x-axis is horizontal and goes from left to right.
  • y-axis is vertical and goes from top to bottom.

Conventions for the output points (top_left, bottom_left, bottom_right, top_right):

  • The origin is defined by the origin_location argument.
  • x-axis is horizontal and goes from left to right.
  • y-axis is vertical. If origin_location is "top_left", it goes from top to bottom. If origin_location is "bottom_left", it goes from bottom to top.

If the image width and height are provided, the output point coordinates will be scaled to the image size. If not, the method will return the output points' coordinates normalized to [0, 1].

Parameters:

Name Type Description Default
normalized_vertices List[Dict[str, float]]

A list of normalized vertices.

required
img_width Union[int, float]

Width of the image the bounding box is defined in.

None
img_height Union[int, float]

Height of the image the bounding box is defined in.

None
origin_location typing_extensions.Literal['top_left', 'bottom_left']

Location of the origin of output point coordinate system. Can be either top_left or bottom_left.

'bottom_left'

Returns:

Type Description
Dict[typing_extensions.Literal['top_left', 'bottom_left', 'bottom_right', 'top_right'], Dict[typing_extensions.Literal['x', 'y'], float]]

A dict with keys "top_left", "bottom_left", "bottom_right", "top_right", and corresponding points.

Example

from kili.utils.labels.bbox import normalized_vertices_to_bbox_points

normalized_vertices = label["jsonResponse"]["OBJECT_DETECTION_JOB"]["annotations"][0]["boundingPoly"][0]["normalizedVertices"]
img_height, img_width = 1080, 1920
bbox_points = normalized_vertices_to_bbox_points(normalized_vertices, img_width, img_height)
Source code in kili/utils/labels/bbox.py
def normalized_vertices_to_bbox_points(
    normalized_vertices: List[Dict[str, float]],
    img_width: Optional[Union[int, float]] = None,
    img_height: Optional[Union[int, float]] = None,
    origin_location: Literal["top_left", "bottom_left"] = "bottom_left",
) -> Dict[
    Literal["top_left", "bottom_left", "bottom_right", "top_right"], Dict[Literal["x", "y"], float]
]:
    # pylint: disable=line-too-long
    """Converts a rectangle normalizedVertices annotation to a bounding box defined by 4 points.

    It is the inverse of the method `bbox_points_to_normalized_vertices`.

    A point is a dict with keys `"x"` and `"y"`, and corresponding values in pixels (`int` or `float`).

    Conventions for the input vertices:

    - The origin is the top left corner of the image.
    - x-axis is horizontal and goes from left to right.
    - y-axis is vertical and goes from top to bottom.

    Conventions for the output points (`top_left`, `bottom_left`, `bottom_right`, `top_right`):

    - The origin is defined by the `origin_location` argument.
    - x-axis is horizontal and goes from left to right.
    - y-axis is vertical. If `origin_location` is `"top_left"`, it goes from top to bottom. If `origin_location` is `"bottom_left"`, it goes from bottom to top.

    If the image width and height are provided, the output point coordinates will be scaled to the image size.
    If not, the method will return the output points' coordinates normalized to `[0, 1]`.

    Args:
        normalized_vertices: A list of normalized vertices.
        img_width: Width of the image the bounding box is defined in.
        img_height: Height of the image the bounding box is defined in.
        origin_location: Location of the origin of output point coordinate system. Can be either `top_left` or `bottom_left`.

    Returns:
        A dict with keys `"top_left"`, `"bottom_left"`, `"bottom_right"`, `"top_right"`, and corresponding points.

    !!! Example
        ```python
        from kili.utils.labels.bbox import normalized_vertices_to_bbox_points

        normalized_vertices = label["jsonResponse"]["OBJECT_DETECTION_JOB"]["annotations"][0]["boundingPoly"][0]["normalizedVertices"]
        img_height, img_width = 1080, 1920
        bbox_points = normalized_vertices_to_bbox_points(normalized_vertices, img_width, img_height)
        ```
    """
    if len(normalized_vertices) != 4:
        raise ValueError(f"normalized_vertices must have length 4. Got {len(normalized_vertices)}.")

    if (img_width is None) != (img_height is None):
        raise ValueError("img_width and img_height must be both None or both not None.")

    img_height = img_height or 1
    img_width = img_width or 1

    ret = {}

    for vertex, point_name in zip(
        normalized_vertices, ("bottom_left", "top_left", "top_right", "bottom_right")
    ):
        ret[point_name] = normalized_point_to_point(
            vertex, img_width=img_width, img_height=img_height, origin_location=origin_location
        )

    return ret

Polygon and segmentation masks

kili.utils.labels.image

OpenCV

It is recommended to install the image dependencies to use the image helpers.

pip install kili[image-utils]

Helpers to create boundingPoly polygon and semantic annotations.

mask_to_normalized_vertices(image)

Converts a binary mask to a list of normalized vertices using OpenCV cv2.findContours.

The output can be used to create "boundingPoly" polygon or semantic annotations. See the documentation for more details.

Parameters:

Name Type Description Default
image ndarray

Binary mask. Should be an array of shape (height, width) with values in {0, 255}.

required

Returns:

Type Description
Tuple

A tuple containing a list of normalized vertices and the hierarchy of the contours (see OpenCV documentation).

Example

import urllib.request
import cv2
from kili.utils.labels.image import mask_to_normalized_vertices

mask_url = "https://raw.githubusercontent.com/kili-technology/kili-python-sdk/master/recipes/img/HUMAN.mask.png"
urllib.request.urlretrieve(mask_url, "mask.png")

img = cv2.imread("mask.png")[:, :, 0]  # keep only height and width
img[200:220, 200:220] = 0  # add a hole in the mask to test the hierarchy

contours, hierarchy = mask_to_normalized_vertices(img)
# hierarchy tells us that the first contour is the outer contour
# and the second one is the inner contour

json_response = {
    "OBJECT_DETECTION_JOB": {
        "annotations": [
            {
                "boundingPoly": [
                    {"normalizedVertices": contours[0]},  # outer contour
                    {"normalizedVertices": contours[1]},  # inner contour
                ],
                "categories": [{"name": "A"}],
                "type": "semantic",
            }
        ]
    }
}
Source code in kili/utils/labels/image.py
def mask_to_normalized_vertices(
    image: np.ndarray,
) -> Tuple[List[List[Dict[str, float]]], np.ndarray]:
    # pylint: disable=line-too-long
    """Converts a binary mask to a list of normalized vertices using OpenCV [cv2.findContours](https://docs.opencv.org/4.7.0/d3/dc0/group__imgproc__shape.html#gadf1ad6a0b82947fa1fe3c3d497f260e0).

    The output can be used to create "boundingPoly" polygon or semantic annotations.
    See the [documentation](https://docs.kili-technology.com/reference/export-object-entity-detection-and-relation#standard-object-detection) for more details.

    Args:
        image: Binary mask. Should be an array of shape (height, width) with values in {0, 255}.

    Returns:
        Tuple: A tuple containing a list of normalized vertices and the hierarchy of the contours (see [OpenCV documentation](https://docs.opencv.org/4.7.0/d9/d8b/tutorial_py_contours_hierarchy.html)).

    !!! Example
        ```python
        import urllib.request
        import cv2
        from kili.utils.labels.image import mask_to_normalized_vertices

        mask_url = "https://raw.githubusercontent.com/kili-technology/kili-python-sdk/master/recipes/img/HUMAN.mask.png"
        urllib.request.urlretrieve(mask_url, "mask.png")

        img = cv2.imread("mask.png")[:, :, 0]  # keep only height and width
        img[200:220, 200:220] = 0  # add a hole in the mask to test the hierarchy

        contours, hierarchy = mask_to_normalized_vertices(img)
        # hierarchy tells us that the first contour is the outer contour
        # and the second one is the inner contour

        json_response = {
            "OBJECT_DETECTION_JOB": {
                "annotations": [
                    {
                        "boundingPoly": [
                            {"normalizedVertices": contours[0]},  # outer contour
                            {"normalizedVertices": contours[1]},  # inner contour
                        ],
                        "categories": [{"name": "A"}],
                        "type": "semantic",
                    }
                ]
            }
        }
        ```
    """
    if image.ndim > 2:
        raise ValueError(f"Image should be a 2D array, got {image.ndim}D array")

    unique_values = np.unique(image).tolist()
    if not all(value in [0, 255] for value in unique_values):
        raise ValueError(f"Image should be binary with values in {{0, 255}}, got {unique_values}")

    img_height, img_width = image.shape
    # pylint:disable=no-member
    contours, hierarchy = cv2.findContours(image, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)  # type: ignore

    contours = [
        _opencv_contour_to_normalized_vertices(contour, img_width, img_height)
        for contour in contours
    ]
    hierarchy = hierarchy[0]

    return contours, hierarchy

normalized_vertices_to_mask(normalized_vertices, img_width, img_height)

Converts a Kili label with normalized vertices to a binary mask.

It is the inverse of the method mask_to_normalized_vertices.

Parameters:

Name Type Description Default
normalized_vertices List[Dict[str, float]]

A list of normalized vertices.

required
img_width Union[int, float]

Width of the image the segmentation is defined in.

required
img_height Union[int, float]

Height of the image the segmentation is defined in.

required

Returns:

Type Description
ndarray

A numpy array of shape (height, width) with values in {0, 255}.

Example

from kili.utils.labels.image import normalized_vertices_to_mask

normalized_vertices = label["jsonResponse"]["OBJECT_DETECTION_JOB"]["annotations"][0]["boundingPoly"][0]["normalizedVertices"]
img_height, img_width = 1080, 1920
mask = normalized_vertices_to_mask(normalized_vertices, img_width, img_height)
plt.imshow(mask)
plt.show()
Source code in kili/utils/labels/image.py
def normalized_vertices_to_mask(
    normalized_vertices: List[Dict[str, float]],
    img_width: Union[int, float],
    img_height: Union[int, float],
) -> np.ndarray:
    # pylint: disable=line-too-long
    """Converts a Kili label with normalized vertices to a binary mask.

    It is the inverse of the method `mask_to_normalized_vertices`.

    Args:
        normalized_vertices: A list of normalized vertices.
        img_width: Width of the image the segmentation is defined in.
        img_height: Height of the image the segmentation is defined in.

    Returns:
        A numpy array of shape (height, width) with values in {0, 255}.

    !!! Example
        ```python
        from kili.utils.labels.image import normalized_vertices_to_mask

        normalized_vertices = label["jsonResponse"]["OBJECT_DETECTION_JOB"]["annotations"][0]["boundingPoly"][0]["normalizedVertices"]
        img_height, img_width = 1080, 1920
        mask = normalized_vertices_to_mask(normalized_vertices, img_width, img_height)
        plt.imshow(mask)
        plt.show()
        ```
    """
    mask = np.zeros((img_height, img_width), dtype=np.uint8)
    polygon = [
        [
            int(round(vertice["x"] * img_width)),
            int(round(vertice["y"] * img_height)),
        ]
        for vertice in normalized_vertices
    ]
    polygon = np.array([polygon])
    cv2.fillPoly(img=mask, pts=polygon, color=255)  # type: ignore  # pylint:disable=no-member
    return mask