def _normalize_inplace(self, scale_func, mode='all'):
        pixels = self.as_vector(keep_channels=True)
        if mode == 'all':
            centered_pixels = pixels - np.mean(pixels)
            scale_factor = scale_func(centered_pixels)

        elif mode == 'per_channel':
            centered_pixels = pixels - np.mean(pixels, axis=1)[..., None]
            scale_factor = scale_func(centered_pixels, axis=1)[..., None]
        else:
            raise ValueError("mode has to be 'all' or 'per_channel' - '{}' "
                             "was provided instead".format(mode))

        if np.any(scale_factor == 0):
            raise ValueError("Image has 0 variance - can't be "
                             "normalized")
        else:
            self._from_vector_inplace(centered_pixels / scale_factor)
dataset/ETHPy150Open menpo/menpo/menpo/image/base.py/Image._normalize_inplace/original