Skip to main content

tifffile-based drop-in replacement for openslide-python

Project description

tiffslide: a drop-in replacement for openslide-python

PyPI Version Conda (channel only) tiffslide ci GitHub issues PyPI - Downloads PyPI - Python Version DOI

Welcome to tiffslide :wave:, a tifffile based drop-in replacement for openslide-python.

tiffslide's goal is to provide an easy way to migrate existing code from an openslide dependency to the excellently maintained tifffile module.

We strive to make your lives as easy as possible: If using tiffslide is unintuitive, slow, or if it's drop-in behavior differs from what you expect, it's a bug in tiffslide. Feel free to report any issues or feature requests in the issue tracker!

Development happens on github :octocat:

Notes

TiffSlide aims to be compatible with all formats that openslide supports and more, but not all are implemented yet. Aperio SVS is currently the most tested format. Contributions to expand to a larger variety of file formats that tifffile supports are very welcome :heart:
If there are any questions open an issue, and we'll do our best to help!

Compatibility

Here's a list with currently supported formats.

File Format can be opened full support references
Aperio SVS :white_check_mark: :white_check_mark:
Generic TIFF :white_check_mark: :white_check_mark:
Hamamatsu NDPI :white_check_mark: :warning: #35
Leica SCN :white_check_mark: :white_check_mark:
Ventana :warning: :warning: #37
Hamamatsu VMS :no_entry_sign: :no_entry_sign:
DICOM :no_entry_sign: :no_entry_sign: #32
Mirax :no_entry_sign: :no_entry_sign: #33
Zeiss ZVI :no_entry_sign: :no_entry_sign:

Documentation

Installation

tiffslide's stable releases can be installed via pip:

pip install tiffslide

Or via conda:

conda install -c conda-forge tiffslide

Usage

tiffslide's behavior aims to be identical to openslide-python where it makes sense. If you rely heavily on the internals of openslide, this is not the package you are looking for. In case we add more features, we will add documentation here.

as a drop-in replacement

# directly
from tiffslide import TiffSlide
slide = TiffSlide('path/to/my/file.svs')

# or via its drop-in behavior
import tiffslide as openslide
slide = openslide.OpenSlide('path/to/my/file.svs')

access files in the cloud

A nice side effect of using tiffslide is that your code will also work with filesystem_spec, which enables you to access your whole slide images from various supported filesystems:

import fsspec
from tiffslide import TiffSlide

# read from any io buffer
with fsspec.open("s3://my-bucket/file.svs") as f:
    slide = TiffSlide(f)
    thumb = slide.get_thumbnail((200, 200))

# read from fsspec urlpaths directly, using your AWS_PROFILE 'aws'
slide = TiffSlide("s3://my-bucket/file.svs", storage_options={'profile': 'aws'})
thumb = slide.get_thumbnail((200, 200))

# read via fsspec from google cloud and use fsspec's caching mechanism to cache locally
slide = TiffSlide("simplecache::gcs://my-bucket/file.svs", storage_options={'project': 'my-project'})
region = slide.read_region((300, 400), 0, (512, 512))

read numpy arrays instead of PIL images

Very often you'd actually want your region returned as a numpy array instead getting a PIL Image and then having to convert to numpy:

import numpy as np
from tiffslide import TiffSlide

slide = TiffSlide("myfile.svs")
arr = slide.read_region((100, 200), 0, (256, 256), as_array=True)
assert isinstance(arr, np.ndarray)

Development Installation

If you want to help improve tiffslide, you can setup your development environment in two different ways:

With conda:

  1. Clone tiffslide git clone https://github.com/bayer-science-for-a-better-life/tiffslide.git
  2. cd tiffslide
  3. conda env create -f environment.devenv.yml
  4. Activate the environment conda activate tiffslide

Without conda:

  1. Clone tiffslide git clone https://github.com/bayer-science-for-a-better-life/tiffslide.git
  2. cd tiffslide
  3. python -m venv venv && source venv/bin/activate && python -m pip install -U pip
  4. pip install -e .[dev]

Note that in these environments tiffslide is already installed in development mode, so go ahead and hack.

Benchmarks

Here are some benchmarks comparing tiffslide to openslide for different supported file types and access patterns. Please note that you should test the difference in access time always for yourself on your target machine and your specific use case.

In case you would like a specific use case to be added, please feel free to open an issue or make a pull request.

The plots below were generated on a Thinkpad E495 and the files were stored on the internal ssd. Note, that in general, on my test my machine, tiffslide outperforms openslide when reading data as numpy arrays. Ventana tile reading is not "correct" since as of now (1.5.0) tiffslide lacks compositing for the overlapping tiles.

See the docs/README.md to run the benchmarks on your own machine.

reading PIL images

access times reading PIL

reading Numpy arrays

access times reading numpy

Contributing Guidelines

  • Please follow pep-8 conventions but:
    • We allow 120 character long lines (try anyway to keep them short)
  • Please use numpy docstrings.
  • When contributing code, please try to use Pull Requests.
  • tests go hand in hand with modules on tests packages at the same level. We use pytest.

You can setup your IDE to help you adhering to these guidelines.
(Santi is happy to help you setting up pycharm in 5 minutes)

Acknowledgements

Build with love by Andreas Poehlmann and Santi Villalba from the Machine Learning Research group at Bayer.

tiffslide: copyright 2020 Bayer AG, licensed under BSD

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

tiffslide-2.4.0.tar.gz (748.9 kB view details)

Uploaded Source

Built Distribution

tiffslide-2.4.0-py3-none-any.whl (32.3 kB view details)

Uploaded Python 3

File details

Details for the file tiffslide-2.4.0.tar.gz.

File metadata

  • Download URL: tiffslide-2.4.0.tar.gz
  • Upload date:
  • Size: 748.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.8

File hashes

Hashes for tiffslide-2.4.0.tar.gz
Algorithm Hash digest
SHA256 630bc36215e950dd9df279ded147cf129570f2040c7e3363cdf6845414da9672
MD5 d2d5ed91cdd4f5b715bffe4466131133
BLAKE2b-256 268a90fc9e812644f037b182453b3b2ab95f4041cc4d226e88ad13c22b0ccb12

See more details on using hashes here.

File details

Details for the file tiffslide-2.4.0-py3-none-any.whl.

File metadata

  • Download URL: tiffslide-2.4.0-py3-none-any.whl
  • Upload date:
  • Size: 32.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.8

File hashes

Hashes for tiffslide-2.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f12964dd6356abc970efda6697fd4791147139dac9efc11ea008eec6883db35c
MD5 e0a69c80872ab5aa7c771099614a1b5d
BLAKE2b-256 dda6020c310f220e6f0941c9433f5ff86b498239f5eb6f246512ca3e8cd2ac64

See more details on using hashes here.

Supported by

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