AffineWSITransformer¶

class AffineWSITransformer(reader, transform)[source]¶

Resampling regions from a whole slide image.

This class is used to resample tiles/patches from a whole slide image using transformation.

Example

>>> from tiatoolbox.tools.registration.wsi_registration import (
... AffineWSITransformer
... )
>>> from tiatoolbox.wsicore.wsireader import WSIReader
>>> wsi_reader = WSIReader.open(input_img=sample_ome_tiff)
>>> transform_level0 = np.eye(3)
>>> tfm = AffineWSITransformer(wsi_reader, transform_level0)
>>> output = tfm.read_rect(location, size, resolution=resolution, units="level")

Initialize object.

Parameters:
  • reader (WSIReader) – An object with base WSIReader as base class.

  • transform (numpy.ndarray) – A 3x3 transformation matrix. The inverse transformation will be applied.

Methods

get_patch_dimensions

Compute patch size needed for transformation.

get_transformed_location

Get corresponding location on unregistered image and the required patch size.

read_rect

Read a transformed region of the transformed whole slide image.

transform_patch

Apply transformation to the given patch.

transform_points

Transform points using the given transformation matrix.

get_patch_dimensions(size, transform)[source]¶

Compute patch size needed for transformation.

Parameters:
Returns:

tuple - Maximum size of the patch needed for transformation.

Return type:

tuple[int, int]

get_transformed_location(location, size, level)[source]¶

Get corresponding location on unregistered image and the required patch size.

This function applies inverse transformation to the centre point of the region. The transformed centre point is used to obtain the transformed top left pixel of the region.

Parameters:
  • location (tuple(int)) – (x, y) tuple giving the top left pixel in the baseline (level 0) reference frame.

  • size (tuple(int)) – (width, height) tuple giving the desired output image size.

  • level (int) – Pyramid level/resolution layer.

  • self (AffineWSITransformer)

Returns:

  • tuple - Transformed location (top left pixel).
    • int - X coordinate

    • int - Y coordinate

  • tuple - Maximum size suitable for transformation.

Return type:

tuple

read_rect(location, size, resolution, units)[source]¶

Read a transformed region of the transformed whole slide image.

Location is in terms of the baseline image (level 0 / maximum resolution), and size is the output image size.

Parameters:
  • location (tuple(int)) – (x, y) tuple giving the top left pixel in the baseline (level 0) reference frame.

  • size (tuple(int)) – (width, height) tuple giving the desired output image size.

  • resolution (Resolution) – Resolution used for reading the image.

  • units (Units) – Units of resolution used for reading the image.

  • self (AffineWSITransformer)

Returns:

A transformed region/patch.

Return type:

numpy.ndarray

transform_patch(patch, size)[source]¶

Apply transformation to the given patch.

This function applies the transformation matrix after removing the translation.

Parameters:
Returns:

A transformed region/patch.

Return type:

numpy.ndarray

static transform_points(points, transform)[source]¶

Transform points using the given transformation matrix.

Parameters:
  • points (numpy.ndarray) – A set of points of shape (N, 2).

  • transform (numpy.ndarray) – Transformation matrix of shape (3, 3).

Returns:

Warped points of shape (N, 2).

Return type:

numpy.ndarray