Find Tract Bounding Boxes


In [1]:
#f = '/media/sf_SharedFolder/Code/libraries_of_mine/github/ConWhAt/ConWhAt/atlases/volumetric/dipy_dsi_sd4_l2k8_sc33/vismap_grp_cat_rois_v2_70_norm.nii.gz'

Importage


In [2]:
%matplotlib inline

from matplotlib import pyplot

import nibabel as nib

from nilearn.plotting import plot_stat_map

from nilearn.image import index_img


/home/john/Software/anaconda/envs/_ipython2.4/lib/python2.7/site-packages/matplotlib/font_manager.py:273: UserWarning: Matplotlib is building the font cache using fc-list. This may take a moment.
  warnings.warn('Matplotlib is building the font cache using fc-list. This may take a moment.')

In [3]:
from mpl_toolkits.mplot3d import Axes3D
from matplotlib import pyplot as plt
import numpy as np
from itertools import product,combinations
%matplotlib inline

In [ ]:
from nilearn.plotting import cm as nl_cm

In [4]:
import os,sys

In [17]:
import pandas as pd

In [5]:
sys.path.append('/media/sf_SharedFolder/Code/libraries_of_mine/github/ConWhAt')

In [6]:
import ConWhAt

In [7]:
from ConWhAt.volumetric.utils import get_bounding_box_inds,plot_cube_from_bb,plot_vol_scatter,get_intersection

In [8]:
# These are all now in volumetric/utils.py

"""
def get_bounding_box_inds(dat):
    
  nzx,nzy,nzz = np.nonzero(dat>0)
  xmin,xmax = nzx.min(),nzx.max()
  ymin,ymax = nzy.min(),nzy.max()
  zmin,zmax = nzz.min(),nzz.max()
    
  minmaxarr = np.array([[xmin,xmax],[ymin,ymax],[zmin,xmax]])    
    
  return minmaxarr
  
    
    
def plot_cube_from_bb(bb,ax=None,c='b'):

  corners = np.array(list(product(bb[0],
                                  bb[1],
                                  bb[2])))
    
  cornerpairs = list(combinations(corners,2))

  linestoplot = [(s,e) for (s,e) in cornerpairs if ((np.abs(s-e) == 0).sum() == 2)]
    

  if not ax:
    fig = plt.figure()
    ax = fig.gca(projection='3d')
    ax.set_aspect('equal')

    
  for (s,e) in linestoplot: 
    ax.plot3D(*zip(s,e), color=c) 
        
    
    
  
def plot_vol_scatter(dat,ax=None, pointint = 50,c='b',alpha=0.2,s=20.,
                     xlim=[0,100],ylim=[0,100],zlim=[0,100],marker='o',figsize=(10,10),
                     linewidth=0.01):
    
  xs,ys,zs = np.nonzero(dat>0)    
  idx = np.arange(0,xs.shape[0],pointint)

  if not ax: 
    fig = plt.figure(figsize=figsize)
    ax = fig.gca(projection='3d')
    ax.set_aspect('equal')
    ax.set_xlim([xlim[0],xlim[1]])  
    ax.set_ylim([ylim[0],ylim[1]])
    ax.set_zlim([zlim[0],zlim[1]])

  ax.scatter3D(xs[idx],ys[idx],zs[idx],c=c,alpha=alpha,s=s, marker=marker,linewidths=linewidth)
    
    
def get_intersection(bba,bbb):
    
  (xa1,xa2),(ya1,ya2),(za1,za2) = bba
  (xb1,xb2),(yb1,yb2),(zb1,zb2) = bbb
    
  SI = max(0, min(xa2,xb2) - max(xa1,xb1)) \
     * max(0, min(ya2,yb2) - max(ya1,yb1)) \
     * max(0, min(za2,zb2) - max(za1,zb1))

  return SI
""";

Test cases


In [64]:
A_xyz = [[-5,10],
         [-11,21],
         [-20,30]]


