This file contains 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
from typing import Any, Tuple | |
def resize_img(img: np.ndarray, extent_from: Tuple[int, int, int, int], extent_to: Tuple[int, int, int, int], fill_value: Any = 0): | |
""" | |
Resize an image to a new extent, keeping the pixels size. | |
The image is cropped if the new extent is smaller than the old one. | |
The image is padded with fill_value if the new extent is larger than the old one. | |
Parameters: | |
img (numpy.ndarray): Input image as a NumPy array. | |
extent_from (tuple): Tuple (left, right, top, bottom) representing the current extent of the image. |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains 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
""" | |
!! ADAPTED FROM https://gist.github.com/natedileas/8eb31dc03b76183c0211cdde57791005 !! | |
""" | |
from contextlib import contextmanager | |
import io, os, sys, ctypes, tempfile | |
if sys.version_info < (3, 5): | |
libc = ctypes.CDLL(ctypes.util.find_library('c')) | |
else: |