I am trying to get a list of an image's pixels that are different from a specific color using NumPy.
For example, while processig the following image:
I've managed to get a list of all black pixels using:
np.where(np.all(mask == [0,0,0], axis=-1))
But when I try to do:
np.where(np.all(mask != [0,0,0], axis=-1))
I get a pretty strange result:
It looks like NumPy has returned only the indices were R, G, and B are non-0
Here is a minimal example of what I'm trying to do:
import numpy as np
import cv2
# Read mask
mask = cv2.imread("path/to/img")
excluded_color = [0,0,0]
# Try to get indices of pixel with different colors
indices_list = np.where(np.all(mask != excluded_color, axis=-1))
# For some reason, the list doesn't contain all different colors
print("excluded indices are", indices_list)
# Visualization
mask[indices_list] = [255,255,255]
cv2.imshow(mask)
cv2.waitKey(0)


