Kristan
Kristan

Reputation: 387

How to count the number of pixels with a certain pixel value in python opencv?

I'd like to count the number of pixels with the value=[0,100,234] in an image.

Without using loops over the image, could you please propose a method of how to determine the number of these particular pixels?

Upvotes: 5

Views: 9225

Answers (1)

Miki
Miki

Reputation: 41775

To count the number of pixels with the value = [0,100,234] you can use:

np.count_nonzero((img == [0, 100, 234]).all(axis = 2))

Upvotes: 9

Related Questions