简体   繁体   中英

Converting Image to Black and White vs Converting Image to Monochrome(Grey Levels) in Python

I have the image below filename = '1.png' :

在此处输入图像描述

Whenever, I tried converting it to monochrome using the code below, the image is just the same as the input image.

image_counter = 1
path = 'sample/' + str(image_counter) + '.png'
image = Image.open(path).convert('L')  # Convert it into monochrome.
image = Image.fromarray(image)
image.save('monochrome.png')  

Monochrome Output:

在此处输入图像描述

But when i convert it to a black and white image, the output is different and produces not straight borders.

image_counter = 1
path = 'sample/' + str(image_counter) + '.png'
image = Image.open(path).convert('1')  # Convert it into black and white.
image = Image.fromarray(image)
image.save('blackandwhite.png') 

在此处输入图像描述

When zoomed, you can really observed the not straight borders.

在此处输入图像描述

Why is it?

The default method of converting a greyscale (“L”) or “RGB” image into a bilevel (mode “1”) image uses Floyd-Steinberg dither to approximate the original image luminosity levels. If dither is NONE, all non-zero values are set to 255 (white).

Dithering method, used when converting from mode “RGB” to “P” or from “RGB” or “L” to “1”. Available methods are NONE or FLOYDSTEINBERG (default).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM