Skip to content

registration

convert_to_nifti(base_path, path, container=None)

Runs c2d on the input image to turn into HistoReg <https://github.com/CBICA/HistoReg>_ compatible nifti.

Parameters:

Name Type Description Default
path PathLike

path to input image file.

required

equalize_contrasts(he_H, ihc_H, he_G, ihc_G, whitetol=220, low_percentile=5, high_percentile=95)

Equalizes the contrasts from H&E and IHC images that were converted into H space.

Parameters:

Name Type Description Default
he_H NDByteGrayImage

input H&E image in H space.

required
ihc_H NDByteGrayImage

input IHC image in H space.

required
he_G NDByteGrayImage

input H&E image in grayscale.

required
ihc_G NDByteGrayImage

input IHC image in grayscale.

required
whitetol int

value from grayscale image above which all values in the H image will be zeroed.

220
low_percentile float

percentile from the IHC_H image under which all values from both H images will be zeroed.

5
low_percentile float

percentile from the IHC_H image under which all values from both H images will be 255.

5

Returns:

Type Description
Tuple[NDByteGrayImage, NDByteGrayImage]

Tuple containg H&E and IHC H images with adjusted contrasts.

equalize_vert_lengths(l1, l2, centroid1, centroid2, max_angle=0.4)

Given 2 lists of vertices coordinates, remove items from the longest one that are the farthest from all points from the smalles one.

Parameters:

Name Type Description Default
l1 List[Tuple[Number, Number]]

first list of vertices coordinates.

required
l2 List[Tuple[Number, Number]]

second list of vertices coordinates.

required

full_registration(slide_he, slide_ihc, patch_he, patch_ihc, base_path, dab_thr=0.03, object_min_size=1000, iterations=20000, threads=0)

Perform full registration process on patches from an IHC slide and a H&E slide.

Parameters:

Name Type Description Default
slide_he Slide

input H&E slide.

required
slide_ihc Slide

input IHC slide.

required
patch_he Patch

input H&E patch (fixed for the registration).

required
patch_ihc Patch

input IHC patch (moving for the registration).

required
base_path PathLike

root path for all other files.

required
dab_thr float

minimum value to use for DAB thresholding.

0.03
object_min_size int

the smallest allowable object size to check if registration needs to be performed.

1000
iterations int

number of iterations for initial rigid search.

20000
Return

True if registration was sucesfully performed, False otherwise.

get_affine_transform(fixed, moving, centroid_fixed, centroid_moving)

Given 2 dot masks, get the affine transform (as rotation, scale and translation) to apply to the moving one to align it with the fixed one.

Parameters:

Name Type Description Default
fixed NDBoolMask

input fixed mask.

required
moving NDBoolMask

input moving mask.

required

Returns:

Type Description
Tuple[NDArray[3, 3, float], NDArray[3, 3, float], NDArray[3, 3, float]]

Tuple containing the rotation, the scale and the translation 3x3 matrices.

get_angle(v1, v2)

Get angle between two 2D vectors.

Parameters:

Name Type Description Default
v1 NDArray[2, Number]

first input vector.

required
v2 NDArray[2, Number]

second input vector.

required

Returns:

Type Description
float

Angle in radian between -pi and +pi.

get_binary_op(op_name)

Given a binary operation name, returns the corresponding scikit-image function.

Parameters:

Name Type Description Default
op_name str

name of the operation, either "closing", "dilation" or "none".

required

Returns:

Type Description
Union[binary_closing, binary_dilation, None]

If "closing", :func:~skimage.morphology.binary_closing; if "dilation",

Union[binary_closing, binary_dilation, None]

func:~skimage.morphology.binary_dilation; else None.

get_coord_transform(slide_he, slide_ihc)

Given an H&E slide and an immunohistochemistry slide, get a transform function that registers coordinates from the H&E slide into the IHC slide.

Parameters:

Name Type Description Default
slide_he Slide

input H&E slide.

required
slide_ihc Slide

input IHC slide.

required

Returns:

Type Description
Callable[[int, int], Coord]

A function that takes coordinates from the H&E slide as input and returns the

Callable[[int, int], Coord]

corresponding coords in the IHC slide.

get_dot_mask(slide, thumb_level=3, min_val=60, max_val=90)

Given a slide, computes a thumbnail mask where gray fixing dots are segmented.

Parameters:

Name Type Description Default
thumb_level int

