Page 1 of 1
replace the colormap of an indexed image
Posted: 2015-08-10T21:20:07-07:00
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!!!
Re: replace the colormap of an indexed image
Posted: 2015-08-10T21:38:22-07:00
by snibgo
I don't think you can directly replace colormaps at the command line. You probably could by writing a C program.
Re: replace the colormap of an indexed image
Posted: 2015-08-10T21:41:33-07:00
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).
Re: replace the colormap of an indexed image
Posted: 2015-08-10T22:28:34-07:00
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".
Re: replace the colormap of an indexed image
Posted: 2015-08-10T22:30:08-07:00
by yakir
Do you know of anything that would do that (in linux) by any chance?
Re: replace the colormap of an indexed image
Posted: 2015-08-10T23:53:04-07:00
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
Re: replace the colormap of an indexed image
Posted: 2015-08-11T02:04:28-07:00
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
Re: replace the colormap of an indexed image
Posted: 2015-08-11T02:28:15-07:00
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
Re: replace the colormap of an indexed image
Posted: 2015-08-11T02:58:04-07:00
by yakir
snibgo understands me...
I'd rather steer away from proprietary software like Matlab.
Thanks anyhow!!!