Message Boards Message Boards

0
|
3751 Views
|
4 Replies
|
1 Total Likes
View groups...
Share
Share this post:

Specify color palette in images?

Is it possible to Export an image with a specified color palette? Ideally I would like to have some option when exporting an animated GIF to specify that all frames should use the exact same color palette, either by specifying the specific palette or (even better) by just specifying how many colors should be used.

4 Replies

I don't have much experience with images but before someone competent answers we can implement what you just said:

pic = ExampleData[{"TestImage", "Mandrill"}];

nf = Nearest[List @@@ {Red, Green, Blue, Yellow}];

ImageApply[First@*nf, pic]

enter image description here

POSTED BY: Kuba Podkalicki

You can map exported Images with:

Colorize[#, ColorFunction -> "schemename", ColorFunctionScaling -> False]&

Does it fit your needs?

POSTED BY: Kuba Podkalicki

I don't quite think so, but I could also just be confused. I'd like to have a (short) list of RGB colors and somehow tell Export to only use those colors. But maybe there's a way to do this with ColorFunction that I just don't understand?

When exporting to GIF, Export obviously has to discretize the colors in the frames somehow. I would just like to be able to give it guidance: to tell it something like "convert every color in the Graphics object I'm giving you to the nearest match from this list of colors".

Now, I realize I could do this myself by Rasterizeing and manipulating the list of pixels, but I'm wondering if there's something built in.

But if you use ColorQuantize to get a set of 'representable' colors, and then use Nearest for every pixel to get to the closest color found by ColorQuantize... Export might realize then that you only have 2,3,4.. colors and use these colors only in export...

POSTED BY: Sander Huisman
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract