I have a label matrix of 256*256 for example. And the classes are 0-11 so 12 classes. I want to convert the label matrix to colour matrix. I tried do it in a code like this
`for i in range(256):
for j in range(256):
if x[i][j] == 11:
dummy[i][j] = [255,255,255]
if x[i][j] == 1:
dummy[i][j] = [144,0,0]
if x[i][j] == 2:
dummy[i][j] = [0,255,0]
if x[i][j] == 3:
dummy[i][j] = [0,0,255]
if x[i][j] == 4:
dummy[i][j] = [144,255,0]
if x[i][j] == 5:
dummy[i][j] = [144,0,255]
if x[i][j] == 6:
dummy[i][j] = [0,255,255]
if x[i][j] == 7:
dummy[i][j] = [122,0,0]
if x[i][j] == 8:
dummy[i][j] = [0,122,0]
if x[i][j] == 9:
dummy[i][j] = [0,0,122]
if x[i][j] == 10:
dummy[i][j] = [122,0,122]
if x[i][j] == 11:
dummy[i][j] = [122,122,0]
`
It is highly inefficient. PS: the shape of x is [256 256] and dummy is [256 256 3]. Is there any better way to do it ?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…