2

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.

Defyleiti
  • 535
  • 1
  • 7
  • 23

2 Answers2

3

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

Mark Setchell
  • 191,897
  • 31
  • 273
  • 432
  • Thank you works great. Replaced copyalpha to copy-opacity. Quick question. Is there a way to flatten this without losing transparency since when you use this image to pdflib you only get outlines of the circle. – Defyleiti Sep 15 '18 at 08:20
  • Sorry, I don't know `pdflib`, but questions, and answers ;-) are free and you'll get more exposure if you ask a new question showing what you are trying to do rather than in the comments section of an already answered question. Good luck! – Mark Setchell Sep 15 '18 at 08:49
  • `Is there a way to flatten this without losing transparency`. There is nothing to flatten in your image other than transparency. PNG does not support multiply layers, so you only have one RGBA layer. The only thing is to flatten the alpha with some background color so that it could potentially be converted to JPG (or PNG). I am not familiar with PDFLIB. But try my solution below by add code to Mark Setchell's solution to make the background a solid black first before the -remap – fmw42 Sep 15 '18 at 18:14
2

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.

fmw42
  • 46,825
  • 10
  • 62
  • 80