forked from jqug/mobile-microscopy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplot-patches-by-classification-score.py
executable file
·57 lines (51 loc) · 1.77 KB
/
plot-patches-by-classification-score.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
'''
Show examples of image patches classified arranged by different classification
probabilities. After running the classification experiment, this file can be
run by sourcing in the same ipython environment:
run -i plot-patches-by-classification-score.py
'''
thresholds = [.6, .3, 0]
ncols = 8
nrows = len(thresholds)
for row in range(nrows):
thresh = thresholds[row]
idx = np.where(np.logical_and(predictions>thresh, predictions<(thresh+.1)))[0]
idx = np.random.permutation(idx)
npatchesperimage = len(ytest)/len(testfiles)
offset = 0
for i in range(ncols):
found = False
while not found:
imageidx = idx[i+offset]/npatchesperimage
patchidx = idx[i+offset] % npatchesperimage
if patchidx<300:
found = True
else:
offset += 1
fname = IMAGE_DIR + testfiles[imageidx]
img = cv2.imread(fname)
height, width, channels = img.shape
patchcount = 0
finished = False
x = step
y = step
while y<height and not finished:
x = step;
while (x<width) and not finished:
if patchcount==patchidx:
left = x - size/2
right = x + size/2
top = y - size/2
bottom = y + size/2
patch = img[top:bottom, left:right, :]
finished = True
patchcount += 1
x+=step
y += step
plt.subplot(nrows, ncols, row*ncols + i)
plt.imshow(patch)
plt.xticks([])
plt.yticks([])
if i==1:
ylabel('%.1f-%.1f' % (thresh, thresh+.1))
plt.savefig('output-patches-by-threshold.pdf', bbox_inches='tight')