Skip to content
Advertisement

minimizing pixel non-uniformity in binary images

I am creating binary images (i.e., with only black and white and no other colors) of different shapes using matplotlib and PIL libraries. I have constraints on the number of pixels as 64×64, and the image has to be binary. At this low pixel range, I am getting pixelated images as shown below. I am searching for an approach where I can minimize the protrusions of white pixels and make their variation more uniform and gradual.

Magnified image with 64x64 pixels

I have used the following piece of code to generate this image.

JavaScript

Advertisement

Answer

You probably want to disable dithering in the conversion from RGB, use:

JavaScript

You could also consider generating a binary shape directly, instead of “thresholding” the anti-aliassed shape from Matplotlib.

For example using something like:

JavaScript

And plot the array with plt.imshow(circle, resample="nearest") instead. It might give you finer control at the pixel level. Relying on Matplotlibs anti-aliassing might make your solution backend specific?

enter image description here

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement