forked from RockStarCoders/alienMarkovNetworks
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathisprs.py
36 lines (33 loc) · 1.34 KB
/
isprs.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import scipy.io
import superPixels
import numpy as np
# This is a superpixel result
def loadISPRSResultFromMatlab( fn ):
# a mat file, from paul S.
matdata = scipy.io.loadmat( fn )['superpix']
matlabels = matdata['label'][0,0] # labels start at 1 here
matprobs = matdata['prob'][0,0]
# the labels are out of order for probabilities. Paul has: impervious, bldg, car, low veg, tree, clutter
#matprobs = matprobs[:, np.array([1,2,4,5,3,6])-1]
# currently my code relies on consecutive superpixels starting at 0
ulabs = np.unique( matlabels )
# replace matlabels values with renumbered labels.
labelMap = np.zeros( (ulabs.max()+1,), dtype=int )
for i,l in enumerate(ulabs):
labelMap[l] = i
matlabels = labelMap[ matlabels ]
nodes, edges = superPixels.make_graph(matlabels)
spix = superPixels.SuperPixelGraph(matlabels,nodes,edges)
# todo: I think I probably need to reduce these probs to correspond to the
# ordinal labels in the superpixel graph.
classProbs = matprobs[ ulabs-1, : ]
return (spix, classProbs)
colourMap = [\
('Impervious surfaces' , (255, 255, 255)),
('Building' , (0, 0, 255)),
('Low vegetation' , (0, 255, 255)),
('Tree' , (0, 255, 0)),
('Car' , (255, 255, 0)),
('Clutter/background' , (255, 0, 0))\
]
classLabels = [z[0] for z in colourMap]