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?
Figure 5: In OpenCV, pixels are accessed by their (x, y)-coordinates. The origin, (0, 0), is located at the top-left of the image. OpenCV images are zero-indexed, where the x-values go left-to-right (column number) and y-values go top-to-bottom (row number). Here, we have the letter “I” on a piece of graph paper.
The width and height of the image in pixels. To find the total number of pixels, multiply the width and height together. In this case, 4700 pixels x 3133 pixels = 14,725,100 pixels. That's a lot of pixels.
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))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With