Changing the bit depth of shapes obtained using Matplotlib

I use matplotlib to generate some digits via savefig . These numbers are black and white and must be saved with a very high resolution (1000 dpi) in TIFF format. Therefore, it would be useful to store them with a reduced bit depth in order to use less memory.

To this end, my question is: how to determine the bit depth while storing digits using matplotlib?

Thanks!

+5
source share
1 answer

So far I have the impression that matplotlib does not support the bit depth option. Thus, I use imagemagick to convert the posthoc image:

convert -monochrome +dither A.tiff B.tiff

A few things that I will talk about in case someone tries to do this:

When I first changed the bitdept by running convert -monochrome A.tiff B.tiff , the fonts looked unacceptably ugly (even at 1000 DPI!). This was caused by the anti-aliasing that matplotlib performs by default. I could not find any way to turn this off, but its negative effects (when DPI downsampling) can be pretty much a workaround by turning on anti-aliasing. Therefore, even if there is an option to change the DPI of the output image in matplotlib, it is not useful if it does not perform anti-aliasing or if there is also no option to disable anti-aliasing.

The short answer is, I would suggest to anyone in a similar situation how to do my monochrome posthoc transition, as I did.

+1
source

Source: https://habr.com/ru/post/1202429/


All Articles