Skip to content

get_hematoxylin_mask

Get the binary hematoxylin mask from the hematoxylin channel.

Parameters:

Name Type Description Default
img_hematoxylin ndarray

The hematoxylin channel. Shape (H, W, 3).

required
eosin_mask ndarray

The eosin mask. Shape (H, W).

required
device str

Device to use for computation. Options are 'cpu' or 'cuda'.

'cpu'

Returns:

Type Description
ndarray

np.ndarray: The binary hematoxylin mask. Shape (H, W).

Source code in src/histolytics/utils/im.py
def get_hematoxylin_mask(
    img_hematoxylin: np.ndarray, eosin_mask: np.ndarray, device: str = "cpu"
) -> np.ndarray:
    """Get the binary hematoxylin mask from the hematoxylin channel.

    Parameters:
        img_hematoxylin (np.ndarray):
            The hematoxylin channel. Shape (H, W, 3).
        eosin_mask (np.ndarray):
            The eosin mask. Shape (H, W).
        device (str):
            Device to use for computation. Options are 'cpu' or 'cuda'.

    Returns:
        np.ndarray:
            The binary hematoxylin mask. Shape (H, W).
    """
    if device == "cuda" and _has_cp:
        return _get_hematoxylin_mask_cp(img_hematoxylin, eosin_mask)
    else:
        return _get_hematoxylin_mask_np(img_hematoxylin, eosin_mask)