garmentiq.landmark.utils

Helpers for mapping landmarks onto a measurement instruction.

 1"""Helpers for mapping landmarks onto a measurement instruction."""
 2import numpy as np
 3
 4
 5def find_instruction_landmark_index(instruction_landmarks: dict, predefined: bool):
 6    """
 7    Finds the indices of predefined or non-predefined landmarks from an instruction landmarks dictionary.
 8
 9    Args:
10        instruction_landmarks (dict): A dictionary of landmark information from an instruction schema.
11        predefined (bool): If True, returns indices of predefined landmarks.
12                           If False, returns indices of non-predefined (derived) landmarks.
13
14    Returns:
15        list: A list of integer indices (0-based) for the requested type of landmarks.
16    """
17    if predefined:
18        return [
19            int(k) - 1
20            for k, v in instruction_landmarks.items()
21            if v.get("predefined") is True
22        ]
23    else:
24        return [
25            int(k) - 1
26            for k, v in instruction_landmarks.items()
27            if v.get("predefined") is False
28        ]
29
30
31def fill_instruction_landmark_coordinate(
32    instruction_landmarks: dict, index: list, fill_in_value: np.array
33):
34    """
35    Fills the 'x' and 'y' coordinates for specified landmarks in the instruction dictionary
36    based on provided coordinate values.
37
38    Args:
39        instruction_landmarks (dict): The dictionary of landmark instructions to be updated.
40        index (list): A list of integer indices (0-based) corresponding to the landmarks
41                      in `instruction_landmarks` that should be updated.
42        fill_in_value (np.array): A NumPy array containing the new coordinates.
43                                  Expected shape: (1, N, 2), where N is the number of landmarks to fill.
44
45    Returns:
46        dict: The updated `instruction_landmarks` dictionary with filled coordinates.
47    """
48    for k in instruction_landmarks:
49        idx = int(k) - 1
50        if idx in index:
51            preds_idx = index.index(idx)
52            instruction_landmarks[k]["x"] = float(fill_in_value[0, preds_idx, 0])
53            instruction_landmarks[k]["y"] = float(fill_in_value[0, preds_idx, 1])
54    return instruction_landmarks
def find_instruction_landmark_index(instruction_landmarks: dict, predefined: bool):
 6def find_instruction_landmark_index(instruction_landmarks: dict, predefined: bool):
 7    """
 8    Finds the indices of predefined or non-predefined landmarks from an instruction landmarks dictionary.
 9
10    Args:
11        instruction_landmarks (dict): A dictionary of landmark information from an instruction schema.
12        predefined (bool): If True, returns indices of predefined landmarks.
13                           If False, returns indices of non-predefined (derived) landmarks.
14
15    Returns:
16        list: A list of integer indices (0-based) for the requested type of landmarks.
17    """
18    if predefined:
19        return [
20            int(k) - 1
21            for k, v in instruction_landmarks.items()
22            if v.get("predefined") is True
23        ]
24    else:
25        return [
26            int(k) - 1
27            for k, v in instruction_landmarks.items()
28            if v.get("predefined") is False
29        ]

Finds the indices of predefined or non-predefined landmarks from an instruction landmarks dictionary.

Arguments:
  • instruction_landmarks (dict): A dictionary of landmark information from an instruction schema.
  • predefined (bool): If True, returns indices of predefined landmarks. If False, returns indices of non-predefined (derived) landmarks.
Returns:

list: A list of integer indices (0-based) for the requested type of landmarks.

def fill_instruction_landmark_coordinate( instruction_landmarks: dict, index: list, fill_in_value: <built-in function array>):
32def fill_instruction_landmark_coordinate(
33    instruction_landmarks: dict, index: list, fill_in_value: np.array
34):
35    """
36    Fills the 'x' and 'y' coordinates for specified landmarks in the instruction dictionary
37    based on provided coordinate values.
38
39    Args:
40        instruction_landmarks (dict): The dictionary of landmark instructions to be updated.
41        index (list): A list of integer indices (0-based) corresponding to the landmarks
42                      in `instruction_landmarks` that should be updated.
43        fill_in_value (np.array): A NumPy array containing the new coordinates.
44                                  Expected shape: (1, N, 2), where N is the number of landmarks to fill.
45
46    Returns:
47        dict: The updated `instruction_landmarks` dictionary with filled coordinates.
48    """
49    for k in instruction_landmarks:
50        idx = int(k) - 1
51        if idx in index:
52            preds_idx = index.index(idx)
53            instruction_landmarks[k]["x"] = float(fill_in_value[0, preds_idx, 0])
54            instruction_landmarks[k]["y"] = float(fill_in_value[0, preds_idx, 1])
55    return instruction_landmarks

Fills the 'x' and 'y' coordinates for specified landmarks in the instruction dictionary based on provided coordinate values.

Arguments:
  • instruction_landmarks (dict): The dictionary of landmark instructions to be updated.
  • index (list): A list of integer indices (0-based) corresponding to the landmarks in instruction_landmarks that should be updated.
  • fill_in_value (np.array): A NumPy array containing the new coordinates. Expected shape: (1, N, 2), where N is the number of landmarks to fill.
Returns:

dict: The updated instruction_landmarks dictionary with filled coordinates.