Is it possible to specify a CLUT to use as a PNG's palette?

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
pwnedd
Posts: 35
Joined: 2008-09-03T13:03:57-07:00

Is it possible to specify a CLUT to use as a PNG's palette?

Post 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,
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Is it possible to specify a CLUT to use as a PNG's palette?

Post 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!
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Is it possible to specify a CLUT to use as a PNG's palette?

Post 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
Last edited by fmw42 on 2009-03-23T11:39:28-07:00, edited 1 time in total.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Is it possible to specify a CLUT to use as a PNG's palette?

Post 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.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply