如何将图像转换为黑白?(使用 Scipy 或 Matplotlib)



我需要拍摄这张图像并将其旋转 90 天并以黑白颜色打印。我需要用matplotlib或scipy来做。

import scipy.misc
import matplotlib.pyplot as plt
from scipy import ndimage
face = scipy.misc.face()
rotate = ndimage.rotate(face,90)
gray = rotate
plt.imshow(gray, cmap=plt.get_cmap('gray'), vmin=0, vmax=1)
plt.show()

我在几个网站上看到了这段代码,但它只旋转了图像。

你可以试试:

from PIL import Image, ImageDraw
image = Image.open("convert.png")
image = image_file.convert('1')
image = image.rotate(90)
image.save('result.png')

最新更新