Help remapping colors

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
mindv0rtex
Posts: 3
Joined: 2013-11-04T10:13:02-07:00
Authentication code: 6789

Help remapping colors

Post by mindv0rtex »

Dear ImageMagick pundits. I am trying to remap the colors of this image
https://drive.google.com/file/d/0B6_zZu ... sp=sharing

Only the colors from this palette can be used
https://drive.google.com/file/d/0B6_zZu ... sp=sharing

For anyone interested, those are colors that one can purchase from the PixelHobby company to create a physical mosaic. I have tried using the free software that is available on their website for this purpose, but the results are poor because some colors (and hence details) are lost in the transition. Also, simply using the -remap operator produces poor results as well. Can anyone offer me a helping hand here if it is not too much trouble?
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Help remapping colors

Post by snibgo »

This ...

Code: Select all

convert forest.gif -remap pixels.png r.png
... seems to work. What do you think is wrong? forest.png contains black pixels, but pixels.png doesn't have a black.
snibgo's IM pages: im.snibgo.com
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Help remapping colors

Post by fmw42 »

I do not know that you can do better than with -remap in IM.

This is what I get with IM 6.8.7.4 Q16 Mac OSX

Code: Select all

convert forest.gif +dither -remap pixels.png forest_remap.gif
Image
mindv0rtex
Posts: 3
Joined: 2013-11-04T10:13:02-07:00
Authentication code: 6789

Re: Help remapping colors

Post by mindv0rtex »

What is unsatisfying for me in using the -remap is the details lost in the upper part and in the lower left corner because for both colors of the original image -remap picks the same closest alternative from the pixels.png. I thought maybe there is some clever way of changing the original image a little bit such that -remap would be able to preserve all the details...
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Help remapping colors

Post by magick »

Add -gamma 1.6 to your command-line.
mindv0rtex
Posts: 3
Joined: 2013-11-04T10:13:02-07:00
Authentication code: 6789

Re: Help remapping colors

Post by mindv0rtex »

Gamma correction reveals the lost details but now -remap shifts blue colors to magenta...
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Help remapping colors

Post by snibgo »

Another way is to note that the darkest colour in pixels.png is about 16%, so we reduce the contrast of the original by lightening it:

Code: Select all

%IM%convert ^
  forest.gif ^
  +level 16%%,100%% ^
  -remap pixels.png ^
  r.png
snibgo's IM pages: im.snibgo.com
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Help remapping colors

Post by fmw42 »

mindv0rtex wrote:Gamma correction reveals the lost details but now -remap shifts blue colors to magenta...
Did you put -gamma right after reading the forest image? -gamma 1.6 may be too strong. try reducing it but keep it larger than 1.0

Perhaps a more linear adjustment such as user snibgo suggests may work better.
Post Reply