Openslide/libtiff/GDAL ndarray-like interface and lazy parallel tile-based processing
Project description
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...)
import numpy as np
from bipl import Slide
slide = 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 resolution
MPP = 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.
import numpy as np
from bipl import Mosaic, Slide
m = 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
pip install bipl
bipl is compatible with: Python 3.10+. Tested on ArchLinux, Ubuntu 20.04/22.04, Windows 10/11.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
bipl-0.6.1.tar.gz
(39.1 kB
view details)
Built Distribution
File details
Details for the file bipl-0.6.1.tar.gz
.
File metadata
- Download URL: bipl-0.6.1.tar.gz
- Upload date:
- Size: 39.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | adef25f1bc9cf138a1fcf69137a9914999b0c1aa811cfd876841878da722cdf6 |
|
MD5 | 32d304ba454d888859da50ec11b4fdc3 |
|
BLAKE2b-256 | a9c5fe7d1b3923d5ab316d432cdd634eebf3b45b67059bec9a7dbe940cbd9656 |
File details
Details for the file bipl-0.6.1-py3-none-win_amd64.whl
.
File metadata
- Download URL: bipl-0.6.1-py3-none-win_amd64.whl
- Upload date:
- Size: 4.6 MB
- Tags: Python 3, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1b6d50738148cbd6148917e3649575f9a913f2ec02b1f0eb6b49f1ee3c223970 |
|
MD5 | 3cf7b955bad21f2a39abbc0e3c8d7b24 |
|
BLAKE2b-256 | 1fe8ecff15eeff7cd00c71b9169af9d720d0e2c2fff6414a2b9d51dfbb7c0289 |