Visualize Clusters on Volume


In [1]:
%matplotlib inline

1. Upload all statistical maps into the data folder

The data folder can be found in the same folder as this notebook. Just drag and drop your NIfTI file into the data folder and press the upload button.

2. Specify relevant visualization parameters


In [2]:
# Voxel cluster extend
cluster_extend = 20

# Threshold for statistical map
threshold = 2.3

# Template to use for background
template = '../scripts/templates/MNI152_T1_1mm_brain.nii.gz'

# Creat CSV file with cluster information
create_CSV = True

# Show cross on cut position
show_cross = True

# Show image annotation (hemisphere laterality and coordination)
annotate_figure = True

# Show colorbar
show_colorbar = True

# Colorbar orientation
colorbar_orientation = 'horizontal'

# Show cluster information in title
show_title = False

# Image resolution
dpi = 300

# Image type
imageType = 'png'

# Add prefix to image name
prefix = 'cluster'

3. Run the visualization script


In [13]:
%run ../scripts/show_cluster_in_volume.py --help


usage: show_cluster_in_volume.py [-h] [-ce, --cluster_extent cluster_extent]
                                 [-t, --cluster_thr threshold] [--csv]
                                 [--cluster_title] [-c cmap] [-cb]
                                 [--black_bg] [--dpi dpi] [--format format]
                                 stats_file

Show the locations of clusters in a statistical map in MNI space.

positional arguments:
  stats_file            3D nifti file in MNI space containing the statistical values
                         you want to visualise.
                        Note that this file can be pre-thresholded or not.
                        If your file is already thresholded then you will need to
                         pass an argument to the -t option otherwise it will default to 2.3.
                         A suggested value is 0.01.

optional arguments:
  -h, --help            show this help message and exit
  -ce, --cluster_extent cluster_extent
                        Minimum cluster extent for a region to be included in the visualisation
                         (integer)
                         Default: 20
  -t, --cluster_thr threshold
                        Minimum statistical value for a region to be included in the visualisation
                         (float)
                         Default: 2.3
  --csv                 Create a csv file with cluster information.
                         Default: False
  --cluster_title       Show cluster information in the title of the plot.
                         Default: False
  -c cmap, --cmap cmap  Any matplotlib colormap listed at
                          http://matplotlib.org/examples/color/colormaps_reference.html
                         Default: RdBu_r
  -cb, --cbar           Display a colorbar on the right of the plots
                         Default: False
  --black_bg            Set the background to black.
                         Default: White
  --dpi dpi             DPI of output png file
                         Default: 300
  --format format       Format of the output image file.
                         Eg: png, pdf, tif, jpeg, svg. 
                         Default: png

Author: Kirstie Whitaker <kw401@cam.ac.uk>

In [ ]:
%run ../scripts/show_volume.py \
    $cluster_extend \
    $threshold \
    $template \
    $create_CSV \
    $show_cross \
    $annotate_figure \
    $show_colorbar \
    $colorbar_orientation \
    $show_title \
    $dpi \
    $imageType \
    $prefix

4. Look at your data


In [ ]:
from IPython.display import Image, display
outputs = sorted(gg('figures/*/*.%s' % imageType))
for o in outputs:
    a = Image(filename=o)
    display(a)