您当前的位置: 首页 > 

星夜孤帆

暂无认证

  • 1浏览

    0关注

    626博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

将RGB图像转换为灰度图像

星夜孤帆 发布时间:2018-07-05 23:14:38 ,浏览量:1

对于彩色转灰度,有一个很著名的心理学公式:

Gray = R*0.299 + G*0.587 + B*0.114

from PIL import Image
import matplotlib.image as mpimg
import numpy as np
import matplotlib.pyplot as plt
img = mpimg.imread('C:\\Users\\Administrator\\Desktop\\sd\\test.jpg')#输出一个数组
def RGB_to_Grey(image):
    return np.dot(image[...,:3],[0.299,0.587,0.114])
grey = RGB_to_Grey(img)
plt.imshow(grey,cmap='Greys_r')
plt.show()
关注
打赏
1636984416
查看更多评论
立即登录/注册

微信扫码登录

0.0383s