3D Marker Selection

MainPage || iamxt

 1 import numpy as np
 2 import iamxt
 3 import nibabel as nib
 4 import ia636
 5 
 6 sample = '/awmedia3/q/orig/LPBA40/native_space/S11/S11.native.mri.img'
 7 img = nib.load(sample)
 8 min_vol = 250000
 9 max_vol = 500000
10 sx,sy,sz = img.header['pixdim'][1:4]
11 
12 img = img.get_data()
13 img = ia636.ianormalize(img).astype(np.uint8)
14 
15 img = img[:,:,::-1,0].transpose(0,2,1)
16 
17 adshow(ia636.iamosaic(ia636.ianormalize(img),5),"Original image")
18 
19 Bc = np.zeros((3,3,3),dtype = bool)
20 Bc[1,1,:] = True
21 Bc[1,:,1] = True
22 Bc[:,1,1] = True
23 
24 mxt = iamxt.MaxTreeAlpha(img,Bc)
25 avg_gray = mxt.computeNodeGrayAvg()
26 var_gray = mxt.computeNodeGrayVar(avg_gray)
27 volume = mxt.node_array[3,:]*sx*sy*sz
28 dx = (mxt.node_array[7,:] -  mxt.node_array[6,:]  + 1)*sx
29 dy = (mxt.node_array[10,:] - mxt.node_array[9,:]  + 1)*sy
30 dz = (mxt.node_array[13,:] - mxt.node_array[12,:] + 1)*sz
31 RR = mxt.computeRR()
32 dx = dx.reshape(-1,1)
33 dy = dy.reshape(-1,1)
34 dz = dz.reshape(-1,1)
35 dims = np.concatenate((dx,dy,dz), axis = 1)
36 dims = np.sort(dims,axis = 1)
37 indexes = (volume > min_vol) & (volume < max_vol)
38 aux = np.nonzero(indexes)[0]
39 
40 
41 f = 1.0*(dims[:,0]*dims[:,1])/(dims[:,2]**2)*RR
42 f = f[indexes]
43 
44 node = np.argmax(f)
45 node = aux[node]
46 
47 cc = mxt.recConnectedComponent(node)
48 img[cc>0] = 255
49 
50 
51 adshow(ia636.iamosaic(ia636.ianormalize(img),5),"White-matter marker")

Original image

White-matter marker