I'm trying to identify the colors of the used color palette of an image with PIL/pillow. I've tried the following:
image[x,y]: this will only give me the index number of the corresponding pixel (i.e.1)image.getpixel((x,y)): again, this will only give me the index number of the corresponding pixel (i.e.1)image.getcolors(): This will give me the number of pixels and their corresponding index number (i.e.[(2, 1), (2, 0)])image.palette: Returns a "PIL.ImagePalette.ImagePalette object"image.getpalette(): Returns a large array of (to me seemingly) unrelated integers (i.e.[0, 0, 255, 255, 0, 0, 2, 2, 2, 3, 3 ,3 ...])
As an absolute fallback, I could convert the image mode and then get the color values, but I'd rather not if possible.
With this example image (2x2 pixel image, indexed mode with 2 colors created with GIMP, the top two pixels are red (255,0,0) the bottom two are blue (0,0,255)), I was expecting something like:
image.getpalette()
1: (255,0,0)
0: (0,0,255)
Edit: The closest I have is:
image.palette.getdata(): This gives me ('RGB;L', b'\x00\x00\xff\xff\x00\x00'). Is there any way to have this mapped to the index number. Here each three bytes would map to one index number, I'd reckon.