Page 1 of 1

convert image with exact specified colormap

Posted: 2012-06-29T11:32:49-07:00
by holistone
I am using Image Magick Q8 on Windows 7 to add new images to an ancient display program that accepts .gif file input but uses a fixed colormap with no ability to alter the colormap for individual images. Specifically, I want to save .gif conversions of other images with a specified colormap. The "-remap cmap.gif" option in Image Magick, example:

Code: Select all

convert -remap cmap.gif input.png output.gif
DOES process input.png using the specified colors from cmap.gif, but it changes the order in the output colormap. Is there a way to force Image Magick to used EXACTLY the same colormap?

Re: convert image with exact specified colormap

Posted: 2012-06-29T12:19:51-07:00
by fmw42
I am no expert on this, but form previous post about this, I do not think so. But I will leave it to the IM developers for a proper answer.

I am not sure if there is even a way to swap the color map in the image via IM.

Re: convert image with exact specified colormap

Posted: 2012-06-29T13:29:01-07:00
by glennrp
Please try
  • -define png:preserve-colormap
The manual suggests this option to use the existing image->colormap. Normally the PNG encoder will try to optimize the palette, eliminating unused entries and putting the transparent colors first. If this flag is set, that behavior is suppressed. Sorry it's not well tested; let us know if it works for you. This option was added 2011-04-18 to IM-6.6.9-6

Re: convert image with exact specified colormap

Posted: 2012-06-29T14:40:26-07:00
by holistone
-define png:preserve-colormap
has no effect using IM 6.7.7-8. My reading of the documentation is that this is for ENCODING png files, while I am trying to encode a .gif file.

I hoped there there would be some form of
-define remap:preserve-colormap
option to map the image exactly to the desired input colormap independent of the output format.

Re: convert image with exact specified colormap

Posted: 2012-06-29T14:48:47-07:00
by fmw42
convert to PNG8 format. It is very similar to gif.

http://www.imagemagick.org/Usage/formats/#png_formats

See if that has the colormap as desired. If so, then try

convert image.png image.gif

Re: convert image with exact specified colormap

Posted: 2012-06-29T15:00:51-07:00
by holistone
Converting to a png palette image with -remap and -define png:preserve-colormap gives the same result as converting to gif. The output colormap/palette DOES contain all of the colors from the remap specified input, but it alters the order.

Re: convert image with exact specified colormap

Posted: 2012-06-29T15:34:37-07:00
by fmw42
holistone wrote:Converting to a png palette image with -remap and -define png:preserve-colormap gives the same result as converting to gif. The output colormap/palette DOES contain all of the colors from the remap specified input, but it alters the order.
That then is an issue back to Glennrp as he is the PNG guru.

Re: convert image with exact specified colormap

Posted: 2012-06-29T15:59:19-07:00
by fmw42
Just to confirm. Have you created your -remap colortable image by creating a one row or one column image with each pixel being the colors in the desired order?

Re: convert image with exact specified colormap

Posted: 2012-06-29T19:40:32-07:00
by holistone
The cmap.gif image is one row of 16 pixels with color indices from 0 to 15. There are 16 entries in the gif colormap/palette. When I run

convert -remap cmap.gif input.png output.gif

I get a 4-bit (16-color) .gif file as output with a colormap/palette that has the same colors as cmap.gif, but in a different order. I get the same colormap/palette if I change the output to output.png (4-bits, 16 colors). If I change the colormap to a full-color RGB (24-bit) input.png, I get an 8-bit .gif or .png file with just the 2 non-background colors that are in the input image (the input image is simple 1-color text on a black background).

To me, it makes sense for the -remap operation to use the same code independent of output type. If the user has specified a specific colormap/palette, then I would expect it be used for the output.

As I said when I originally posted the question, I am trying to create new .gif images for display with an ancient program which has a fixed colormap. It is important not only that the new image use the same colors, but it must also use the same color index as given in the input colormap for each color. The actual images are simple text labels that can be conveniently created with the IM label option. I check the output and palette using Irfanview.

Re: convert image with exact specified colormap

Posted: 2012-06-29T19:48:01-07:00
by fmw42
properly your command should be, but won't really make a difference

convert input.png -remap cmap.gif output.gif

I understand your request/requirements, but as far as I know IM does not support that, with the exception of whatever Glenn has built into png. Perhaps one of the IM developers can respond and clarify this further for you. If the colors in your cmap.gif are in one row or one column as an image and the colors there are placed in order as you have in your colortable, then if that gets changed around, I guess you may be out of luck.

Be sure to put +dither with your command as I believe that it may do dithering. See the section of remap at http://www.imagemagick.org/Usage/quantize/#intro. That may be why you get different results

Re: convert image with exact specified colormap

Posted: 2012-06-29T20:07:26-07:00
by holistone
Thanks for the quick responses. Experimentally the order of the input file and first option make no difference to the output. The +dither makes no difference, possibly since my input images contain only colors that are already in the palette. In fact, if I give as input a .gif image that already has the desired colormap (identical to that of cmap.gif) the color indices are still changed in the output. I suspect my expectation that applying a specific colormap/palette to an image would be an easy task for IM was unfounded (or perhaps my definition of "applying" is simply more restrictive).

Re: convert image with exact specified colormap

Posted: 2012-06-29T20:23:30-07:00
by fmw42
holistone wrote:Thanks for the quick responses. Experimentally the order of the input file and first option make no difference to the output. The +dither makes no difference, possibly since my input images contain only colors that are already in the palette. In fact, if I give as input a .gif image that already has the desired colormap (identical to that of cmap.gif) the color indices are still changed in the output. I suspect my expectation that applying a specific colormap/palette to an image would be an easy task for IM was unfounded (or perhaps my definition of "applying" is simply more restrictive).

I think this should be something that IM would be able to handle via some kind of -define as Glenn had suggested though may not be working. And also for gif or any other format that supports 8-bit or less palette. This would likely be a new feature. If not via a define, there ought to be a way to export the colortable, edit it and import it back.

You are not the only one that has asked or requested this.

But such decisions and enhancements are up to the iM developers. But I know they have many enhancements in their queue and right now are devoting much of their limited time to IM 7 development.

But it cannot hurt to suggest something like this in the developers forum.

Re: convert image with exact specified colormap

Posted: 2012-06-30T09:23:31-07:00
by holistone
Thanks. I'll check the developers forum. I also tried GraphicMagick which has a similar convert -map option to specify a colormap. Like iM, the output uses only the colors specified in the colormap, and scrambles the order in colormap, but in a different manner than iM.