Skip to main content

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.13+. Tested on Ubuntu & Windows.

DeepZoom server

To start use:

pip install bipl[deepzoom]
export SLIDES=~/slides
uvicorn bipl.dzi:app --workers 4 --host 0.0.0.0 --port 8000

Or you can just use a router from there:

from bipl.dzi import router

your_fastapi_app.include_router(router)

Project details


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.7.2.11.tar.gz (47.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

bipl-0.7.2.11-py3-none-win_amd64.whl (56.4 kB view details)

Uploaded Python 3Windows x86-64

File details

Details for the file bipl-0.7.2.11.tar.gz.

File metadata

  • Download URL: bipl-0.7.2.11.tar.gz
  • Upload date:
  • Size: 47.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for bipl-0.7.2.11.tar.gz
Algorithm Hash digest
SHA256 8b26358ef1cffc965d4f2c2440ba3d0c2446535e4e9d576bbcc750e16e31fdac
MD5 758a03960b0c058031f43ff8b2ea88fb
BLAKE2b-256 6d6194f249541071891f8ec45d9c9bd10ffe36a897d94e743847b46b75383aff

See more details on using hashes here.

Provenance

The following attestation bundles were made for bipl-0.7.2.11.tar.gz:

Publisher: publish.yaml on arquolo/bipl

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file bipl-0.7.2.11-py3-none-win_amd64.whl.

File metadata

  • Download URL: bipl-0.7.2.11-py3-none-win_amd64.whl
  • Upload date:
  • Size: 56.4 kB
  • Tags: Python 3, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for bipl-0.7.2.11-py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 7f29fc3fb98ed7a67f41f6e1a4fb23acfd0d1d6246eba586e1cbfbbe79c44ea8
MD5 8eda8645cb0b0b2b8603c8beb5fd6da0
BLAKE2b-256 503a6a6d59d07e975e25fbb1246504a1a9ddcd95e82066fac8be246e89fd901a

See more details on using hashes here.

Provenance

The following attestation bundles were made for bipl-0.7.2.11-py3-none-win_amd64.whl:

Publisher: publish.yaml on arquolo/bipl

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page