In [7]:
import nibabel #Library for reading NIFTI images
import os
%matplotlib inline

In [16]:
sample_mask = '../data/DJ_RECURATED/TCGA-02-0003/TCGA-02-0003_1997-06-08_PREOP/AXIAL-T1-POST-GD_TCGA-02-0003_TCGA-02-0003_PREOP_SCAN13-MASK.nii.gz'
sample_bg = '../data/DJ_RECURATED/TCGA-02-0003/TCGA-02-0003_1997-06-08_PREOP/BACKGROUND_IMAGES/AXIAL-T1-POST-GD_TCGA-02-0003_TCGA-02-0003_PREOP_SCAN13.nii.gz'

mask_mtx = nibabel.load(sample_mask).get_data()
bg_mtx = nibabel.load(sample_bg).get_data()

In [17]:
print mask_mtx.shape
print bg_mtx.shape  ## The image is 256x256 in place with 25 z slicses


(256, 256, 25)
(256, 256, 25)

In [25]:
## LETS ACTUALLY GRAPH A SINGLE Z PLANE IN THE MIDDLE OF THE IMAGE SPACE--- so Z=13
slice_to_view = 13

nz = bg_mtx.shape
fig,ax = plt.subplots()
ax.set_title('Axial Slice {:03d}'.format(slice_to_view))
ax.imshow(bg_mtx[:,:, slice_to_view])

fig.show()

ax.set_title('Axial Slice {:03d}'.format(slice_to_view))
ax.imshow(mask_mtx[:,:, slice_to_view])

#   "\n",
#      "data = nib.load(brain).get_data()\n",
#      "nz = data.shape[2]\n",
#      "def axial_viewer(slice):\n",
#      "    fig, ax = plt.subplots()\n",
#      "    ax.set_title('Axial Slice {:03d}'.format(slice))\n",
#      "    ax.imshow(data[:, :, slice])\n",
#      "    axes = ax.get_axes()\n",
#      "    axes.get_xaxis().set_ticks([])\n",
#      "    axes.get_yaxis().set_ticks([])\n",
#      "    return fig"


Out[25]:
<matplotlib.image.AxesImage at 0x2ed5ed0>

In [8]:
import matplotlib as mpl
mpl.rc('figure', figsize=(4,3)) # size
plt = mpl.pyplot
plt.gray() # MR images have no concept of color


<matplotlib.figure.Figure at 0x25b5b10>