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.

Revisions

  1. sukhitashvili created this gist Jan 13, 2023.
    14 changes: 14 additions & 0 deletions resize_coords.pu
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,14 @@
    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