garmentiq.landmark.derive

 1import copy
 2from garmentiq.landmark.derivation import (
 3    prepare_args,
 4    process,
 5)
 6
 7
 8def derive(
 9    class_name: str, detection_dict: dict, derivation_dict: dict, **extra_args
10) -> dict:
11    """
12    Derives non-predefined landmark coordinates based on predefined landmarks and a mask.
13
14    This function identifies landmarks marked for derivation within the `detection_dict`,
15    prepares arguments for the derivation function using `prepare_args`,
16    processes the derivation using `process`, and updates the `detection_dict`
17    with the newly derived coordinates.
18
19    Args:
20        class_name (str): The name of the garment class.
21        detection_dict (dict): The dictionary containing detected landmarks, including predefined ones.
22        derivation_dict (dict): The dictionary defining derivation rules and available functions.
23        **extra_args: Additional keyword arguments required by the derivation functions,
24                      such as `landmark_coords` (NumPy array of landmark coordinates)
25                      and `np_mask` (NumPy array of the segmentation mask).
26
27    Returns:
28        dict: A tuple containing:
29            - derived_coords (dict): A dictionary mapping the derived landmark IDs to their new (x, y) coordinates.
30            - detection_dict (dict): The original `detection_dict` updated with the derived landmark coordinates.
31    """
32    non_predefined_landmark = {
33        k: detection_dict[class_name]["landmarks"][k]["derivation"]
34        for k, v in detection_dict[class_name]["landmarks"].items()
35        if v.get("predefined") is False
36    }
37    derived_coords = {}
38    detection_dict_copy = copy.deepcopy(detection_dict)
39    for k, v in non_predefined_landmark.items():
40        args = prepare_args(non_predefined_landmark[k], derivation_dict, **extra_args)
41        derived_coord = tuple(float(x) for x in process(**args))
42        derived_coords[k] = derived_coord
43        detection_dict_copy[class_name]["landmarks"][k]["x"] = derived_coord[0]
44        detection_dict_copy[class_name]["landmarks"][k]["y"] = derived_coord[1]
45    return derived_coords, detection_dict_copy
def derive( class_name: str, detection_dict: dict, derivation_dict: dict, **extra_args) -> dict:
 9def derive(
10    class_name: str, detection_dict: dict, derivation_dict: dict, **extra_args
11) -> dict:
12    """
13    Derives non-predefined landmark coordinates based on predefined landmarks and a mask.
14
15    This function identifies landmarks marked for derivation within the `detection_dict`,
16    prepares arguments for the derivation function using `prepare_args`,
17    processes the derivation using `process`, and updates the `detection_dict`
18    with the newly derived coordinates.
19
20    Args:
21        class_name (str): The name of the garment class.
22        detection_dict (dict): The dictionary containing detected landmarks, including predefined ones.
23        derivation_dict (dict): The dictionary defining derivation rules and available functions.
24        **extra_args: Additional keyword arguments required by the derivation functions,
25                      such as `landmark_coords` (NumPy array of landmark coordinates)
26                      and `np_mask` (NumPy array of the segmentation mask).
27
28    Returns:
29        dict: A tuple containing:
30            - derived_coords (dict): A dictionary mapping the derived landmark IDs to their new (x, y) coordinates.
31            - detection_dict (dict): The original `detection_dict` updated with the derived landmark coordinates.
32    """
33    non_predefined_landmark = {
34        k: detection_dict[class_name]["landmarks"][k]["derivation"]
35        for k, v in detection_dict[class_name]["landmarks"].items()
36        if v.get("predefined") is False
37    }
38    derived_coords = {}
39    detection_dict_copy = copy.deepcopy(detection_dict)
40    for k, v in non_predefined_landmark.items():
41        args = prepare_args(non_predefined_landmark[k], derivation_dict, **extra_args)
42        derived_coord = tuple(float(x) for x in process(**args))
43        derived_coords[k] = derived_coord
44        detection_dict_copy[class_name]["landmarks"][k]["x"] = derived_coord[0]
45        detection_dict_copy[class_name]["landmarks"][k]["y"] = derived_coord[1]
46    return derived_coords, detection_dict_copy

Derives non-predefined landmark coordinates based on predefined landmarks and a mask.

This function identifies landmarks marked for derivation within the detection_dict, prepares arguments for the derivation function using prepare_args, processes the derivation using process, and updates the detection_dict with the newly derived coordinates.

Arguments:
  • class_name (str): The name of the garment class.
  • detection_dict (dict): The dictionary containing detected landmarks, including predefined ones.
  • derivation_dict (dict): The dictionary defining derivation rules and available functions.
  • **extra_args: Additional keyword arguments required by the derivation functions, such as landmark_coords (NumPy array of landmark coordinates) and np_mask (NumPy array of the segmentation mask).
Returns:

dict: A tuple containing: - derived_coords (dict): A dictionary mapping the derived landmark IDs to their new (x, y) coordinates. - detection_dict (dict): The original detection_dict updated with the derived landmark coordinates.