pyramid level on which to extract the thumbnail.

3
min_val int

min value to filter on RGB channels.

60
max_val int

max value to filter on RGB channels.

90

Returns:

Type Description
NDBoolMask

Mask array with fixing dots segmented.

get_input_images(slide, patch, h_min=0.017, h_max=0.11)

Return patches from a slide that are used for registration:

Parameters:

Name Type Description Default
slide Slide

input slide.

required
patch Patch

input pathaia patch object.

required
h_min float

minimum hematoxylin value for standardization.

0.017
h_max float

maximum hematoxylin value for standardization.

0.11

Returns:

Type Description
NDByteImage

3-tuple containing patch as RGB image, grayscale image and with only Hematoxylin

NDByteGrayImage

channel.

get_rotation(fixed_vert, moving_vert)

Given 2 lists of vertices coordinates sorted in trigonometric order, get the rotation transform that aligns them.

Parameters:

Name Type Description Default
fixed_vert NDArray[Any, 2, int]

first vertices coordinates array considered as fixed for the rotation.

required
moving_vert NDArray[Any, 2, int]

first vertices coordinates array considered as moving for the rotation.

required

Returns:

Type Description
NDArray[3, 3, float]

2D rotation 3x3 matrix.

get_scale(fixed_vert, moving_vert)

Given 2 lists of vertices coordinates sorted in trigonometric order, get the scale transform that aligns them.

Parameters:

Name Type Description Default
fixed_vert NDArray[Any, 2, int]

first vertices coordinates array considered as fixed for the scale.

required
moving_vert NDArray[Any, 2, int]

first vertices coordinates array considered as moving for the scale.

required

Returns:

Type Description
NDArray[3, 3, float]

2D scale 3x3 matrix.

get_sort_key(vertices, centroid)

Computes a key function that aims at sorting vertices by increasing angle around their centroid.

Parameters:

Name Type Description Default
vertices Sequence[Tuple[Number, Number]]

array of vertices coordinates.

required

Returns:

Type Description
Callable[[Tuple[Number, Number]], float]

Function that takes a vertex as input and returns the angle between the (1, 0)

Callable[[Tuple[Number, Number]], float]

horizontal unit vector and the vector between the vertices' centroid and the

Callable[[Tuple[Number, Number]], float]

input vertex.

get_translation(fixed_vert, moving_vert)

Given 2 lists of vertices coordinates sorted in trigonometric order, get the translation transform that aligns them.

Parameters:

Name Type Description Default
fixed_vert NDArray[Any, 2, int]

first vertices coordinates array considered as fixed for the translation.

required
moving_vert NDArray[Any, 2, int]

first vertices coordinates array considered as moving for the translation.

required

Returns:

Type Description
NDArray[3, 3, float]

2D translation 3x3 matrix.

get_vertices(mask, centroid)

Given a fixing dot mask (obtained using :func:get_dot_mask), get list of all dots' centroid coordinates, sorted in trigonometric order.

Parameters:

Name Type Description Default
mask NDBoolMask

input dot mask array.

required

Returns:

Type Description
List[Tuple[int, int]]

List of vertex coordinates as tuples.

has_enough_tissue(img, blacktol=0, whitetol=247, area_thr=0.99)

Check if grayscale image contains enough tissue by filtering black and white pixels.

Parameters:

Name Type Description Default
img NDByteImage

input grayscale image.

required
blacktol int

minimum accepted pixel value.

0
whitetol int

maximum accepted pixel value.

247
area_thr float

minimum fraction of pixels that must be positive to consider the img to have enough tissue.

0.99

Returns:

Type Description
bool

True if the image is considered to have enough tissue, False otherwise.

register(base_path, he_H_path, ihc_H_path, he_path, ihc_path, reg_path, container=None, iterations=20000, resample=4, threads=0)

Registers IHC H image into H&E H image using HistoReg <https://github.com/CBICA/HistoReg>_.

Parameters:

Name Type Description Default
base_path PathLike

root path for all other files.

required
he_H_path PathLike

relative path to H&E H image file.

required
ihc_H_path PathLike

relative path to IHC H image file.

required
he_path PathLike

relative path to H&E image file saved as nifti.

required
ihc_path PathLike

relative path to IHC image file saved as nifti.

required
iterations int

number of iterations for initial rigid search.

20000
resample int

percentage of the full resolution the images will be resampled to, used for computation.

4