Skip to content

Instantly share code, notes, and snippets.

@sukhitashvili
Created January 13, 2023 13:30
Show Gist options
  • Save sukhitashvili/ea51eaa7a510432782f67e93a7226b83 to your computer and use it in GitHub Desktop.
Save sukhitashvili/ea51eaa7a510432782f67e93a7226b83 to your computer and use it in GitHub Desktop.
Resized coordinates
def resize_coordinates(coords: np.ndarray, old_size: tuple, new_size: tuple):
"""
:param coords: coordinates as numpy array of shape (N, 2) [x, y] format
:param old_size: old size as (width, height)
:param new_size: new size as (width, height)
:return: resized coordinates as numpy array of shape (N, 2)
"""
# Calculate the scale factor
scale_factor = np.array(new_size) / np.array(old_size)
# Scale the coordinates
coords = np.round(coords.reshape(-1, 2) * scale_factor).astype(int)
return coords
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment