0
点赞
收藏
分享

微信扫一扫

Python 使用skimage实现将彩色图像转换为灰度图像并保存


Python实现

在做课程作业的时候

需要使用到一些灰度图片

但是Matlab卸载了 以前的一些测试图片也没有了

就利用python简单的实现一下

代码如下:

import matplotlib.pyplot as plt

from skimage import data,io
from skimage.color import rgb2gray

# 读取原图片
original = io.imread("img/3.jpeg")
grayscale = rgb2gray(original)

print(original.shape)

fig, axes = plt.subplots(1, 2, figsize=(8, 4))
ax = axes.ravel()

ax[0].imshow(original)
ax[0].set_title("Original")
ax[1].imshow(grayscale, cmap=plt.cm.gray)
ax[1].set_title("Grayscale")

# 输出灰度图片
i_name = "test3.jpg"
io.imsave(i_name, grayscale)

fig.tight_layout()
plt.show()

结果:

Python 使用skimage实现将彩色图像转换为灰度图像并保存_Python

Python 使用skimage实现将彩色图像转换为灰度图像并保存_开发语言_02


举报

相关推荐

灰度图像转换为频域图像

python实现将图像合成GIF图

0 条评论