wsipipe.load.slides package

Slide loaders wrap different WSI image formats into generic slide loader

slide module

SlideBase is a parent class that contains functionality for reading slides. This is used to render different types of slides into a common format

class SlideBase[source]

Bases: object

Generic base class for slide loaders.

open()[source]

opens a slide

Return type

None

close()[source]

closes a slide

Return type

None

path()

returns the filepath to the slide

dimensions()

returns a list of the slide dimensions in pixels

for each level present in the WSI pyramid
read_region()[source]

returns a specified region of the slide as a PIL image

Parameters

region (Region) –

Return type

Image

read_regions()[source]

returns multiple regions as a list of PIL images

Parameters

regions (List[Region]) –

Return type

List[Image]

get_thumbnail()[source]

returns the whole of the slide at a given level

Parameters

level (int) –

Return type

numpy.array

in the WSI pyramid as numpy array. This can run out of memory if
too low a level in the pyramid is selected
abstract close()[source]
Return type

None

abstract property dimensions: List[Size]

Gets slide dimensions in pixels for all levels in pyramid :returns: A list of sizes :rtype: (List[Size])

get_thumbnail(level)[source]

Get thumbnail of whole slide downsized to a level in the pyramid

Parameters

level (int) – Level at which to return thumbnail

Returns

thumbnail as an RGB numpy array

Return type

im (np.array)

abstract open()[source]
Return type

None

abstract property path: Path
abstract read_region(region)[source]

Read a region from a WSI

Returns a PIL image for the region

Parameters

region (Region) – A region of the image

Returns

A PIL Image of the specified region

Return type

image (Image)

abstract read_regions(regions)[source]

Read multiple regions of a WSI

Returns a PIL image for each region

Parameters

regions (List[Region]) – List of regions

Returns

List of Images

Return type

images (List[Image])

openslide module

class OSSlide(path)[source]

Bases: SlideBase

Read slides to generic format using the openslide package. For example, to open OMETiff WSIs.

Parameters

path (Path) –

check_level(region)[source]

Checks if level specified in region exists in pyramid :param region: A Region to check :type region: Region

Returns

True if level in region exists in pyramid

Return type

(bool)

Parameters

region (Region) –

close()[source]
Return type

None

convert_region(region)[source]

Creates a PIL image of a region by downsampling from lower level :param region: A Region to create :type region: Region

Returns

A downsampled PIL Image

Return type

image (Image)

Parameters

region (Region) –

property dimensions: List[Size]

Gets slide dimensions in pixels for all levels in pyramid

If fewer than 10 levels exist in the pyramid it calculates the extra sizes and adds them to the list

Returns

A list of sizes

Return type

sizelist (List[Size])

open()[source]
Return type

None

property path: Path
read_region(region)[source]

Read a region from a WSI

Checks if the specified level for the region exists in the pyramid. If not reads the region from the highest level that exists and downscales it

Parameters

region (Region) – A region of the image

Returns

A PIL Image of the specified region

Return type

image (Image)

read_regions(regions)[source]

Read multiple regions of a WSI

Returns a PIL image for each region

Parameters

regions (List[Region]) – List of regions

Returns

List of Images

Return type

images (List[Image])

region module

class Region(level, location, size)[source]

Bases: tuple

Class for a Region of a whole slide image :param level: Level to extract the region :type level: int :param location: x y tuple giving location of top left of region at that level :type location: Point :param size: width and height tuple giving size of region at that level :type size: Size

Parameters
  • level (int) –

  • location (Point) –

  • size (Size) –

as_values()[source]

Splits out location and size into separate values

Return type

Tuple[int, int, int, int, int]

property level

Alias for field number 0

property location

Alias for field number 1

classmethod make(x, y, size, level)[source]

An alternate construction method for square region

Assumes a square region of width and height equal to size

Parameters
  • x (int) – the pixel location of left of image at level

  • y (int) – the pixel location of top of image at level

  • size (int) – size of square region

  • level (int) – Level to extract the region

property size

Alias for field number 2