replace the colormap of an indexed image

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
yakir
Posts: 8
Joined: 2013-01-25T13:45:23-07:00
Authentication code: 6789

replace the colormap of an indexed image

Post by yakir »

I have a b&w UInt8 image (in.png) and a colormap with 256 ordered colors (colormap.png). I want to recolor the b&w image according to the colormap. I'm very happy with:

Code: Select all

convert in.png colormap.png -clut out.png
but I was wondering if it wouldn't be a lot faster to just switch the internal colormap of an indexed image from the black and white one to the desired colormap. My understanding of how this would work might be completely wrong... I would want for a pixel that has a value of UInt8(0) to get the first color in the colormap, a pixel with a value of UInt8(1) to get the second color in the colormap, etc... No interpolation, dithering, or stuff like that.

Any thoughts?

Thanks in advance!!!
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: replace the colormap of an indexed image

Post by snibgo »

I don't think you can directly replace colormaps at the command line. You probably could by writing a C program.
snibgo's IM pages: im.snibgo.com
yakir
Posts: 8
Joined: 2013-01-25T13:45:23-07:00
Authentication code: 6789

Re: replace the colormap of an indexed image

Post by yakir »

I see. That's too bad. It would make sense to have some functionality like that in imagemagick for indexed images. Should be super fast regardless of the size of the image (but I guess that the size of the colormap should matter).
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: replace the colormap of an indexed image

Post by snibgo »

Yes, it would be quick, as pixels wouldn't need to be read or written (just the bytes copied from input to output).

ImageMagick is really an image processor, so it doesn't have many command-line options for manipulating lower-level constructs like colormaps, other than "-cycle".
snibgo's IM pages: im.snibgo.com
yakir
Posts: 8
Joined: 2013-01-25T13:45:23-07:00
Authentication code: 6789

Re: replace the colormap of an indexed image

Post by yakir »

Do you know of anything that would do that (in linux) by any chance?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: replace the colormap of an indexed image

Post by fmw42 »

You can convert your color table to an image, with one pixel per color. Then use -remap to recolor the image so that it is using only those colors, which should then go into the image's colormap. See http://www.imagemagick.org/Usage/quantize/#remap
yakir
Posts: 8
Joined: 2013-01-25T13:45:23-07:00
Authentication code: 6789

Re: replace the colormap of an indexed image

Post by yakir »

I tried that and it doesn't result in the same thing as:

Code: Select all

convert in.png colormap.png -clut out.png
nor is it faster.
Not sure if I'm doing it right:

Code: Select all

convert in.png -dither None -remap colormap.png out.png
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: replace the colormap of an indexed image

Post by snibgo »

"-remap" finds for each pixel the closest colour in the map image. By contrast, "-clut" (or somehow changing the colormap) can change any colours to any other colours, which is what I think yakir wants.

It seems that Mathlab has tools for changing colormaps. I don't know if this would be faster than ImageMagic's "-clut". There may be specific tools for colourmaps in specific formats such as PNG or TIFF
snibgo's IM pages: im.snibgo.com
yakir
Posts: 8
Joined: 2013-01-25T13:45:23-07:00
Authentication code: 6789

Re: replace the colormap of an indexed image

Post by yakir »

snibgo understands me... :)
I'd rather steer away from proprietary software like Matlab.
Thanks anyhow!!!
Post Reply