You could use np.unique
with its new axis
argument functionality that does grouping -
np.c_[np.unique(im.reshape(-1,3), axis=0, return_counts=1)]
Sample run -
In [56]: im
Out[56]:
array([[[255, 255, 255],
[255, 0, 0]],
[[255, 0, 255],
[255, 255, 255]]])
In [57]: np.c_[np.unique(im.reshape(-1,3), axis=0, return_counts=1)]
Out[57]:
array([[255, 0, 0, 1],
[255, 0, 255, 1],
[255, 255, 255, 2]])
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…