在 numpy 或 scikit-image 模块中,我如何查看二进制图像是几乎全黑还是全白?
我想过numpy.all
函数或 numpy.any
但我不知道对于全黑图像和几乎全黑图像如何。
最佳答案
假设所有像素确实是 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
关于python - 如果二进制图像几乎全黑,我如何检查 numpy?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22619506/