B_xyz = [[-3,15],
         [-20,2],
         [-4,12]]

fig = plt.figure(figsize=(10,10))
ax = fig.gca(projection='3d')
#ax.set_aspect('equal')

plot_cube_from_bb(A_xyz,ax=ax,c='b')
plot_cube_from_bb(B_xyz,ax=ax,c='r')


xa1,xa2 = A_xyz[0]
ya1,ya2 = A_xyz[1]
za1,za2 = A_xyz[2]

xb1,xb2 = B_xyz[0]
yb1,yb2 = B_xyz[1]
zb1,zb2 = B_xyz[2]


SI = get_intersection(A_xyz,B_xyz)
SI


Out[64]:
2704

In [65]:
A_xyz = [[-5,10],
         [-11,21],
         [-20,30]]


B_xyz = [[15,30],
         [-20,-15],
         [-4,12]]

fig = plt.figure(figsize=(10,10))
ax = fig.gca(projection='3d')
#ax.set_aspect('equal')

plot_cube_from_bb(A_xyz,ax=ax,c='b')
plot_cube_from_bb(B_xyz,ax=ax,c='r')


xa1,xa2 = A_xyz[0]
ya1,ya2 = A_xyz[1]
za1,za2 = A_xyz[2]

xb1,xb2 = B_xyz[0]
yb1,yb2 = B_xyz[1]
zb1,zb2 = B_xyz[2]

SI = get_intersection(A_xyz,B_xyz)


SI


Out[65]:
0

In [68]:
A_xyz = [[-5,10],
         [-11,21],
         [-20,30]]


B_xyz = [[15,30],
         [-20,-15],
         [40,50]]

fig = plt.figure(figsize=(10,10))
ax = fig.gca(projection='3d')
ax.view_init(0,90)
#ax.set_aspect('equal')

plot_cube_from_bb(A_xyz,ax=ax,c='b')
plot_cube_from_bb(B_xyz,ax=ax,c='r')


xa1,xa2 = A_xyz[0]
ya1,ya2 = A_xyz[1]
za1,za2 = A_xyz[2]

xb1,xb2 = B_xyz[0]
yb1,yb2 = B_xyz[1]
zb1,zb2 = B_xyz[2]



SI = get_intersection(A_xyz,B_xyz)

ax.view_init(90,90)


SI


Out[68]:
0

Get bounding box for test image


In [9]:
test_file = '/media/sf_SharedFolder/Code/libraries_of_mine/github/ConWhAt/ConWhAt/scratch/lesion_test_file_from_jhu.nii.gz'

In [10]:
test_img = nib.load(test_file)

tbb = get_bounding_box_inds(test_img.get_data())

In [11]:
tbb


Out[11]:
array([[47, 59],
       [46, 91],
       [25, 59]])

Get bounding boxes for jhu tracts


In [12]:
f = '/usr/share/fsl/data/atlases/JHU/JHU-ICBM-tracts-prob-2mm.nii.gz'

In [13]:
jhu_img = nib.load(f)
jhu_bbs = []

for j in range(jhu_img.shape[3]):
  dat = index_img(jhu_img,j).get_data()
  bb = get_bounding_box_inds(dat)
  jhu_bbs.append(bb)

Find which JHU bounding boxes overlap with test file


In [14]:
jhu_is = []

for jbb in jhu_bbs:
  I = get_intersection(tbb,jbb)
  jhu_is.append(I)

In [15]:
jhu_is


Out[15]:
[18360,
 10800,
 5304,
 3045,
 10530,
 0,
 8160,
 0,
 792,
 15504,
 18360,
 0,
 12240,
 0,
 14688,
 0,
 17136,
 0,
 18360,
 0]

Now check that these are correct


In [16]:
jhu_overlaps = []

