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
Minc2.draw_outline_with_labels
— Functiondraw_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 layoutanat
is a Volume3D with anatomical imageseg
is a Volume3D with discrete segemntationslabels
is a dictionary of labels to showcmap
is a color map to uselevels
is a list of levels ofanat
to use for contoursshow_colorbar
is a boolean flag to show colorbarnslices
is a number of slices to show
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
Minc2.draw_outline_with_heatmap
— Functiondraw_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 layoutanat
is a Volume3D with anatomical imageheat
is a Volume3D with overlay heatmapheat_limits
limits for the heatmapcmap
is a color map to uselevels
is a list of levels ofanat
to use for contoursshow_colorbar
is a boolean flag to show colorbarnslices
is a number of slices to show
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)
Minc2.draw_outline_with_heatmap_symmetric
— Functiondraw_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 layoutanat
is a Volume3D with anatomical imagemask
is a Volume3D with ROIheat
is a Volume3D with overlay heatmap, can be arbitrary samplingheat_limits
limits for the heatmapcmap_pos
is a color map to use for positive values, if nothing then don't show positive valuescmap_neg
is a color map to use for negative values, if nothing then don't show negative valueslevels
is a list of levels ofanat
to use for contoursshow_colorbar
is a boolean flag to show colorbarcolorbar_label
is a label for the colorbarnslices
is a number of slices to show