johnrcomeau has asked for the wisdom of the Perl Monks concerning the following question:

I have been working with Imager for about a week now and would like to know how to better control the palette. I have an image that has some high-saturation colors in a small number of pixels. I create a paletted image with this type of call:
my $paletted_img = $img->to_paletted({max_colors => 12, colors => \@colors, });
I have noticed that the palette seems to consist of a lot of neutral, low-saturation colors. I suppose they have less color quantization error for more neutral and prevalent pixels. I would like to have some control over the palette so that I can preserve some of the high-saturation colors. I'd like to be able to specify one or two of the colors in the palette and let the module determine the other 10 or 11 colors. I can't find a lot of sample code on how to control how the pallete is formed, and the documentation I've found says that specifying a color list is a feature to be added to Imager in the future. Can anyone please help me fix one or two colors in the palette? Thanks.

Replies are listed 'Best First'.
Re: control palette with Imager
by tangent (Parson) on Apr 28, 2014 at 22:45 UTC
    What are the contents of @colors in your sample code? If it contains just two Imager::Color objects which represent the two high-saturation colors that you want to preserve then Imager should do what you require, i.e. the other ten colors will be filled in by the module.
Re: control palette with Imager
by wjw (Priest) on Apr 28, 2014 at 19:27 UTC
    This is a very specific question in specific discipline. There might be someone here who knows exactly what you are talking about, but then maybe not. I am not entirely certain this is a Perl question.

    Would help if you could show a bit more of your code. At least list the module(s) you are using. You describe the specifics of what you want to solve nicely, but not how you expect Perl to do it.

    Could you describe that a little more clearly? Seems to be an interesting problem...

    ...the majority is always wrong, and always the last to know about it...
    Insanity: Doing the same thing over and over again and expecting different results...
Re: control palette with Imager
by GotToBTru (Prior) on Apr 28, 2014 at 21:31 UTC

    I'm not really sure what the Imager module documentation is saying about to_palletted(), but it does say that it may ignore those colors. Perhaps you should explore the logging methods to see if something is failing?