I did read on numpy indexing but I didn't find what I was looking for.
I have a 288*384 image, where each pixel can have a labelling in [0,15].
It is stored in a 3d (288,384,16)-shaped numpy array im
.
With im[:,:,1]
, I can for example get the image where all pixels have the label 1.
I have another 2d array labelling
, (288*384)-shaped, containing a label for each pixel.
How do I get the image where each pixel has the corresponding pixel using some clever slicing?
Using loops, that would be:
result = np.zeros((288,384))
for x,y in zip(range(288), range(384)):
result[x,y] = im[x,y,labelling[x,y]]
But this is of course inefficient.