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.