How can I count how many black and white pixels are on a picture?

Hello!

After turning an image grayscale I figured the best solutions for one of my projects would be if I could count the amount of white pixels on a picture, is there a way to loop through the pixels on the picture and get their colour?

I would appreciate some kind intellect to help me find a solution! :slight_smile:

look at countNonZero()

if you have a grayscale image, not a binary one, you probably have to add some condition:

n = cv.countNonZero(gray == 255) # count only "full-on" pixels
1 Like