python - 如何将图像转换为黑白?(使用 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()
我在几个网站上看到了这段代码,但它只旋转了图像。
解决方案
你可以试试:
from PIL import Image, ImageDraw
image = Image.open("convert.png")
image = image_file.convert('1')
image = image.rotate(90)
image.save('result.png')
推荐阅读
- php - 将翻译的分类重定向到分类文件
- bash - 尝试将变量作为 URL 的一部分传递时出现 CURL 错误“URL 使用错误/非法格式或缺少 URL”
- mysql - 跨域的mysql连接字符串
- angular - Angular - 在进入 Angular-Archwizard 中的下一步之前验证当前页面
- c++ - C ++中的thread_local与局部变量
- angular - 错误:在 Angular CLI >6.0 中,Karma 插件现在由“@angular-devkit/build-angular”导出
- java - FirebaseMessagingService onMessageReceived() 未执行
- java - Java 8/9/10 - 简洁的编程
- laravel - 在 Laravel 中 - 将变量添加到模型中,而不将其放入数据库中
- javascript - 如何设置超时功能