wright-group / WrightTools

Tools for loading, processing, and plotting multidimensional spectroscopy data.
http://wright.tools
MIT License
17 stars 8 forks source link

`artists.stitch_to_animation`: gif generation can have low color fidelity #1182

Open ddkohler opened 1 month ago

ddkohler commented 1 month ago

e.g. the component images of a 2D pcolormesh might have a smooth color gradient:

original

but the gif reduces the color size to be very segmented:

segmented

GIFs can only use a 256 color palette, but this is clearly more segmented than that. Maxing the palette_size kwarg to 256 does not fix this issue.

Proposing to add settings that allows for more color fidelity.

ddkohler commented 1 month ago

When pillow writes a gif from our images (pngs), it needs to define a palette to use. The images are imported in RGBA format (so they pixels are given a transparency value), and it appears that devoting colors to allow transparency significantly uses up the palette. If I convert the images to RGB before inserting them into the gif, the palette is built with much higher resolution.

So my current solution removes transparency, which might be desired in some cases. Still, it's progress, and the fix is simple.