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