Skip to content

Instantly share code, notes, and snippets.

View rfezzani's full-sized avatar

Riadh Fezzani rfezzani

  • VitaDX
  • Paris, France
View GitHub Profile
@rfezzani
rfezzani / get_crop.py
Last active September 27, 2023 07:00
Crop extraction from tiled TIFF image file directory without whole page loading using tifffile
from tifffile import TiffFile
import numpy as np
def get_crop(page, i0, j0, h, w):
"""Extract a crop from a TIFF image file directory (IFD).
Only the tiles englobing the crop area are loaded and not the whole page.
This is usefull for large Whole slide images that can't fit int RAM.
@rfezzani
rfezzani / argfix.py
Last active September 13, 2019 08:13
Python decorator to ensure backward compatibility if function's argument name is modified
"""Decorator ensuring backward compatibility when an argument name is
modified in a function definition.
# Use case
Let's suppose that in a previous version, the function `func` was defined
with the `old_arg` argument name:
```python
def func(old_arg, arg=0):