def denormalise_pixels_range(pixels, out_dtype):
    """
    Denormalise the given pixels array into the range of the given out dtype.
    If the given pixels are floating point or boolean then the values
    are scaled appropriately and cast to the output dtype. If the pixels
    are already the correct dtype they are immediately returned.
    Floating point pixels must be in the range [0, 1].
    Currently uint8 and uint16 output dtypes are supported.

    Parameters
    ----------
    pixels : `ndarray`
        The pixels to denormalise.
    out_dtype : `np.dtype`
        The numpy data type to output and scale the values into.

    Returns
    -------
    out_pixels : `ndarray`
        Will be in the correct range and will have type ``out_dtype``.

    Raises
    ------
    ValueError
        Pixels are floating point and range outside [0, 1]
    ValueError
        Input pixels dtype not in the set {float32, float64, bool}.
    ValueError
        Output dtype not in the set {uint8, uint16}
    """
    in_dtype = pixels.dtype
    if in_dtype == out_dtype:
        return pixels

    if np.issubclass_(in_dtype.type, np.floating) or in_dtype == np.float:
        if np.issubclass_(out_dtype, np.floating) or out_dtype == np.float:
            return pixels.astype(out_dtype)
        else:
            p_min = pixels.min()
            p_max = pixels.max()
            if p_min < 0.0 or p_max > 1.0:
                raise ValueError('Unexpected input range [{}, {}] - pixels '
                                 'must be in the range [0, 1]'.format(p_min,
                                                                      p_max))
    elif in_dtype != np.bool:
        raise ValueError('Unexpected input dtype ({}) - only float32, float64 '
                         'and bool supported'.format(in_dtype))

    if out_dtype == np.uint8:
        max_range = 255.0
    elif out_dtype == np.uint16:
        max_range = 65535.0
    else:
        raise ValueError('Unexpected output dtype ({}) - normalisation range '
                         'is unknown'.format(out_dtype))

    return (pixels * max_range).astype(out_dtype)
dataset/ETHPy150Open menpo/menpo/menpo/image/base.py/denormalise_pixels_range/original