partially pre-fixed pallette?

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
bugbear
Posts: 33
Joined: 2010-10-21T03:06:35-07:00
Authentication code: 8675308

partially pre-fixed pallette?

Post by bugbear »

I would like to make an optimal-as-possible-palette to quantise
an image (without dithering, as it happens).

Many good algorithms are known for this, and are embodied
in netpnm, imagemagick, gimp etc.

But I would like to be able to pre-select some
colours, then let the algorithm pick the rest,
taking proper account of my pre-selections.

For example, I might (well) want to always
have pure black and pure white, but let the algorithm
pick the remaining colours (which I intend
to be a VERY small number, e.g. 4, for a total palette of 6).

Does anyone know a way to do this?

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

Re: partially pre-fixed pallette?

Post by snibgo »

I don't think there is a guaranteed way to do this in IM.

However, you might kludge it by appending a large number of black pixels and white pixels to the image. Then ask IM to quantise, then remove the extra pixels.
snibgo's IM pages: im.snibgo.com
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: partially pre-fixed pallette?

Post by anthony »

This is an area of IM that can use some major redevelopment.


The IM quantization function was designed to allow it to quantize and dither using large numbers of colors, but new dither methods allows you to dither with a small number of colors, and do it in a more 'ordered' fashion, better suited to small icon and animation generation.

Also the quantization method generally finds colors in the center of a color cluster, while error correction dither works better with a set of colors around the edges of color clusters (preventing dither speckle).

No if we can get something interested in having a go :-)
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
bugbear
Posts: 33
Joined: 2010-10-21T03:06:35-07:00
Authentication code: 8675308

Re: partially pre-fixed pallette?

Post by bugbear »

My thoughts now run as follows;

1) remove all pixels from the image that are within "some small distance" of the fixed colour palette (under some reasonable metric), making image-2

2) make a palette for image-2 using "some good algorithm".

3) measure the average colour distance (under the same metric as before) for the image-2/palette pair.

Repeat from step (1) with the distance altered to be closer to the distance found in (3) until
the distances are similar.

I suspect this is far from optimal in results or performance, but each of 1,2,3 is a well known, well defined procedure.

I would welcome comment, insight and suggestions from people cleverer and/or more knowledgeable than me. :D

BugBear
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: partially pre-fixed pallette?

Post by anthony »

Take a look at....

General overview of Quantization
http://web.cs.wpi.edu/~matt/courses/cs5 ... index.html

New Dithering Methods
http://bisqwit.iki.fi/story/howto/dither/jy/
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: partially pre-fixed pallette?

Post by anthony »

Further thoughts on original problem.

I would like to be able to get the output of the -color quantization phase as a 'colortable image' separate to the dithering step.
That is get the actual colors IM picked, before they are used for dithering (as per '-map'), so that you can add/ remove or change those colors. Also as a debugging.

As it stands you can only get those colors after they are dithered onto the image, which often does not use all the colors the quantization routine decided was a 'good color set' for dithering.

For example you could use -colors 255 on some image, and Im will find 255 colors, but afetr dithering only 150 of those colors were used.

This separation would also mean we (well someone) could add new quantization methods other than the current highly tweeked version currently is use.


Note this is something on my 'to do' list but it has been pushed so far down the list, it is unlikely I would ever get to it.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply