def _palette_is_grayscale(pil_image):
 assert (pil_image.mode == 'P')
 palette = np.asarray(pil_image.getpalette()).reshape((256, 3))
 (start, stop) = pil_image.getextrema()
 valid_palette = palette[start:stop]
 return np.allclose(np.diff(valid_palette), 0)

def _palette_is_grayscale ( pil_image ) : assert ( pil_image . mode == 'P' ) palette = np . asarray ( pil_image . getpalette ( ) ) . reshape ( ( 256 , 3 ) ) ( start , stop ) = pil_image . getextrema ( ) valid_palette = palette [ start : stop ] return np . allclose ( np . diff ( valid_palette ) , 0 )
return true if pil image in palette mode is grayscale .