[英]How can i check in numpy if a binary image is almost all black?
How can i see in if a binary image is almost all black or all white in numpy or scikit-image modules ? 我如何查看numpy或scikit-image模块中的二进制映像是几乎全黑还是全白?
I thought about numpy.all
function or numpy.any
but i do not know how neither for a total black image nor for a almost black image. 我考虑过
numpy.all
函数或numpy.any
但我不知道如何不使用全黑图像或几乎全黑图像。
Here is a list of ideas I can think of: 这是我能想到的想法清单:
np.sum()
and if it is lower than a threshold, then consider it almost black np.sum()
,如果它小于阈值,则认为它几乎是黑色的 np.mean()
and np.std()
of the image, an almost black image is an image that has low mean and low variance np.mean()
和np.std()
,近乎黑色的图像是均值低且方差低的图像 Assuming that all the pixels really are ones or zeros, something like this might work (not at all tested): 假设所有像素实际上都是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.