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
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]:
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]:
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]:
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]:
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]:
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]:
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]
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]
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]
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]
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]
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]
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]
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]
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]
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]
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]
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]
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]
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]
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]
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]
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]
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]
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]