Reduce image colors based on colorlookup table excluding transparent

Viewed 285

I'm trying to reduce the number of colors in the image below using -remap in imagemagick.

olympic-logo.png olympic-logo.png

colortable.png which consists of this two color A12E64, FF0000

enter image description here

Using the following code:

convert olympic-logo.png +dither -remap colortable.png olympic-logo-remap.png

Output: olympic-logo-remap.png

enter image description here

Expected Output: olympic-logo-expected.png enter image description here

Is there a way to ignore transparent area so It won't get mapped to get the expected output?

Thanks and more power.

2 Answers

You can put a copy of the original image to one side before doing what you already did and then restore the alpha from that afterwards like this:

convert rings.png -write MPR:orig +dither -remap colortable.png MPR:orig -compose copyalpha -composite result.png

where MPR: is a "Memory Program Register", i.e. a named lump of RAM.

enter image description here

Your input image does not have a constant background color. It is mostly black with a large white border. You can see that if you turn alpha off:

convert olympic-logo.png -alpha off aoff.png

enter image description here

So you can modify Mark Setchell's command by adding -background black -alpha background to it.

convert xc:"#A12E64" xc:"#FF0000" +append colortable.png

convert olympic-logo.png -background black -alpha background -write MPR:orig +dither -remap colortable.png MPR:orig -compose copy_opacity -composite result.png

enter image description here

Does this now work for you? If not, try making the background all white.

Related