Skip to content

Commit

Permalink
Add docstrings for _scale_coords and _bounding_box methods for better…
Browse files Browse the repository at this point in the history
… clarity
  • Loading branch information
stefanklut committed Dec 19, 2024
1 parent 690d84b commit 490f5f3
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions page_xml/xml_converters/xml_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,32 @@ def convert(

@staticmethod
def _scale_coords(coords: np.ndarray, out_size: tuple[int, int], size: tuple[int, int]) -> np.ndarray:
"""
Scale coordinates to a new size
Args:
coords (np.ndarray): the coordinates to scale
out_size (tuple[int, int]): the size of the output image
size (tuple[int, int]): the size of the input image
Returns:
np.ndarray: the scaled coordinates
"""
scale_factor = (np.asarray(out_size) - 1) / (np.asarray(size) - 1)
scaled_coords = (coords * scale_factor[::-1]).astype(np.float32)
return scaled_coords

@staticmethod
def _bounding_box(array: np.ndarray) -> list[float]:
"""
Get the bounding box of an array of coordinates
Args:
array (np.ndarray): array of coordinates
Returns:
list[float]: bounding box of the array
"""
min_x, min_y = np.min(array, axis=0)
max_x, max_y = np.max(array, axis=0)
bbox = np.asarray([min_x, min_y, max_x, max_y]).astype(np.float32).tolist()
Expand Down

0 comments on commit 490f5f3

Please sign in to comment.