forked from RockStarCoders/alienMarkovNetworks
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtestFeatures.py
executable file
·59 lines (48 loc) · 1.63 KB
/
testFeatures.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/usr/bin/env python
import sys
import pomio
import amntools
import matplotlib.pyplot as plt
import numpy as np
import FeatureGenerator
import matplotlib
# Load all data
print 'Loading all data...'
# first arg should be msrc data path
data = pomio.msrc_loadImages( sys.argv[1], ['Images/7_3_s.bmp'])
# get particular image we like
ex = data[0]
plt.figure()
plt.imshow(ex.m_img)
plt.title('original image')
plt.figure()
clrs = [[z/255.0 for z in c[1]] for c in pomio.msrc_classToRGB]
pomio.showLabels( ex.m_gt )
plt.title('ground truth labels' )
print 'unique class labels: ', np.unique(ex.m_gt)
# generate features
imagePixelFeatures = FeatureGenerator.generatePixelFeaturesForImage(ex.m_img)
# For each feature, how many distinct values?
for i in range(imagePixelFeatures.shape[1]):
print "Feature %d has %d distinct values" \
% (i, len(np.unique( imagePixelFeatures[:,i])) )
# Plot a selection of features
sel = np.arange(26,30)
# sel = range(80,86)
# colours have to be on range 0-1
plt.figure()
# just plot some of the data for clarity
nbpts = 2000
ptsz = 5
whichPts = np.random.choice( imagePixelFeatures.shape[0], nbpts, replace=False)
# python weirdness, can't index from 2 lists at once...
subset = imagePixelFeatures[whichPts,:]
subset = subset[:,sel]
labelSubset = np.reshape(ex.m_gt, (imagePixelFeatures.shape[0],1))[whichPts].squeeze()
print labelSubset.shape
# todo: fix bug, displayed labels not right, car cluster should be lower right
amntools.gplotmatrix( subset,\
labelSubset, \
#ex.m_gt.flatten(1)[whichPts], \
msize=ptsz, classColours=clrs)
plt.show()