[英]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.