python的灰度处理怎么搞
本帖最后由 王球球a 于 2022-3-21 13:49 编辑以下 2 个公式可用来计算灰度值( 即将 RGB 彩色图像转换为灰度图),公式 2 是 PIL 灰度图的计算公式,比较常用。
公式1: $L = 0.333R + 0.333G + 0.333*B$
公式2: L=0.299∗R+0.587∗G+0.114∗B
请用公式 2 制作灰度掩膜 grey_mask,生成灰度图。
(提示:转换过程涉及到掩膜数组的制作,数组转置(ndarray.T),矩阵乘法(@ or np.matmul),numpy 数据格式转换(astype),图像模式转换等操作。)
# 灰度掩膜
grey_mask = np.array()
# 通过转置、矩阵乘法、数据格式转换等操作获得灰度矩阵
img_arr_temp =
img_arr_grey = img_arr_temp.astype()
# 将灰度矩阵转换成灰度图像
img_grey = Image.fromarray(img_arr_grey, mode='L')# 图像模式设置为'L',即灰度图
# 显示转换好的灰度图像
img_grey , ?问题呢 大马强 发表于 2022-3-20 22:53
?问题呢
一直莫得人理我,就发到别的帖子了,大佬救救我 img_arr_temp = np.dot(img[..., :3], )
img 是你导入的图像矩阵 大马强 发表于 2022-3-21 15:42
img 是你导入的图像矩阵
报错了昂
TypeError: 'JpegImageFile' object is not subscriptable 王球球a 发表于 2022-3-21 16:49
报错了昂
TypeError: 'JpegImageFile' object is not subscriptable
{:10_266:}我一般设置参数直接转换成灰度图的
我这学期刚开这门课程
页:
[1]