[英]How can i check in numpy if a binary image is almost all black?
我如何查看numpy或scikit-image模块中的二进制映像是几乎全黑还是全白?
我考虑过numpy.all
函数或numpy.any
但我不知道如何不使用全黑图像或几乎全黑图像。
这是我能想到的想法清单:
np.sum()
,如果它小于阈值,则认为它几乎是黑色的 np.mean()
和np.std()
,近乎黑色的图像是均值低且方差低的图像 假设所有像素实际上都是1或0,则可能会这样(完全未经测试):
def is_sorta_black(arr, threshold=0.8):
tot = np.float(np.sum(arr))
if tot/arr.size > (1-threshold):
print "is not black"
return False
else:
print "is kinda black"
return True
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.