首页 > 解决方案 > 如何将图像转换为黑白?(使用 scipy 或 matplotlib)

问题描述

我需要拍摄这张图片并将其旋转 90d 并以黑白颜色打印。我需要用 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()

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

标签: pythonmatplotlibscipy

解决方案


你可以试试:

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

推荐阅读