High level functions for plotting 3D volumes

These are helper functions for plotting Volume3D objects using Makie. To make them available one must first load Makie or equivalent (i.e CairoMakie)

Show MNI-ICBM152 template contours with tissue masks overlays

using CairoMakie
using Minc2

# read T1w scan
icbm=Minc2.read_volume("mni_icbm152_t1_tal_nlin_sym_09c.mnc", store=Float64)
# read label mask, represent it as array of bytes 
lab=Minc2.read_volume("mni_icbm152_cls_tal_nlin_sym_09c.mnc", store=UInt8)


fig = Figure()
gc = fig[1, 1] = GridLayout()

Minc2.draw_outline_with_labels(gc, icbm, lab, 
    labels=Dict([1=>"CSF",2=>"GM",3=>"WM"]),
    nslices = 5)

resize_to_layout!(fig)

save("mni_icbm152_segmentation.png", fig, px_per_unit = 1)

Will produce MNI-ICBM152 Segmentation

Minc2.draw_outline_with_labelsFunction
draw_outline_with_labels(
    layout, 
    anat, 
    seg; 
    labels, 
    cmap = :rainbow,
    levels = [20,30],
    show_colorbar = true,
    nslices = 4)

Draws a segmentation seg on top of anat in a grid layout layout

  • layout is a grid layout
  • anat is a Volume3D with anatomical image
  • seg is a Volume3D with discrete segemntations
  • labels is a dictionary of labels to show
  • cmap is a color map to use
  • levels is a list of levels of anat to use for contours
  • show_colorbar is a boolean flag to show colorbar
  • nslices is a number of slices to show
source

Show MNI-ICBM152 template contours with GM proability map

using CairoMakie
using Minc2

# read T1w scan
anat=Minc2.read_volume("mni_icbm152_t1_tal_nlin_sym_09c.mnc",store=Float64)
# read field
gm=Minc2.read_volume("mni_icbm152_gm_tal_nlin_sym_09c.mnc",store=Float64)

fig = Figure()
gc = fig[1, 1] = GridLayout()

# set background to transparent
Minc2.array(gm)[Minc2.array(gm) .< 1e-6] .= NaN

Minc2.draw_outline_with_heatmap(gc, anat, gm, 
    heat_limits=(0.0,1.0),cmap=:turbo,
    nslices = 5)

resize_to_layout!(fig)

save("mni_icbm152_gm.png", fig, px_per_unit = 1) 

Will produce MNI-ICBM152 GM

Minc2.draw_outline_with_heatmapFunction
draw_outline_with_heatmap(
    layout, anat, heat; 
    cmap=:rainbow, levels=[20, 40],
    heat_limits=nothing, 
    show_colorbar=true,
    nslices=4)

Draws a heatmap of heat on top of anat in a grid layout layout.

  • layout is a grid layout
  • anat is a Volume3D with anatomical image
  • heat is a Volume3D with overlay heatmap
  • heat_limits limits for the heatmap
  • cmap is a color map to use
  • levels is a list of levels of anat to use for contours
  • show_colorbar is a boolean flag to show colorbar
  • nslices is a number of slices to show
source

Show two-tailed t-statistics on DBM style analysis

using CairoMakie
using Minc2

# read T1w scan and crop black area around ROI
anat=Minc2.crop_volume(
    Minc2.read_volume("mni_icbm152_t1_tal_nlin_sym_09c.mnc",store=Float64),
    [[15,15],[20,20],[20,20]])

# Read brain ROI, should be the same sampling as anat
mask=Minc2.crop_volume(
    Minc2.read_volume("mni_icbm152_t1_tal_nlin_sym_09c_mask.mnc",store=UInt8),
    [[15,15],[20,20],[20,20]])

# read statistics map, does not have to be the same resolution as anat
vol_t=Minc2.read_volume("t_AD_vs_CN_2mm.mnc",store=Float64)

# statistical limits (two-tailed)
stat_limits  = [2.9 , 5]

# start new figure
fig = Figure()

g1  = f[1,1] = GridLayout()
Label(f[1,1,Top()],"AD vs CN-")

draw_outline_with_heatmap_symmetric(g1, anat, mask, vol_stat;
    heat_limits=stat_limits,
    show_colorbar=true,
    cmap_pos=:YlOrRd_9,cmap_neg=:YlGnBu_9,
    nslices=5,
    colorbar_label="t-statistics")

resize_to_layout!(fig)

save("t-statistics.png", fig, px_per_unit = 1) 

T-statistics

Minc2.draw_outline_with_heatmap_symmetricFunction
draw_outline_with_heatmap_symmetric(
    layout, anat, mask, heat; 
    cmap_pos=:YlOrRd_9,
    cmap_neg=:YlGnBu_9,
    levels=[20, 40],
    heat_limits=nothing,
    show_colorbar=true,
    under=nothing, 
    over=nothing,
    nslices=4,
    alpha=0.7,
    colorbar_label="",
    slices_gap=5,
    colorbar_gap=10)

Draws a two-sided (symmetric positive and negative) heatmap of heat on top of anat in a grid layout layout.

  • layout is a grid layout
  • anat is a Volume3D with anatomical image
  • mask is a Volume3D with ROI
  • heat is a Volume3D with overlay heatmap, can be arbitrary sampling
  • heat_limits limits for the heatmap
  • cmap_pos is a color map to use for positive values, if nothing then don't show positive values
  • cmap_neg is a color map to use for negative values, if nothing then don't show negative values
  • levels is a list of levels of anat to use for contours
  • show_colorbar is a boolean flag to show colorbar
  • colorbar_label is a label for the colorbar
  • nslices is a number of slices to show
source