Max-tree signature

MainPage || iamxt

 1 import numpy as np
 2 import iamxt
 3 import ia870
 4 import ia636
 5 
 6 img = adreadgray('/awmedia/www/media/Attachments/iamxt/MainPage/monalisa.jpg')
 7 
 8 x,y = 168,305 # Hand picked regional maximum
 9 bin_img = np.zeros(img.shape,dtype = bool)
10 bin_img[x,y] = True
11 bin_img = ia870.iadil(bin_img,ia870.iasedisk(5))
12 img2 = ia870.iagshow(img,bin_img)
13 adshow(img2,'Mona Lisa image with a regional maxima highlighted')
14 
15 
16 # Max-tree construction
17 Bc = np.ones((3,3), dtype = bool)
18 mxt = iamxt.MaxTreeAlpha(img,Bc)
19 node = mxt.node_index[x,y]
20 
21 # Area signature
22 A = mxt.node_array[3,:]
23 levels,signature =  mxt.getSignature(A, node)
24 adshow(ia636.iaplot(signature, levels,xlabel = 'Gray-level',ylabel = 'Area'))
25 
26 
27 #Getting the nodes before and after the largest drop
28 anc = mxt.getAncestors(int(node))[::-1]
29 area = A[anc]
30 gradient = area[0:-1]- area[1:]
31 indexes = np.argsort(gradient)
32 max1 = indexes[-1]
33 anc_max1 = [anc[max1],anc[max1+1]]
34 
35 
36 adshow(mxt.recConnectedComponent(anc_max1[0]),"Node %d, area %d" %(anc_max1[0],A[anc_max1[0]]))
37 adshow(mxt.recConnectedComponent(anc_max1[1]),"Node %d, area %d" %(anc_max1[1],A[anc_max1[1]]))

Mona Lisa image with a regional maxima highlighted

Node 81144, area 244024

Node 82019, area 27550

Do it yourself! #1

Try to segment the brain from the skull using area signature analysis.

 1 import numpy as np
 2 import iamxt
 3 
 4 img = adreadgray('/awmedia/www/media/Attachments/iamxt-tutorial/interactive_maxtree01/MRI_coronal.png')
 5 adshow(img, "Coronal brain image")
 6 x,y = 134,157 # Hand picked regional maximum
 7 bin_img = np.zeros(img.shape,dtype = bool)
 8 bin_img[x,y] = True
 9 bin_img = ia870.iadil(bin_img,ia870.iasedisk(5))
10 img2 = ia870.iagshow(img,bin_img)
11 adshow(img2,'Mona Lisa image with a regional maxima highlighted')
12 
13 # Max-tree construction
14 Bc = np.ones((3,3), dtype = bool)
15 mxt = iamxt.MaxTreeAlpha(img,Bc)
16 node = mxt.node_index[x,y]
17 
18 # Area signature
19 A = mxt.node_array[3,:]
20 levels,signature =  mxt.getSignature(A, node)
21 adshow(ia636.iaplot(signature, levels,xlabel = 'Gray-level',ylabel = 'Area'))
22 
23 
24 #Getting the nodes before and after the largest drop
25 anc = mxt.getAncestors(int(node))[::-1]
26 area = A[anc]
27 gradient = area[0:-1]- area[1:]
28 indexes = np.argsort(gradient)
29 
30 for max1 in indexes[-5:]:
31     anc_max1 = [anc[max1],anc[max1+1]]
32     # precisa usar for
33     adshow(mxt.recConnectedComponent(anc_max1[0]),"Node %d, area %d" %(anc_max1[0],A[anc_max1[0]]))
34     adshow(mxt.recConnectedComponent(anc_max1[1]),"Node %d, area %d" %(anc_max1[1],A[anc_max1[1]]))

Coronal brain image

Mona Lisa image with a regional maxima highlighted

Node 53, area 28764

Node 94, area 26899

Node 967, area 11221

Node 999, area 9275

Node 2616, area 2344

Node 2653, area 1

Node 1251, area 7562

Node 1293, area 5206

Node 0, area 65536

Node 53, area 28764

Do it yourself! #2

Try to segment the brain from the skull using area signature analysis.

1 import numpy as np
2 import iamxt
3 
4 img = adreadgray('/awmedia/www/media/Attachments/iamxt-tutorial/interactive_maxtree01/MRI_sagittal.png')
5 adshow(img, "Sagittal brain image")

Sagittal brain image