【发布时间】:2020-07-08 08:45:00
【问题描述】:
我必须编写一个函数 to_red,它应该将绿色和蓝色分量归零并返回结果。我为 Image(.png) 编写了以下代码,以将绿色和蓝色归零并返回红色并且它起作用了。但是,如标题中所述,输入参数必须是 3-d 数组并返回 3-d 数组。应该如何更改我的以下代码。
import numpy as np
将 matplotlib.pyplot 导入为 plt
from matplotlib.pyplot import imshow
def to_red()
src = plt.imread("C:\src\painting.png")
red_channel = src[:,:,0]
red_img = np.zeros(src.shape)
red_img[:,:,0] = red_channel
plt.imshow(red_img)
plt.show()
【问题讨论】:
标签: python arrays matplotlib rgb