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
device str

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

'cpu'

Returns:

Type Description
Tuple[ndarray, ndarray, ndarray]

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

Source code in src/histolytics/utils/im.py
def hed_decompose(
    img: np.ndarray, device: str = "cpu"
) -> 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).
        device (str):
            Device to use for computation. Options are 'cpu' or 'cuda'.

    Returns:
        Tuple[np.ndarray, np.ndarray, np.ndarray]: The H, E, D channels.
    """
    if device == "cuda" and _has_cp:
        return _hed_decompose_cp(img)
    else:
        return _hed_decompose_np(img)