dlup.backends package#

Submodules#

dlup.backends.common module#

class dlup.backends.common.AbstractSlideBackend(filename: Union[str, pathlib.Path])[source]#

Bases: abc.ABC

Abstract base class for slide experimental_backends

Parameters
filenamePathLike

Path to image.

abstract close() None[source]#

Close the underlying slide

property color_profile: PIL.ImageCms.ImageCmsProfile | None#
property dimensions: tuple[int, int]#

A (width, height) tuple for the base level (level 0) of the image.

Returns
Tuple
get_best_level_for_downsample(downsample: float) int[source]#

Compute the best level for displaying the given downsample. Returns the closest better resolution.

Parameters
downsamplefloat
Returns
int
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 level_count: int#

The number of levels in the image.

property level_dimensions: list[tuple[int, int]]#

A list of (width, height) tuples, one for each level of the image. This property level_dimensions[n] contains the dimensions of the image at level n.

Returns
list
property level_downsamples: tuple[float, ...]#

A tuple of downsampling factors for each level of the image. level_downsample[n] contains the downsample factor of level n.

property level_spacings: tuple[tuple[float, float], ...]#

A list of (mpp_x, mpp_y) tuples, one for each level of the image. This property level_spacings[n] contains the spacings of the image at level n.

Returns
Tuple
abstract property magnification: float | None#

Returns the objective power at which the WSI was sampled.

property mode: str | None#

Returns the mode of the image.

abstract property properties: dict[str, Any]#

Properties of slide

abstract read_region(coordinates: tuple[Union[int, float], Union[int, float]], level: int, size: tuple[int, int]) 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.

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

Returns the bounds of the slide. 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
abstract property vendor: str | None#

Returns the scanner vendor.

dlup.backends.common.numpy_to_pil(tile: numpy.ndarray[Any, numpy.dtype[numpy.uint8]]) PIL.Image.Image[source]#

Convert a numpy tile to a PIL image, assuming the last axis is the channels

Parameters
tilenp.ndarray
Returns
PIL.Image

dlup.backends.tifffile_backend module#

class dlup.backends.tifffile_backend.TifffileSlide(filename: Union[str, pathlib.Path])[source]#

Bases: dlup.backends.common.AbstractSlideBackend

Backend for tifffile.

Parameters
filenamePathLike

Path to image.

close() None[source]#

Close the underlying slide

property magnification: None#

Returns the objective power at which the WSI was sampled. For tiff’s this is unknown.

property properties: dict[str, Any]#

Metadata about the image as given by tifffile.

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]#

Cache for tifffile.

property vendor: None#

Returns the scanner vendor. For tiffs this is unknown.

dlup.backends.tifffile_backend.open_slide(filename: Union[str, pathlib.Path]) dlup.backends.tifffile_backend.TifffileSlide[source]#

Read slide with tifffile.

Parameters
filenamePathLike

Path to image.

Module contents#