根据其他两个通道的值替换一个通道的像素值
replacing pixel value of one channel based on values of other two channels
target_positive_replace = np.where(positive_replace[...,0]>0 or positive_replace[...,1]>0 or positive_replace[...,2]>0),target_positive_replace[...,1]=255 ,0)
我有一个三通道 RGB 图像。
想进行以上操作
如果通道中的给定值之一大于零(通道值>0)。我想让那个像素变绿。 (0,255,0).
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
你的问题是 positive_replace[...,x]
returns 一个无法用 >0
检查的数组( 错误 )。因此,正如错误消息所述,您可以使用 a.all()
或 a.any()
检查返回数组的每个元素,或者您必须确保检索整数颜色值。
编辑
以上仅部分正确。正如@Cris Luengo 在他的评论中所述,or
需要一个值,而不是一个数组。因此,要么将单个值与 a.all()
和 a.any()
进行比较,要么将 positive_replace[...,x]>0
返回的布尔数组与 |
进行比较
target_positive_replace = np.where(positive_replace[...,0]>0 or positive_replace[...,1]>0 or positive_replace[...,2]>0),target_positive_replace[...,1]=255 ,0)
我有一个三通道 RGB 图像。
想进行以上操作
如果通道中的给定值之一大于零(通道值>0)。我想让那个像素变绿。 (0,255,0).
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
你的问题是 positive_replace[...,x]
returns 一个无法用 >0
检查的数组( 错误 )。因此,正如错误消息所述,您可以使用 a.all()
或 a.any()
检查返回数组的每个元素,或者您必须确保检索整数颜色值。
编辑
以上仅部分正确。正如@Cris Luengo 在他的评论中所述,or
需要一个值,而不是一个数组。因此,要么将单个值与 a.all()
和 a.any()
进行比较,要么将 positive_replace[...,x]>0
返回的布尔数组与 |