通过标签索引图像获取像素值

问题描述 投票:1回答:1

我有一个被分割的RGB图像Img(256,256,3)。此图像的标签与标签值范围从Lbl(256,256)其中n是在图像中的簇的数目的阵列0-n。如何获得分配给特定集群像素的实际RGB值?例如,如何找到分配到集群1中的所有像素值?

我敢肯定有一个非常Python化的方式numpy的做到这一点。

python numpy indexing
1个回答
1
投票

你可以做,像这样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]))
© www.soinside.com 2019 - 2024. All rights reserved.