def read_image(path: str | Path, as_tensor: bool = False) -> torch.Tensor | np.ndarray:
    """Read RGB image from disk.

    Args:
        path (str | Path): Path to image file
        as_tensor (bool): If ``True``, return torch.Tensor. Defaults to ``False``

    Returns:
        torch.Tensor | np.ndarray: Image as tensor or array, normalized to [0,1]

    Examples:
        >>> image = read_image("image.jpg")
        >>> type(image)
        <class 'numpy.ndarray'>

        >>> image = read_image("image.jpg", as_tensor=True)
        >>> type(image)
        <class 'torch.Tensor'>
    """
    image = Image.open(path).convert("RGB")
    return to_dtype(to_image(image), torch.float32, scale=True) if as_tensor else np.array(image) / 255.0
Read RGB image from disk.

    Args:
        path (str | Path): Path to image file
        as_tensor (bool): If ``True``, return torch.Tensor. Defaults to ``False``

    Returns:
        torch.Tensor | np.ndarray: Image as tensor or array, normalized to [0,1]

    Examples:
        >>> image = read_image("image.jpg")
        >>> type(image)
        <class 'numpy.ndarray'>

        >>> image = read_image("image.jpg", as_tensor=True)
        >>> type(image)
        <class 'torch.Tensor'>
    
src/anomalib/data/utils/image.py