【python】RGB图片到灰度图的转换

ref: https://www.cnblogs.com/Chilly2015/p/4943724.html

https://blog.csdn.net/lanchunhui/article/details/66972783

RGB到灰度图转换公式:

         Y' = 0.299 R + 0.587 G + 0.114 B

import numpy as np
import matplotlib.image as mpimg
import matplotlib.pyplot as plt

def rgb2gray(rgb):
    return np.dot(rgb[..., :3], [0.299, 0.587, 0.144])
rgbPic = '01.png'
img = mpimg.imread(rgbPic)
grayPic = rgb2gray(img)
plt.imshow(grayPic,cmap = plt.get_cmap('gray')) 
plt.savefig('01_gray.png')

 

你可能感兴趣的:(python,image,process)