我有一个可用颜色的数组,我说它们在YCrCb空间中,我想按Y通道(第一个通道)对数组进行排序,而不会弄乱颜色元素。
我的数组:
colors = np.array([[[191,142,109],[196,138,116],[193,144,111],[198,140,118]]],dtype=np.uint8)
colors.shape
# (1,4,3)
我想要的输出:
array([[[191,dtype=uint8)
我尝试过的但不起作用
我正在使用np.sort
。但是我注意到如果我这样做:
np.sort(colors,axis=2)
# array([[[109,191],# [116,196],# [111,193],# [118,198]]],dtype=uint8)
它不会重新排列元素,而是重新排列通道中元素的值。
我使用的另一种策略:
np.sort(pallete.reshape(-1,3),axis=0)
# array([[191,# [193,# [196,# [198,118]],dtype=uint8)
那个误导了我,与我想要的东西非常相似,但是却弄乱了颜色元素。