2D Brain Signature Demo

MainPage

 1 from iamxt import MaxTreeAlpha
 2 import numpy as np
 3 import ia870
 4 import ia636
 5 import matplotlib.pyplot as plt
 6 
 7 
 8 img = adreadgray(find_attachment_file('homeroberto/homeroberto_draft09/brain_demo.png'))
 9 
10 Bc = np.ones((3,3),dtype = bool)
11 mxt = MaxTreeAlpha(img,Bc)
12 adshow(img, "Original Image (%d shapes, %d maxima)" %(mxt.node_array.shape[1],(mxt.node_array[1,:] == 0).sum()))
13 
14 A = mxt.node_array[3,:]
15 ext = mxt.computeExtinctionValues(A,"area")
16 leaf = argsort(ext)[::-1][1] # Manually selected, 3rd highest extinction value
17 leaf_cc = mxt.recConnectedComponent(leaf)
18 leaf_cc = ia870.iadil(leaf_cc,ia870.iasedisk(5))
19 img2 = ia870.iagshow(img,leaf_cc)
20 adshow(img2,'Regional maxima selected')
21 
22 levels,signature =  mxt.getSignature(A, leaf)
23 adshow(ia636.iaplot(signature, levels,xlabel = 'Gray-level',ylabel = 'Area'), "Area signature")
24 gradient = signature[0:-1] - signature[1:]
25 adshow(ia636.iaplot(gradient, levels[0:-1],xlabel = 'Gray-level',ylabel = 'Gradient of the area signature'),
26 "Gradient of the area signature")
27 
28 
29 
30 indexes = np.argsort(gradient)[::-1][1:2]
31 
32 for index in indexes:
33     area1 = signature[index]
34     area2 = signature[index + 1]
35 
36     node1 = np.where(mxt.node_array[3,:] == area1)[0][0]
37     node2 = np.where(mxt.node_array[3,:] == area2)[0][0]
38 
39     fig = plt.figure()
40     ax = fig.add_subplot(111)
41 
42     adshow(mxt.recConnectedComponent(node1), "Reconstruction at h = %d" %mxt.node_array[2,node1])
43     adshow(mxt.recConnectedComponent(node2), "Reconstruction at h = %d" %mxt.node_array[2,node2])
44 
45     cc_graph = mxt.generateCCPathGraph(leaf,0, parent_scale = False, LR = True)
46     mmgraphviz(cc_graph, title='CC Path Signature')
47 print area1
48 print area2
49 print mxt.node_array[2,node1]
50 print mxt.node_array[2,node2]
51 
52 
53 
54 #fig = plt.figure(facecolor = 'w')
55 #ax = fig.add_subplot(111)
56 
57 
58 
59 #line, = ax.plot(levels,signature, linewidth = 2.0)#,xlabel = 'Gray-level',ylabel = 'Area')
60 #ax.annotate('area = 24989', xy=(35.5, area1+150), xytext=(43, area1),
61 #        arrowprops=dict(facecolor='black', shrink=0.05),)
62 
63 #ax.annotate('area = 12291', xy=(35.5, area2), xytext=(22, area2),
64 #        arrowprops=dict(facecolor='black', shrink=0.05),
65 #        horizontalalignment='right',verticalalignment='right')
66 
67 
68 #ax.set_xlabel("Gray-level")
69 #ax.set_ylabel("Area")
70 #ax.grid()
71 #adshow(ia636.iafig2img(fig))
24989
12291
35
36

Original Image (5003 shapes, 2058 maxima)

Regional maxima selected

Area signature

Gradient of the area signature

Reconstruction at h = 35

Reconstruction at h = 36

/media/_xsb/iamxt/brain_signature/GRVIZ66367_001.png

CC Path Signature