我正在使用Python Imaging Library进行一些非常简单的图像处理,但是我无法将灰度图像转换为单色(黑白)图像。如果在将图像更改为灰度(convert('L'))之后保存,则图像将按照您的期望进行渲染。但是,如果我将图像转换为单色,单波段图像,则会产生噪声,如下图所示。有没有一种简单的方法可以使用PIL / python将彩色png图像转换为纯黑白图像?
from PIL import Image
import ImageEnhance
import ImageFilter
from scipy.misc import imsave
image_file = Image.open("convert_image.png") # open colour image
image_file= image_file.convert('L') # convert image to monochrome - this works
image_file= image_file.convert('1') # convert image to black and white
imsave('result_col.png', image_file)
from PIL import Image
image_file = Image.open("convert_image.png") # open colour image
image_file = image_file.convert('1') # convert image to black and white
image_file.save('result.png')
产量
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句