I would like to get the index values of an indexed image, so that I can modify images in a game where the palette and the index data are separate files. I looked through the command-line options of identify, the -grayscale options, the FX expressions and tried the txt:- output format, but they all don't seem to do the trick.
So if I have an image with a red, a blue, and another red pixel, saved as a GIF with a palette of 0: red and 1: blue, then I'd like to get an output similar to "0 1 0" or "\x00\x01\x00".

If you make a 3-pixel French flag similarly to @xenoid like this:
You can dump the colormap and pixels using
MAPformat like this:Hopefully you can see the first three bytes are red
0xff 00 00, the next three are blue0x00 00 ffand the next three are white0xff ff ffand the last three are indices 0, 2, 1.If you go Irish, with lime, white and orange:
It may come in handy to know how many colours there are:
It may come in handy to use JSON to extract the number of entries in the colormap and their values:
Or you can use PIL/Pillow from Python:
Sample Output
PIL/Pillow can also output the palette - though you need to be aware that it pads the palette out to 256 entries using shades of grey: