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

Returns:

Type Description
ndarray

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

Source code in src/histolytics/stroma_feats/utils.py
def get_hematoxylin_mask(
    img_hematoxylin: np.ndarray, eosin_mask: np.ndarray
) -> 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).

    Returns:
        np.ndarray:
            The binary hematoxylin mask. Shape (H, W).
    """
    bg_mask = np.all(img_hematoxylin >= 0.9, axis=-1)
    hematoxylin_mask = (1 - bg_mask - eosin_mask) > 0
    return hematoxylin_mask.astype(bool)