3D Max-tree Marker Selection

MainPage

 1 import numpy as np
 2 from homeroberto.homeroberto_max_tree_alpha import MaxTreeAlpha #16 bit max-tree
 3 import nibabel as nib
 4 import os
 5 import ia636
 6 import time
 7 from homedavidsantos.iamosaic_color import iamosaic_color
 8 
 9 LPBA_PATH = '/awmedia3/q/orig/LPBA40/native_space'
10 sufix1 = '.native.mri.img'
11 
12 subject ='S11'
13 
14 RESULTS_PATH1 = '/awmedia3/q/proc/LPBA_SS_Study/our01'
15 RESULTS_PATH2 = '/awmedia3/q/proc/LPBA_SS_Study/ws3d'
16 
17 #parameters
18 n = 15
19 a = 200
20 perc = 0.20
21 ncols = 5
22 t1 = -1
23 
24 #Structuring element (SE)
25 Bc = np.zeros((3,3,3), dtype = bool)
26 Bc[1,1,:] = True
27 Bc[:,1,1] = True
28 Bc[1,:,1] = True
29 
30 LUT = np.load('/awmedia/www/media/Attachments/homedavidsantos/MainPage/lut.npy')
31 
32 orig_img = os.path.join(LPBA_PATH,subject,subject + sufix1)
33 print orig_img
34 data = nib.load(orig_img).get_data()[:,:,:,0]
35 
36 
37 data = data.astype(np.int32)
38 MAX = data.max()
39 print 'MAX: %d' %MAX
40 data = data*(data>t1)
41 data2 = data[:,:,::-1].transpose(0,2,1)
42 data2 = ia636.ianormalize(data2).astype(np.uint8)
43 adshow(ia636.iamosaic(data2,ncols), "Original Volume")
/awmedia3/q/orig/LPBA40/native_space/S11/S11.native.mri.img
MAX: 321

Original Volume

Our method

 1 t = time.time()
 2 mxt = MaxTreeAlpha(data,Bc)
 3 mxt.areaOpen(a)
 4 area_open = mxt.getImage()
 5 
 6 H = mxt.computeHeight()
 7 Hext = mxt.computeExtinctionValues(H,"height")
 8 mxt.extinctionFilter(Hext,n)
 9 
10 leaves = np.where(mxt.node_array[1,:]== 0)[0]
11 to_prune = np.ones(mxt.node_array.shape[1], dtype = bool)
12 for i in xrange(leaves.size):
13     anc = mxt.getAncestors((mxt.getBifAncestor(leaves[i])))
14     to_prune[anc] = False
15 
16 mxt.prune(to_prune)
17 
18 data_pre_flooded = mxt.getImage()
19 
20 data_pre_flooded_neg = MAX - data_pre_flooded
21 
22 
23 m = np.zeros(data_pre_flooded_neg.shape, dtype = np.int32)
24 leaves = np.where(mxt.node_array[1,:]== 0)[0]
25 leaves_area = mxt.node_array[3,leaves]
26 indexes = np.argsort(leaves_area)[::-1]
27 #m = mmero(mxt.recConnectedComponent(leaves[indexes[1]]))*3
28 #m = m + mxt.recConnectedComponent(leaves[0])
29 for i in indexes: #[2:]:
30     m = m + mxt.recConnectedComponent(leaves[i])*(i+1)
31 #m[0,:,:] = leaves.size + 1
32 #m[-1,:,:] = leaves.size + 1
33 #m[:,0,:] = leaves.size + 1
34 #m[:,-1,:] = leaves.size + 1
35 #m[:,:,0] = leaves.size + 1
36 #m[:,:,-1] = leaves.size + 1
37 
38 print 'Processing time: %f' %(time.time() -t)
Processing time: 6.429702

Max-tree Markers

1 m2 = m[:,:,::-1].transpose(0,2,1)
2 m3 = LUT[m2]
3 adshow(iamosaic_color(m3,ncols),'Markers')

Markers