我想做一个面具,它有一个对应于图像中某些细胞的面具。这些单元格至少应有一个RGB颜色值大于阈值。我的代码不起作用:
B = image[0:h,0:w,0].astype(int)
G = image[0:h,0:w,1].astype(int)
R = image[0:h,0:w,2].astype(int)
mask = np.zeros((h,w))
mask[np.where( max(R,G,B) > threshold )] = 1
这会产生一个错误:
ValueError occurred Message=The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
由于您的图像是一个三维数组
(h, w, 3)
,因此只需取最后一个轴的最大值即可获得max(R, G, B)
:将返回值与
threshold
进行比较,得到一个bool
数组。将其转换为int
以获得0和1的掩码:相关问题 更多 >
编程相关推荐