Reputation: 6275
I have an image I loaded using opencv, that I would like to find pixels that are white.
input_img = [[[255,255,255], [0,127,255]],
[[255,255,255], [255,127,255]]]
should return
white = [[1, 0],
[1, 0]]
Is there a way to do this without reshaping or without an expensive for loop? Using something like numpy.where?
Upvotes: 1
Views: 4182
Reputation: 1158
This should do it
input_img = [[[255,255,255], [0,127,255]],
[[255,255,255], [255,127,255]]]
white = np.array(np.sum(input_img, axis=-1) == 765, dtype=np.int32)
Upvotes: 3