for j in range(jhu_img.shape[3]):

  overlap = ((index_img(jhu_img,j).get_data()>0) * (test_img.get_data()>0)).sum()
  jhu_overlaps.append(overlap)

In [18]:
df = pd.DataFrame([jhu_is,jhu_overlaps],index=['IS', 'overlap'])

In [19]:
df


Out[19]:
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
IS 18360 10800 5304 3045 10530 0 8160 0 792 15504 18360 0 12240 0 14688 0 17136 0 18360 0
overlap 1258 0 10 0 0 0 0 0 0 202 402 0 0 0 42 0 282 0 1 0

When the bounding box overlap is zero, the overlap should be zero; although not necessarily vice versa.

This is the case :)

Show visually:


In [26]:
img1 = test_img
dat1 = img1.get_data()
dat1_bb = get_bounding_box_inds(dat1)

In [39]:
# Get bounding box
volnum = 0
img2 = index_img(jhu_img,volnum)
dat2 = img2.get_data()
dat2_bb = get_bounding_box_inds(dat2)


# Plot with nilearn
display = plot_stat_map(img2,cmap= nl_cm.black_blue,alpha=0.5,colorbar=False)
display.add_overlay(img1,colorbar=False,alpha=0.5,cmap='hot')

# Plot bounding boxes
fig = plt.figure(figsize=(10,10))
ax = fig.gca(projection='3d')
ax.set_aspect('equal')
ax.set_xlim([0,100])  
ax.set_ylim([0,100])
ax.set_zlim([0,100])

plot_vol_scatter(dat1,ax=ax,c='b',alpha=1.,s=20,marker='o')
plot_vol_scatter(dat2,ax=ax,c='r',alpha=1.,s=20,marker='o')

plot_cube_from_bb(dat1_bb,ax=ax,c='b')
plot_cube_from_bb(dat2_bb,ax=ax,c='r')

plt.tight_layout()

print df[volnum]


IS         18360
overlap     1258
Name: 0, dtype: int64

In [40]:
# Get bounding box
volnum = 1
img2 = index_img(jhu_img,volnum)
dat2 = img2.get_data()
dat2_bb = get_bounding_box_inds(dat2)


# Plot with nilearn
display = plot_stat_map(img2,cmap= nl_cm.black_blue,alpha=0.5,colorbar=False)
display.add_overlay(img1,colorbar=False,alpha=0.5,cmap='hot')

# Plot bounding boxes
fig = plt.figure(figsize=(10,10))
ax = fig.gca(projection='3d')
ax.set_aspect('equal')
ax.set_xlim([0,100])  
ax.set_ylim([0,100])
ax.set_zlim([0,100])

plot_vol_scatter(dat1,ax=ax,c='b',alpha=1.,s=20,marker='o')
plot_vol_scatter(dat2,ax=ax,c='r',alpha=1.,s=20,marker='o')

plot_cube_from_bb(dat1_bb,ax=ax,c='b')
plot_cube_from_bb(dat2_bb,ax=ax,c='r')

plt.tight_layout()


print df[volnum]


IS         10800
overlap        0
Name: 1, dtype: int64

In [41]:
# Get bounding box
volnum = 2
img2 = index_img(jhu_img,volnum)
dat2 = img2.get_data()
dat2_bb = get_bounding_box_inds(dat2)


# Plot with nilearn
display = plot_stat_map(img2,cmap= nl_cm.black_blue,alpha=0.5,colorbar=False)
display.add_overlay(img1,colorbar=False,alpha=0.5,cmap='hot')

# Plot bounding boxes
fig = plt.figure(figsize=(10,10))
ax = fig.gca(projection='3d')
ax.set_aspect('equal')
ax.set_xlim([0,100])  
ax.set_ylim([0,100])
ax.set_zlim([0,100])

plot_vol_scatter(dat1,ax=ax,c='b',alpha=1.,s=20,marker='o')
plot_vol_scatter(dat2,ax=ax,c='r',alpha=1.,s=20,marker='o')

plot_cube_from_bb(dat1_bb,ax=ax,c='b')
plot_cube_from_bb(dat2_bb,ax=ax,c='r')

plt.tight_layout()

print df[volnum]


IS         5304
overlap      10
Name: 2, dtype: int64

In [31]:
# Get bounding box
volnum = 3
img2 = index_img(jhu_img,volnum)
dat2 = img2.get_data()
dat2_bb = get_bounding_box_inds(dat2)


# Plot with nilearn
display = plot_stat_map(img2,cmap= nl_cm.black_blue,alpha=0.5,colorbar=False)
display.add_overlay(img1,colorbar=False,alpha=0.5,cmap='hot')

# Plot bounding boxes
fig = plt.figure(figsize=(10,10))
ax = fig.gca(projection='3d')
ax.set_aspect('equal')
ax.set_xlim([0,100])  
ax.set_ylim([0,100])
ax.set_zlim([0,100])

plot_vol_scatter(dat1,ax=ax,c='b',alpha=1.,s=20,marker='o')
plot_vol_scatter(dat2,ax=ax,c='r',alpha=1.,s=20,marker='o')

plot_cube_from_bb(dat1_bb,ax=ax,c='b')
plot_cube_from_bb(dat2_bb,ax=ax,c='r')

plt.tight_layout()



In [42]:
# Get bounding box
volnum = 4
img2 = index_img(jhu_img,volnum)
dat2 = img2.get_data()
dat2_bb = get_bounding_box_inds(dat2)


# Plot with nilearn
display = plot_stat_map(img2,cmap= nl_cm.black_blue,alpha=0.5,colorbar=False)
display.add_overlay(img1,colorbar=False,alpha=0.5,cmap='hot')

# Plot bounding boxes
fig = plt.figure(figsize=(10,10))
ax = fig.gca(projection='3d')
ax.set_aspect('equal')
ax.set_xlim([0,100])  
ax.set_ylim([0,100])
ax.set_zlim([0,100])

plot_vol_scatter(dat1,ax=ax,c='b',alpha=1.,s=20,marker='o')
plot_vol_scatter(dat2,ax=ax,c='r',alpha=1.,s=20,marker='o')

plot_cube_from_bb(dat1_bb,ax=ax,c='b')
plot_cube_from_bb(dat2_bb,ax=ax,c='r')

plt.tight_layout()


print df[volnum]


IS         10530
overlap        0
Name: 4, dtype: int64

In [50]:
# Get bounding box
volnum = 5
img2 = index_img(jhu_img,volnum)
dat2 = img2.get_data()
dat2_bb = get_bounding_box_inds(dat2)


# Plot with nilearn
display = plot_stat_map(img2,cmap= nl_cm.black_blue,alpha=0.5,colorbar=False)
display.add_overlay(img1,colorbar=False,alpha=0.5,cmap='hot',vmax=5.)

# Plot bounding boxes
fig = plt.figure(figsize=(10,10))
ax = fig.gca(projection='3d')
ax.set_aspect('equal')
ax.set_xlim([0,100])  
ax.set_ylim([0,100])
ax.set_zlim([0,100])

plot_vol_scatter(dat1,ax=ax,c='b',alpha=1.,s=20,marker='o')
plot_vol_scatter(dat2,ax=ax,c='r',alpha=1.,s=20,marker='o')

plot_cube_from_bb(dat1_bb,ax=ax,c='b')
plot_cube_from_bb(dat2_bb,ax=ax,c='r')

plt.tight_layout()

print df[volnum]


IS         0
overlap    0
Name: 5, dtype: int64

In [43]:
# Get bounding box
volnum = 6
img2 = index_img(jhu_img,volnum)
dat2 = img2.get_data()
dat2_bb = get_bounding_box_inds(dat2)


