I have been scouring around and can't seem to find an answer to this question. Say I have a given RGB value, i.e. (255,0,25) or something like that.
I have a ndarray called 'img' of shape (height, width, 3). Now, I want to find the number of pixels in this array that equal my color. I thought doing
(img==(255,0,25)).sum() would work, but even if my image is a comprised only of the color (255,0,25), I will overcount and it seems that this is summing up when r=255, 0, or 25, and when g=255,0, or 25, and when b=255,0, or 25.
I have been searching the numpy documentation, but I can't find a way to compare pixel-wise, and not element-wise. Any ideas?
(img == (255,0,25)).all(axis=1).sum()axis=-1?axis=2and it gives the same asaxis=-1axis=-1. That said, an image is more likely a 3-D array.