Page 1 of 1
Is it possible to specify a CLUT to use as a PNG's palette?
Posted: 2009-03-14T05:59:29-07:00
by pwnedd
I would like to create an indexed PNG8 image as efficiently as possible. Thus far I've been using the -clut operator, and then pngnq to reduce the number of colors. Accordion to the
documentation, -clut replaces the original pixels:
Given two images, replace the channel values in the first image using each corresponding channel in the second image as a color lookup table.
Does anyone know if there is an alternative way to using -clut so that rather than actually replacing the original pixels, it will merely associate the specified 1x256 color lookup table with the 8-bit image?
Any help would be greatly appreciated!
Thanks,
Re: Is it possible to specify a CLUT to use as a PNG's palette?
Posted: 2009-03-16T19:05:16-07:00
by anthony
CLUT is as you said just a color lookup and replacement method. where the color values themselves (typically greyscale) are used for replacement. (It is also used for hisogram adjustment of color images using a (usally) greyscale image.
It does not actually 'find and replace' one color with another color (actual one-to-one color replacement), but uses color values (grayscale) to lookup the position in the CLUT image for a replacement color value.
It has nothing to do with color palettes, tables or indexes in reality.
however it is posible to create a index pallete assignment function, it just does not exist at this time.
As long as after the assignment the image does not modify or add more colors
to the image to invalidate the palette, then Im should be able to save it to index images formats ( like PNG8 or GIF).
What is needed is programmers with the time to work on this!
Re: Is it possible to specify a CLUT to use as a PNG's palette?
Posted: 2009-03-19T17:24:35-07:00
by fmw42
anthony wrote:CLUT is as you said just a color lookup and replacement method. where the color values themselves (typically greyscale) are used for replacement. (It is also used for hisogram adjustment of color images using a (usally) greyscale image.
It does not actually 'find and replace' one color with another color (actual one-to-one color replacement), but uses color values (grayscale) to lookup the position in the CLUT image for a replacement color value.
It has nothing to do with color palettes, tables or indexes in reality.
however it is posible to create a index pallete assignment function, it just does not exist at this time.
As long as after the assignment the image does not modify or add more colors
to the image to invalidate the palette, then Im should be able to save it to index images formats ( like PNG8 or GIF).
What is needed is programmers with the time to work on this!
I just built a script that allows one to translate one set of colors in an image to another set from a list of color pairs in a file. So you can have many colors changed like in a colormap table. See mapcolors script at
http://www.fmwconcepts.com/imagemagick/index.html
Re: Is it possible to specify a CLUT to use as a PNG's palette?
Posted: 2009-03-22T22:17:04-07:00
by anthony
Afetr just reading your options I think you can improve it further.
Extract and save the transparency channel of an image, and make it 'opaque' (see -alpha operator) in the working image. You can then safely use the 'none' color as an intermediate for ALL images, and then just restore the alpha channel.
Of course this will only work if the user wants to replace color regardless of there transparency (that is treat semi-transparent as an opaque color for replacement) but that is a very common requirement and makes for a good strategy.
If transparency is important in the replacement, then perhaps using semi-transparent color as the safe color would be better and less important.
Another option that would be useful but difficult to do using a command line replacement method, is a 'default color' that is the color to assign if none of the colors being replaced match (with the fuzz factor of course). For this to work you will need to be able loop though the image one pixel at a time doing the color replacements.