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
pools: tuple[int, ...] = slide.pools
spacing: float = slide.spacing # X um per pixel
image: np.ndarray = slide[:2048, :2048] # Get numpy.ndarray of 2048x2048 from 1:1 level
mini = slide.pool(4) # 1:4 scale, shape is 4x smaller then full resolution
image: np.ndarray = mini[:512, :512] # Same view as `image`, but lower resolution
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')
# Get view at 1:4 scale of slide. `s4.shape` = `s.shape` / 4.
# 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.pool(4)
# Get iterator over tiles.
# Reads will be at [0:512], [512:1024] ... @ 1:4 scale
# or [0:2048], [2048:4096], ... @ 1:1, each downscaled to 512px
tiles = m.iterate(s4)
# Read only subset of tiles according to binary mask (1s are read, 0s are not).
# `mask.shape` * `scale` = `s4.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.9+. Tested on ArchLinux, Ubuntu 18.04/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.3.9.tar.gz
(23.5 kB
view hashes)
Built Distribution
Close
Hashes for bipl-0.3.9-py3-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 58c0d7cff2a98b2a2a99a3856a4c5a758e084512971b0ca3d9c8306c9e93c2a4 |
|
MD5 | 3d128168df73f525807a8d03d8019a68 |
|
BLAKE2b-256 | 8e7af3c43bbfacb43d5cd0316d76abe8790d95ba72bda14e449402d36375f69d |