문제

How can i see in if a binary image is almost all black or all white in numpy or scikit-image modules ?

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.

도움이 되었습니까?

해결책

Assuming that all the pixels really are ones or zeros, something like this might work (not at all tested):


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

다른 팁

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
  2. calculate np.mean() and np.std() of the image, an almost black image is an image that has low mean and low variance
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top