# Plot with nilearn
display = plot_stat_map(img2,cmap= nl_cm.black_blue,alpha=0.5,colorbar=False)
display.add_overlay(img1,colorbar=False,alpha=0.5,cmap='hot')

# Plot bounding boxes
fig = plt.figure(figsize=(10,10))
ax = fig.gca(projection='3d')
ax.set_aspect('equal')
ax.set_xlim([0,100])  
ax.set_ylim([0,100])
ax.set_zlim([0,100])

plot_vol_scatter(dat1,ax=ax,c='b',alpha=1.,s=20,marker='o')
plot_vol_scatter(dat2,ax=ax,c='r',alpha=1.,s=20,marker='o')

plot_cube_from_bb(dat1_bb,ax=ax,c='b')
plot_cube_from_bb(dat2_bb,ax=ax,c='r')

plt.tight_layout()


print df[volnum]


IS         8160
overlap       0
Name: 6, dtype: int64

In [47]:
# Get bounding box
volnum = 7
img2 = index_img(jhu_img,volnum)
dat2 = img2.get_data()
dat2_bb = get_bounding_box_inds(dat2)


# Plot with nilearn
display = plot_stat_map(img2,cmap= nl_cm.black_blue,alpha=0.5,colorbar=False)
display.add_overlay(img1,colorbar=False,alpha=0.5,cmap='hot')

# Plot bounding boxes
fig = plt.figure(figsize=(10,10))
ax = fig.gca(projection='3d')
ax.set_aspect('equal')
ax.set_xlim([0,100])  
ax.set_ylim([0,100])
ax.set_zlim([0,100])

plot_vol_scatter(dat1,ax=ax,c='b',alpha=1.,s=20,marker='o')
plot_vol_scatter(dat2,ax=ax,c='r',alpha=1.,s=20,marker='o')

plot_cube_from_bb(dat1_bb,ax=ax,c='b')
plot_cube_from_bb(dat2_bb,ax=ax,c='r')

plt.tight_layout()

print df[volnum]


IS         0
overlap    0
Name: 7, dtype: int64

In [44]:
# Get bounding box
volnum = 8
img2 = index_img(jhu_img,volnum)
dat2 = img2.get_data()
dat2_bb = get_bounding_box_inds(dat2)


# Plot with nilearn
display = plot_stat_map(img2,cmap= nl_cm.black_blue,alpha=0.5,colorbar=False)
display.add_overlay(img1,colorbar=False,alpha=0.5,cmap='hot')

# Plot bounding boxes
fig = plt.figure(figsize=(10,10))
ax = fig.gca(projection='3d')
ax.set_aspect('equal')
ax.set_xlim([0,100])  
ax.set_ylim([0,100])
ax.set_zlim([0,100])

plot_vol_scatter(dat1,ax=ax,c='b',alpha=1.,s=20,marker='o')
plot_vol_scatter(dat2,ax=ax,c='r',alpha=1.,s=20,marker='o')

plot_cube_from_bb(dat1_bb,ax=ax,c='b')
plot_cube_from_bb(dat2_bb,ax=ax,c='r')

plt.tight_layout()


print df[volnum]


IS         792
overlap      0
Name: 8, dtype: int64

In [46]:
# Get bounding box
volnum = 9
img2 = index_img(jhu_img,volnum)
dat2 = img2.get_data()
dat2_bb = get_bounding_box_inds(dat2)


# Plot with nilearn
display = plot_stat_map(img2,cmap= nl_cm.black_blue,alpha=0.5,colorbar=False)
display.add_overlay(img1,colorbar=False,alpha=0.5,cmap='hot')

# Plot bounding boxes
fig = plt.figure(figsize=(10,10))
ax = fig.gca(projection='3d')
ax.set_aspect('equal')
ax.set_xlim([0,100])  
ax.set_ylim([0,100])
ax.set_zlim([0,100])

plot_vol_scatter(dat1,ax=ax,c='b',alpha=1.,s=20,marker='o')
plot_vol_scatter(dat2,ax=ax,c='r',alpha=1.,s=20,marker='o')

plot_cube_from_bb(dat1_bb,ax=ax,c='b')
plot_cube_from_bb(dat2_bb,ax=ax,c='r')

plt.tight_layout()
print df[volnum]


IS         15504
overlap      202
Name: 9, dtype: int64

In [51]:
# Get bounding box
volnum = 10
img2 = index_img(jhu_img,volnum)
dat2 = img2.get_data()
dat2_bb = get_bounding_box_inds(dat2)


# Plot with nilearn
display = plot_stat_map(img2,cmap= nl_cm.black_blue,alpha=0.5,colorbar=False)
display.add_overlay(img1,colorbar=False,alpha=0.5,cmap='hot')

# Plot bounding boxes
fig = plt.figure(figsize=(10,10))
ax = fig.gca(projection='3d')
ax.set_aspect('equal')
ax.set_xlim([0,100])  
ax.set_ylim([0,100])
ax.set_zlim([0,100])

plot_vol_scatter(dat1,ax=ax,c='b',alpha=1.,s=20,marker='o')
plot_vol_scatter(dat2,ax=ax,c='r',alpha=1.,s=20,marker='o')

plot_cube_from_bb(dat1_bb,ax=ax,c='b')
plot_cube_from_bb(dat2_bb,ax=ax,c='r')

plt.tight_layout()


print df[volnum]


IS         18360
overlap      402
Name: 10, dtype: int64

In [54]:
# Get bounding box
volnum = 11
img2 = index_img(jhu_img,volnum)
dat2 = img2.get_data()
dat2_bb = get_bounding_box_inds(dat2)


# Plot with nilearn
display = plot_stat_map(img2,cmap= nl_cm.black_blue,alpha=0.5,colorbar=False)
display.add_overlay(img1,colorbar=False,alpha=0.5,cmap='hot')

# Plot bounding boxes
fig = plt.figure(figsize=(10,10))
ax = fig.gca(projection='3d')
ax.set_aspect('equal')
ax.set_xlim([0,100])  
ax.set_ylim([0,100])
ax.set_zlim([0,100])

plot_vol_scatter(dat1,ax=ax,c='b',alpha=1.,s=20,marker='o')
plot_vol_scatter(dat2,ax=ax,c='r',alpha=1.,s=20,marker='o')

plot_cube_from_bb(dat1_bb,ax=ax,c='b')
plot_cube_from_bb(dat2_bb,ax=ax,c='r')

plt.tight_layout()


print df[volnum]


IS         0
overlap    0
Name: 11, dtype: int64

In [55]:
# Get bounding box
volnum = 13
img2 = index_img(jhu_img,volnum)
dat2 = img2.get_data()
dat2_bb = get_bounding_box_inds(dat2)


# Plot with nilearn
display = plot_stat_map(img2,cmap= nl_cm.black_blue,alpha=0.5,colorbar=False)
display.add_overlay(img1,colorbar=False,alpha=0.5,cmap='hot')

# Plot bounding boxes
fig = plt.figure(figsize=(10,10))
ax = fig.gca(projection='3d')
ax.set_aspect('equal')
ax.set_xlim([0,100])  
ax.set_ylim([0,100])
ax.set_zlim([0,100])

plot_vol_scatter(dat1,ax=ax,c='b',alpha=1.,s=20,marker='o')
plot_vol_scatter(dat2,ax=ax,c='r',alpha=1.,s=20,marker='o')

plot_cube_from_bb(dat1_bb,ax=ax,c='b')
plot_cube_from_bb(dat2_bb,ax=ax,c='r')

plt.tight_layout()


print df[volnum]


IS         0
overlap    0
Name: 13, dtype: int64

In [56]:
# Get bounding box
volnum = 13
img2 = index_img(jhu_img,volnum)
dat2 = img2.get_data()
dat2_bb = get_bounding_box_inds(dat2)


# Plot with nilearn
display = plot_stat_map(img2,cmap= nl_cm.black_blue,alpha=0.5,colorbar=False)
display.add_overlay(img1,colorbar=False,alpha=0.5,cmap='hot')

# Plot bounding boxes
fig = plt.figure(figsize=(10,10))
ax = fig.gca(projection='3d')
ax.set_aspect('equal')
ax.set_xlim([0,100])  
ax.set_ylim([0,100])
ax.set_zlim([0,100])

plot_vol_scatter(dat1,ax=ax,c='b',alpha=1.,s=20,marker='o')
plot_vol_scatter(dat2,ax=ax,c='r',alpha=1.,s=20,marker='o')

plot_cube_from_bb(dat1_bb,ax=ax,c='b')
plot_cube_from_bb(dat2_bb,ax=ax,c='r')

plt.tight_layout()


print df[volnum]


IS         0
overlap    0
Name: 13, dtype: int64

In [57]:
# Get bounding box
volnum = 14
img2 = index_img(jhu_img,volnum)
dat2 = img2.get_data()
dat2_bb = get_bounding_box_inds(dat2)


# Plot with nilearn
display = plot_stat_map(img2,cmap= nl_cm.black_blue,alpha=0.5,colorbar=False)
display.add_overlay(img1,colorbar=False,alpha=0.5,cmap='hot')

# Plot bounding boxes
fig = plt.figure(figsize=(10,10))
ax = fig.gca(projection='3d')
ax.set_aspect('equal')
ax.set_xlim([0,100])  
ax.set_ylim([0,100])
ax.set_zlim([0,100])

plot_vol_scatter(dat1,ax=ax,c='b',alpha=1.,s=20,marker='o')
plot_vol_scatter(dat2,ax=ax,c='r',alpha=1.,s=20,marker='o')

plot_cube_from_bb(dat1_bb,ax=ax,c='b')
plot_cube_from_bb(dat2_bb,ax=ax,c='r')

plt.tight_layout()


print df[volnum]


IS         14688
overlap       42
Name: 14, dtype: int64

In [58]:
# Get bounding box
volnum = 15
img2 = index_img(jhu_img,volnum)
dat2 = img2.get_data()
dat2_bb = get_bounding_box_inds(dat2)


# Plot with nilearn
display = plot_stat_map(img2,cmap= nl_cm.black_blue,alpha=0.5,colorbar=False)
display.add_overlay(img1,colorbar=False,alpha=0.5,cmap='hot')

# Plot bounding boxes
fig = plt.figure(figsize=(10,10))
ax = fig.gca(projection='3d')
ax.set_aspect('equal')
ax.set_xlim([0,100])  
ax.set_ylim([0,100])
ax.set_zlim([0,100])

plot_vol_scatter(dat1,ax=ax,c='b',alpha=1.,s=20,marker='o')
plot_vol_scatter(dat2,ax=ax,c='r',alpha=1.,s=20,marker='o')

plot_cube_from_bb(dat1_bb,ax=ax,c='b')
plot_cube_from_bb(dat2_bb,ax=ax,c='r')

plt.tight_layout()


print df[volnum]


IS         0
overlap    0
Name: 15, dtype: int64

In [59]:
# Get bounding box
volnum = 16
img2 = index_img(jhu_img,volnum)
dat2 = img2.get_data()
dat2_bb = get_bounding_box_inds(dat2)


# Plot with nilearn
display = plot_stat_map(img2,cmap= nl_cm.black_blue,alpha=0.5,colorbar=False)
display.add_overlay(img1,colorbar=False,alpha=0.5,cmap='hot')

# Plot bounding boxes
fig = plt.figure(figsize=(10,10))
ax = fig.gca(projection='3d')
ax.set_aspect('equal')
ax.set_xlim([0,100])  
ax.set_ylim([0,100])
ax.set_zlim([0,100])

