简体   繁体   English

如何检查numpy中的二进制映像是否几乎全是黑色?

[英]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: 这是我能想到的想法清单:

  1. get the np.sum() and if it is lower than a threshold, then consider it almost black 获取np.sum() ,如果它小于阈值,则认为它几乎是黑色的
  2. calculate 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.

相关问题 如何将数组的二进制numpy列表转换为图像? - How can i transform my binary numpy list of arrays to an image? 如何比较二进制图像并在python中验证几乎相等? - How can i compare to binary images and verified are almost equal in python? 用NumPy填充图像会全黑 - Padding an image with NumPy returns it all black 我如何检查几乎所有行是否相同,如果是,则验证最后不同的行是否有一些常数 k - how can i check if almost all rows are identical and if so then verify that the final differing row varies by some constant k 如何从numpy数组的概率图中获取二进制图像? - How can I get a binary image from a probability map in a numpy array? 如何在PIL中选择与图像边缘相邻的所有黑色像素? - How can I select all black pixels that are contiguous with an edge of the image in PIL? 我应该如何检查张量流张量中的所有数字是否全部为二进制 - How should I check if all numbers in a tensorflow Tensor are all binary 如何在numpy数组中存储带尾随空值的二进制值? - How can I store binary values with trailing nulls in a numpy array? 如何将 numpy 转换为二进制(大小为 8 位) - How can I convert a numpy to a binary (size 8 bits) 如何将 integer 转换为其二进制表示形式为 numpy 数组? - How can I convert an integer to its binary representation as a numpy array?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM