Lung CT Segmentation

 1 from homeroberto.max_tree_alpha import MaxTreeAlpha
 2 import numpy as np
 3 from mmorph import *
 4 import ia636 as ia
 5 from homeroberto.max_tree_toolbox import evsFilter
 6 from homeroberto.rob_max_tree import SSIMIndex
 7 
 8 
 9 # Reading and displaying the image
10 file_ = find_attachment_file('homeroberto/rob_ilus01/3519.dcm')
11 dataset = dicom.read_file(file_)
12 ct = dataset.pixel_array.astype(float64)
13 
14 img = ia.ianormalize(ct).astype('uint8')
15 adshow(img,'Imagem CT')
16 n = 10
17 
18 # Building the Max-Tree
19 mxt = MaxTreeAlpha(mmneg(img))
20 
21 # Applying the EF
22 V = mxt.computeVolume()
23 Vext = mxt.getExtinctionValues(V,"volume")
24 mxt = evsFilter(mxt,Vext,n)
25 
26 ef_img = mmneg(mxt.getImage())
27 print 'SSIM index after the EF: ', SSIMIndex(img,ef_img)
28 adshow(ef_img, 'Image after the EF')
29 
30 
31 # Applying the MMS-T
32 sb = mxt.getSubBranches()
33 mxt.mmsT(sb , t = 0.5)
34 
35 mms_img = mmneg(mxt.getImage())
36 print 'SSIM index after the EF + MMS-T: ', SSIMIndex(img,mms_img)
37 adshow(mms_img, 'Image after EF + MMS-T filter')
38 
39 # Drawing the CC of the Max-Tree
40 mmgraphviz(mxt.generateCCGraph(parent_scale = True),title='Max-tree after the MMS filter')
41 
42 # Segmentation of the lungs
43 adshow(np.logical_or(mxt.recLevelComponent(4),mxt.recLevelComponent(5)), 'Reconstruction of nodes 4 and 5')
SSIM index after the EF:  0.997508208016
SSIM index after the EF + MMS-T:  0.923889979385

Imagem CT

Image after the EF

Image after EF + MMS-T filter

/media/_xsb/code/lung_ct_segmentation_ef_mms/GRVIZ39480_001.png

Max-tree after the MMS filter

Reconstruction of nodes 4 and 5