def apply_palette256(image):
 return image.convert('RGB').convert('P', palette=Image.ADAPTIVE, colors=256, dither=Image.NONE)

def apply_palette256 ( image ) : return image . convert ( 'RGB' ) . convert ( 'P' , palette = Image . ADAPTIVE , colors = 256 , dither = Image . NONE )
get pil to generate and apply an optimum 256 color palette to the given image and return it .