I would recommend the follwoing approach instead of using loops directly:
# image.shape = (height, width, colors) # pixel = np.array([R, G, B]), i.e.numpy array of length <the number of colors> # threshold -- scalar value, takes into account color similarity np.where((np.abs(pixel - image) < threshold).all(axis=-1))