https://github.com/arquolo/bipl
Big Image Python Library
https://github.com/arquolo/bipl
computer-vision image-processing openslide python tiff
Last synced: 4 months ago
JSON representation
Big Image Python Library
- Host: GitHub
- URL: https://github.com/arquolo/bipl
- Owner: arquolo
- License: mit
- Created: 2023-02-26T21:11:49.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2025-06-08T13:38:11.000Z (4 months ago)
- Last Synced: 2025-06-08T14:29:12.869Z (4 months ago)
- Topics: computer-vision, image-processing, openslide, python, tiff
- Language: Python
- Homepage:
- Size: 354 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# BIPL is a Big Image Python Library
Library to read big pyramidal images like in formats like BigTiff, Aperio SVS, Leica MRXS.
## `bipl.Slide` - ndarray-like reader for multiscale images (svs, tiff, etc...)
```python
import numpy as np
from bipl import Slideslide = Slide.open('test.svs')
shape: tuple[int, ...] = slide.shape # Native shape
downsamples: tuple[int, ...] = slide.downsamples # List of pre-existing sub-resolution levels# Get native miniature
tmb: np.ndarray = slide.thumbnail()mpp: float = slide.mpp # X um per pixel, native resolution
image: np.ndarray = slide[:2048, :2048] # Get numpy.ndarray of 2048x2048 from full resolutionMPP = 16. # Let's say we want slide at 16 um/px resolution
downsample = MPP / slide.mpp
mini = slide.pool(downsample) # Gives `downsample`-times smaller image
mini = slide.resample(MPP) # Gives the same result# Those ones trigger ndarray conversion
image: np.ndarray
image = mini[:512, :512] # Take a part of
image = mini.numpy() # Take a whole resolution level
image = np.array(mini, copy=False) # Use __array__ API
```## `bipl.Mosaic` - apply function for each tile of big image on desired scale.
```python
import numpy as np
from bipl import Mosaic, Slidem = Mosaic(step=512, overlap=0) # Read at [0:512], [512:1024], ...
# Open slide at 1:1 scale
s = Slide.open('test.svs')# Target at 4 um/px resolution
# If `test.svs` has some pyramid in it (i.e. 1:1, 1:4, 1:16), it will be used to speed up reads.
s4 = s.resample(mpp=4.0)# Get iterator over tiles.
# Reads will be at [0:512], [512:1024] ... @ MPP
tiles = m.iterate(s4)# Read only subset of tiles according to binary mask (1s are read, 0s are not).
# `s4.shape * scale = mask.shape`, `scale <= 1`
tiles = tiles.select(mask, scale)# Read all data, trigger I/O. All the previous calls do not trigger any disk reads beyond metadata.
images: list[np.ndarray] = [*tiles]
```## Installation
```bash
pip install bipl
```
bipl is compatible with: Python 3.10+.
Tested on ArchLinux, Ubuntu 20.04/22.04, Windows 10/11.