我有一个被分割的RGB图像Img(256,256,3)
。此图像的标签与标签值范围从Lbl(256,256)
其中n是在图像中的簇的数目的阵列0-n
。如何获得分配给特定集群像素的实际RGB值?例如,如何找到分配到集群1中的所有像素值?
我敢肯定有一个非常Python化的方式numpy的做到这一点。
你可以做,像这样np.where()
:
import numpy as np
# Make sample empty image
a = np.zeros((8,8),dtype=np.uint8)
# Label a couple of random pixels as "3" to find
a[2,2]=3
a[3,4]=3
# Find them
my3s = np.where(a==3)
Out[13]: (array([2, 3]), array([2, 4]))