Skip to content

hed_decompose

Transform an image to HED space and return the 3 channels.

Parameters:

Name Type Description Default
img ndarray

The input image. Shape (H, W, 3).

required

Returns:

Type Description
Tuple[ndarray, ndarray, ndarray]

Tuple[np.ndarray, np.ndarray, np.ndarray]: The H, E, D channels.

Source code in src/histolytics/stroma_feats/utils.py
def hed_decompose(img: np.ndarray) -> Tuple[np.ndarray, np.ndarray, np.ndarray]:
    """Transform an image to HED space and return the 3 channels.

    Parameters:
        img (np.ndarray): The input image. Shape (H, W, 3).

    Returns:
        Tuple[np.ndarray, np.ndarray, np.ndarray]: The H, E, D channels.
    """
    ihc_hed = rgb2hed(img)
    null = np.zeros_like(ihc_hed[:, :, 0])
    ihc_h = hed2rgb(np.stack((ihc_hed[:, :, 0], null, null), axis=-1))
    ihc_e = hed2rgb(np.stack((null, ihc_hed[:, :, 1], null), axis=-1))
    ihc_d = hed2rgb(np.stack((null, null, ihc_hed[:, :, 2]), axis=-1))

    return ihc_h, ihc_e, ihc_d