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
Compute patch size needed for transformation.
Get corresponding location on unregistered image and the required patch size.
Read a transformed region of the transformed whole slide image.
Apply transformation to the given patch.
Transform points using the given transformation matrix.
- get_patch_dimensions(size, transform)[source]¶
Compute patch size needed for transformation.
- Parameters:
size (tuple(int)) – (width, height) tuple giving the desired output image size.
transform (
numpy.ndarray
) – Transformation matrix of shape (3, 3).self (AffineWSITransformer)
- Returns:
- Return type:
- 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:
- Returns:
- Return type:
- 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:
- transform_patch(patch, size)[source]¶
Apply transformation to the given patch.
This function applies the transformation matrix after removing the translation.
- Parameters:
patch (
numpy.ndarray
) – A region of whole slide image.size (tuple(int)) – (width, height) tuple giving the desired output image size.
self (AffineWSITransformer)
- Returns:
A transformed region/patch.
- Return type:
- 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: