Created
January 13, 2023 13:30
-
-
Save sukhitashvili/ea51eaa7a510432782f67e93a7226b83 to your computer and use it in GitHub Desktop.
Resized coordinates
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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