2D Brain Segmentation Demo

MainPage

 1 from max_tree_alpha import MaxTreeAlpha
 2 import numpy as np
 3 from ia636 import ialogfilter,ianormalize
 4 
 5 
 6 # Parameters of the method
 7 option = "MSER" #Options "MSER" "T"
 8 n = 8
 9 t = 0.2 # It is only used if option ="T"
10 attr = "area" # options: "volume", "height", "area"
11 
12 #Reading and displaying image
13 img = adreadgray('Attachments/iamxt/MainPage/img_mri_brain.jpg')[:,::-1].copy()
14 img = adreadgray(find_attachment_file("homeroberto/homeroberto_draft29/axial.png"))
15 #img = ianormalize(ialogfilter(img, 0.7)).astype(np.uint8)
16 
17 Bc = np.ones((3,3),dtype = bool)
18 # Building the max-tree
19 mxt = MaxTreeAlpha(img,Bc)
20 
21 adshow(img, "Original Image (%d shapes)" % mxt.node_array.shape[1])
22 
23 
24 # Computinng ectinction values of attr
25 if attr == "volume":
26   ext = mxt.computeExtinctionValues(mxt.computeVolume(),attr)
27 elif attr == "height":
28   ext = mxt.computeExtinctionValues(mxt.computeHeight(),attr)
29 elif attr == "area":
30   ext = mxt.computeExtinctionValues(mxt.node_array[3,:],attr)
31 
32 
33 # Result of the extinction filter
34 mxt.extinctionFilter(ext,n)
35 img_ef = mxt.getImage()
36 adshow(img_ef, 'Image after the Extinction %s Filter (%d shapes)' % (attr,mxt.node_array.shape[1]))
37 
38 
39 # Result of the mms filter
40 sb = mxt.getSubBranches()
41 if option == "MSER":
42   sm = mxt.computeStabilityMeasure()
43   mxt.mmsMSER(sm)
44 elif option == "T":
45   mxt.mmsT(t)
46 
47 img_mms= mxt.getImage()
48 adshow(img_mms, 'Image after the EF + MMS-%s, (%d shapes)' % (option,mxt.node_array.shape[1]))

Original Image (6700 shapes)

Image after the Extinction area Filter (810 shapes)

Image after the EF + MMS-MSER, (16 shapes)

Max-tree Graph

1 area = mxt.node_array[3,:]
2 mmgraphviz(mxt.generateCCGraph(parent_scale = True))#, LR = True
3 RR = mxt.computeRR()
4 for i in xrange(mxt.node_array.shape[1]):
5     #xmin,xmax = mxt.node_array[6,i],mxt.node_array[7,i] + 1
6     #ymin,ymax = mxt.node_array[9,i],mxt.node_array[10,i] + 1
7     adshow(mxt.recConnectedComponent(i),"Node %d, rr %f" %(i,RR[i]))
/media/_xsb/iamxt/brain_segmentation/GRVIZ48234_001.png

Node 0, rr 1.000000

Node 1, rr 0.764857

Node 2, rr 0.184224

Node 3, rr 0.743922

Node 4, rr 0.049843

Node 5, rr 0.052945

Node 6, rr 0.564571

Node 7, rr 0.389162

Node 8, rr 0.087189

Node 9, rr 0.423337

Node 10, rr 0.348014

Node 11, rr 0.292560

Node 12, rr 0.280131

Node 13, rr 0.420617

Node 14, rr 0.219791

Node 15, rr 0.377653