Skip to content

Instantly share code, notes, and snippets.

View arenaudineau's full-sized avatar
🙂

Adrien Renaudineau arenaudineau

🙂
View GitHub Profile
@arenaudineau
arenaudineau / resize_img.py
Last active July 20, 2023 08:32
Python function to conveniently resize an image and preserve pixel size. This was found useful to change extent for plt.imshow
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.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@arenaudineau
arenaudineau / B1530Lib.ipynb
Created June 29, 2022 19:29
B1530Lib demo
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@arenaudineau
arenaudineau / stderr_redirect.py
Last active June 28, 2022 06:58 — forked from natedileas/redirect.py
c-level stderr redirection on windows, compatible with Jupyter Notebooks
"""
!! 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: