I'd like to use ImageMagick to convert pictures to 4-bit RGBI format. It turns out I can do that by making a palette as a separate step. However, the results are very unsatisfying.
For example, here is an input image to the above 15-color palette:
And here's the output with RGBI4 palette:
In comparison, using just 8 colors with -posterize 2
, i.e. not allowing for mid intensity, I get this actually better picture:
Note that all of the colors used in the second conversion are available for the first conversion as well; they are just not picked by ImageMagick.
To me, this suggests that the problem is the color space metric used by ImageMagick to choose colors. How do I control that to get something that is at least as good as -posterize 2
?
AFAIK, ImageMagick always does the remapping in RGB colourspace which doesn't produce very good results for you. I therefore tried converting to a different colourspace, but hiding that from ImageMagick so it believes the image and palette are RGB and then, when the remapping is done, I admitted the data was HSV and converted back to RGB. It seems to work ok for your sample image:
We may have to work on the yellows... in fact, that brings another idea to mind... we could take the few individual colours in your input image separately and force each one to a new output colour, one-at-a-time...
TL;DR - the following paragraph is the solution
I can pick individual colours (within any tolerance, or "fuzz") in the input image and change them to anything I want. So here, I'll make the yellows become red and the greens become magenta:
I'll leave you to do the exact mapping of your input colours, you just need to add an extra line for each input colour and its corresponding output colour... and maybe diddle with the fuzz factor.
Just for reference, here is the ugly, proof-of-concept code I worked on in Python and OpenCV - it works, by the way: