Page 1 of 1
partially pre-fixed pallette?
Posted: 2013-04-29T07:16:51-07:00
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
Re: partially pre-fixed pallette?
Posted: 2013-04-29T07:57:17-07:00
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.
Re: partially pre-fixed pallette?
Posted: 2013-05-01T00:03:40-07:00
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
Re: partially pre-fixed pallette?
Posted: 2013-05-03T01:58:02-07:00
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.
BugBear
Re: partially pre-fixed pallette?
Posted: 2013-05-05T17:17:09-07:00
by anthony
Re: partially pre-fixed pallette?
Posted: 2013-05-05T22:25:53-07:00
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.