def normalise_pixels_range(pixels, error_on_unknown_type=True):
    r"""
    Normalise the given pixels to the Menpo valid floating point range, [0, 1].
    This is a single place to handle normalising pixels ranges. At the moment
    the supported types are uint8 and uint16.

    Parameters
    ----------
    pixels : `ndarray`
        The pixels to normalise in the floating point range.
    error_on_unknown_type : `bool`, optional
        If ``True``, this method throws a ``ValueError`` if the given pixels
        array is an unknown type. If ``False``, this method performs no
        operation.

    Returns
    -------
    normalised_pixels : `ndarray`
        The normalised pixels in the range [0, 1].

    Raises
    ------
    ValueError
        If ``pixels`` is an unknown type and ``error_on_unknown_type==True``
    """
    dtype = pixels.dtype
    if dtype == np.uint8:
        max_range = 255.0
    elif dtype == np.uint16:
        max_range = 65535.0
    else:
        if error_on_unknown_type:
            raise ValueError('Unexpected dtype ({}) - normalisation range '
                             'is unknown'.format(dtype))
        else:
            # Do nothing
            return pixels
    # This multiplication is quite a bit faster than just dividing - will
    # automatically cast it up to float64
    return pixels * (1.0 / max_range)
dataset/ETHPy150Open menpo/menpo/menpo/image/base.py/normalise_pixels_range/original