dlup.experimental_backends package#

Submodules#

dlup.experimental_backends.openslide_backend module#

class dlup.experimental_backends.openslide_backend.OpenSlideSlide(filename: Union[str, pathlib.Path])[source]#

Bases: openslide.OpenSlide, dlup.backends.common.AbstractSlideBackend

Backend for openslide.

Parameters
filenamePathLike

Path to image.

property color_profile: PIL.ImageCms.ImageCmsProfile | None#

Returns the color profile of the image if available. Otherwise returns None.

Returns
ImageCmsProfile, optional

The color profile of the image.

get_thumbnail(size: int | tuple[int, int]) PIL.Image.Image[source]#

Return a PIL.Image as an RGB image with the thumbnail with maximum size given by size. Aspect ratio is preserved.

Parameters
sizeint or tuple[int, int]

Output size of the thumbnail, will take the maximal value for the output and preserve aspect ratio.

Returns
PIL.Image

The thumbnail.

property magnification: int | None#

Returns the objective power at which the WSI was sampled.

property mode: str#

Returns the mode of the image. For OpenSlide this is always RGBA

property slide_bounds: tuple[tuple[int, int], tuple[int, int]]#

Returns the bounds of the slide as ((x,y), (width, height)). These can be smaller than the image itself.

property spacing: tuple[float, float] | None#

A (mpp_x, mpp_y) tuple for spacing of the base level

Returns
Tuple
property vendor: str | None#

Returns the scanner vendor.

dlup.experimental_backends.openslide_backend.open_slide(filename: Union[str, pathlib.Path]) dlup.experimental_backends.openslide_backend.OpenSlideSlide[source]#

Read slide with openslide.

Parameters
filenamePathLike

Path to image.

dlup.experimental_backends.pyvips_backend module#

class dlup.experimental_backends.pyvips_backend.PyVipsSlide(filename: Union[str, pathlib.Path])[source]#

Bases: dlup.backends.common.AbstractSlideBackend

Backend for pyvips.

Parameters
filenamePathLike

Path to image.

property associated_images: dict[str, PIL.Image.Image]#

Images associated with this whole-slide image.

close() None[source]#

Close the underlying slide

property color_profile: PIL.ImageCms.ImageCmsProfile | None#

Returns the color profile of the image if available. Otherwise returns None.

Returns
ImageCmsProfile, optional

The color profile of the image.

property magnification: float | None#

Returns the objective power at which the WSI was sampled.

property mode: str | None#

Returns the mode of the image.

property properties: dict[str, Any]#

Metadata about the image as given by pyvips, which includes openslide tags in case openslide is the selected reader.

read_region(coordinates: tuple[Any, ...], level: int, size: tuple[Any, ...]) PIL.Image.Image[source]#

Return the best level for displaying the given image level.

Parameters
coordinatestuple

Coordinates of the region in level 0.

levelint

Level of the image pyramid.

sizetuple

Size of the region to be extracted.

Returns
PIL.Image

The requested region.

set_cache(cache: Any) None[source]#
property slide_bounds: tuple[tuple[int, int], tuple[int, int]]#

Returns the bounds of the slide as ((x,y), (width, height)). These can be smaller than the image itself.

property spacing: tuple[float, float] | None#

A (mpp_x, mpp_y) tuple for spacing of the base level

Returns
Tuple
property vendor: str | None#

Returns the scanner vendor.

dlup.experimental_backends.pyvips_backend.open_slide(filename: Union[str, pathlib.Path]) dlup.experimental_backends.pyvips_backend.PyVipsSlide[source]#

Read slide with pyvips.

Parameters
filenamePathLike

Path to image.

Module contents#

class dlup.experimental_backends.ImageBackend(value)[source]#

Bases: enum.Enum

Available image experimental_backends.

AUTODETECT() dlup.backends.common.AbstractSlideBackend[source]#

Try to read the file in consecutive order of pyvips, openslide, tifffile, by trying to a tile at the lowest resolution. The results are cached, so the test is only performed once per filename.

Parameters
filename
Returns
AbstractSlideBackend

A backend which is able to read the image.

OPENSLIDE: Callable[[Union[str, pathlib.Path]], dlup.experimental_backends.openslide_backend.OpenSlideSlide] = <class 'dlup.experimental_backends.openslide_backend.OpenSlideSlide'>#
PYVIPS: Callable[[Union[str, pathlib.Path]], dlup.experimental_backends.pyvips_backend.PyVipsSlide] = <class 'dlup.experimental_backends.pyvips_backend.PyVipsSlide'>#
TIFFFILE: Callable[[Union[str, pathlib.Path]], dlup.backends.tifffile_backend.TifffileSlide] = <class 'dlup.backends.tifffile_backend.TifffileSlide'>#
dlup.experimental_backends.autodetect_backend(filename: Union[str, pathlib.Path]) dlup.backends.common.AbstractSlideBackend[source]#

Try to read the file in consecutive order of pyvips, openslide, tifffile, by trying to a tile at the lowest resolution. The results are cached, so the test is only performed once per filename.

Parameters
filename
Returns
AbstractSlideBackend

A backend which is able to read the image.