plot_vol_scatter(dat1,ax=ax,c='b',alpha=1.,s=20,marker='o')
plot_vol_scatter(dat2,ax=ax,c='r',alpha=1.,s=20,marker='o')

plot_cube_from_bb(dat1_bb,ax=ax,c='b')
plot_cube_from_bb(dat2_bb,ax=ax,c='r')

plt.tight_layout()


print df[volnum]


IS         17136
overlap      282
Name: 16, dtype: int64

In [60]:
# Get bounding box
volnum = 17
img2 = index_img(jhu_img,volnum)
dat2 = img2.get_data()
dat2_bb = get_bounding_box_inds(dat2)


# Plot with nilearn
display = plot_stat_map(img2,cmap= nl_cm.black_blue,alpha=0.5,colorbar=False)
display.add_overlay(img1,colorbar=False,alpha=0.5,cmap='hot')

# Plot bounding boxes
fig = plt.figure(figsize=(10,10))
ax = fig.gca(projection='3d')
ax.set_aspect('equal')
ax.set_xlim([0,100])  
ax.set_ylim([0,100])
ax.set_zlim([0,100])

plot_vol_scatter(dat1,ax=ax,c='b',alpha=1.,s=20,marker='o')
plot_vol_scatter(dat2,ax=ax,c='r',alpha=1.,s=20,marker='o')

plot_cube_from_bb(dat1_bb,ax=ax,c='b')
plot_cube_from_bb(dat2_bb,ax=ax,c='r')

plt.tight_layout()


print df[volnum]


IS         0
overlap    0
Name: 17, dtype: int64

In [61]:
# Get bounding box
volnum = 18
img2 = index_img(jhu_img,volnum)
dat2 = img2.get_data()
dat2_bb = get_bounding_box_inds(dat2)


# Plot with nilearn
display = plot_stat_map(img2,cmap= nl_cm.black_blue,alpha=0.5,colorbar=False)
display.add_overlay(img1,colorbar=False,alpha=0.5,cmap='hot')

# Plot bounding boxes
fig = plt.figure(figsize=(10,10))
ax = fig.gca(projection='3d')
ax.set_aspect('equal')
ax.set_xlim([0,100])  
ax.set_ylim([0,100])
ax.set_zlim([0,100])

plot_vol_scatter(dat1,ax=ax,c='b',alpha=1.,s=20,marker='o')
plot_vol_scatter(dat2,ax=ax,c='r',alpha=1.,s=20,marker='o')

plot_cube_from_bb(dat1_bb,ax=ax,c='b')
plot_cube_from_bb(dat2_bb,ax=ax,c='r')

plt.tight_layout()


print df[volnum]


IS         18360
overlap        1
Name: 18, dtype: int64

In [62]:
# Get bounding box
volnum = 19
img2 = index_img(jhu_img,volnum)
dat2 = img2.get_data()
dat2_bb = get_bounding_box_inds(dat2)


# Plot with nilearn
display = plot_stat_map(img2,cmap= nl_cm.black_blue,alpha=0.5,colorbar=False)
display.add_overlay(img1,colorbar=False,alpha=0.5,cmap='hot')

# Plot bounding boxes
fig = plt.figure(figsize=(10,10))
ax = fig.gca(projection='3d')
ax.set_aspect('equal')
ax.set_xlim([0,100])  
ax.set_ylim([0,100])
ax.set_zlim([0,100])

plot_vol_scatter(dat1,ax=ax,c='b',alpha=1.,s=20,marker='o')
plot_vol_scatter(dat2,ax=ax,c='r',alpha=1.,s=20,marker='o')

plot_cube_from_bb(dat1_bb,ax=ax,c='b')
plot_cube_from_bb(dat2_bb,ax=ax,c='r')

plt.tight_layout()


print df[volnum]


IS         0
overlap    0
Name: 19, dtype: int64