Filtering a 3D Brain MRI

MainPage

 1 from max_tree_alpha import MaxTreeAlpha
 2 from toolbox.fattach import find_attachment_files
 3 import dicom
 4 import os
 5 import ia636
 6 import homedanilo.library_dpereira84_dicom as lib
 7 import nibabel as nib
 8 import numpy as np
 9 
10 
11 # Loading and normalizing the volume
12 #filename = 'PHILIPS/DICOM/IM_0040'
13 #dataset = dicom.read_file(find_attachment_file(filename))
14 #data = dataset.pixel_array
15 
16 data = nib.load('/awmedia/www/media/p/Simone/Freesurfer/T1_selected/IM_1371.nii.gz').get_data()
17 data = nib.load(find_attachment_file('volume_depois.nii')).get_data()
18 #data = ia636.ianormalize(data[20:-25]).astype(np.uint8).T
19 data = ia636.ianormalize(data).astype(np.uint8).T
20 adshow(ia636.iamosaic(data,8), "Original Volume")
21 
22 
23 #Building the max-tree
24 Bc = np.ones((3,3,3), dtype = bool)
25 mxt = MaxTreeAlpha(255 - data,Bc)
26 print "Nb of nodes:", mxt.node_array.shape[1]
27 print "Nb of leaves:", (mxt.node_array[1,:] == 0).sum()
28 
29 
30 
31 n = 8
32 V = mxt.computeVolume()
33 Vext = mxt.computeExtinctionValues(V, "volume")
34 mxt.extinctionFilter(Vext,n)
35 mxt = MaxTreeAlpha(255 - mxt.getImage(),Bc)
36 V = mxt.computeVolume()
37 Vext = mxt.computeExtinctionValues(V, "volume")
38 mxt.extinctionFilter(Vext,n)
39 
40 
41 
42 
43 
44 adshow(ia636.iamosaic(mxt.getImage()[:,:,:],8), "After the Extinction Filter n = %d" %n)
45 
46 
47 mxt.mmsT(t = 0.0)
48 adshow(ia636.iamosaic(mxt.getImage()[:,:,:],8), "After the MMS Filter")
49 
50 for i in xrange(mxt.node_array.shape[1] -1,0,-1):
51     cc = mxt.recConnectedComponent(i)
52     adshow(ia636.iamosaic(cc[:,:,:],8), "Node  %d" %i)
53 
54 #g= mxt.generateGraph()
55 #mmgraphviz(g, title='Final max-tree node:level[area]')
Nb of nodes: 93863
Nb of leaves: 43678

Original Volume

After the Extinction Filter n = 8

After the MMS Filter

Node 15

Node 14

Node 13

Node 12

Node 11

Node 10

Node 9

Node 8

Node 7

Node 6

Node 5

Node 4

Node 3

Node 2

Node 1