Load the required data from a file; for the moment, this contains two 3D volumes; anatVol and stats containing the anatomy to use in the background and the output of some statistical computations. (Note for RMINC users: in these examples anatVol and stats would be the output of mincArray)
load("sliceData.RData")
The best way to use MRIcrotome is through pipes; let's load the full tidyverse for now (though only pipes are actively used). Also, the graphics subsystem is grid graphics, so let's go ahead and load that as well.
library(tidyverse) library(grid) library(MRIcrotome)
That's it for the set-up. On to actual package usage.
Starting off with the simplest figure; a coronal slice through the brain.
sliceSeries(nrow = 1, slices=200) %>% anatomy(anatVol, low=700, high=1400) %>% draw()
That's the basic anatomy of displaying MRI anatomy. It always begins with a call to sliceSeries, following by a call to anatomy, and finally the command to draw the results.
Let's prettify it, and overlay the stats.
sliceSeries(nrow = 1, slices=200) %>% anatomy(anatVol, low=700, high=1400) %>% overlay(stats, low=2, high=6, symmetric = T) %>% draw()
So far, so good. A legend would be nice, though.
sliceSeries(nrow = 1, begin=200, end=300) %>% anatomy(anatVol, low=700, high=1400) %>% overlay(stats, low=2, high=6, symmetric = T) %>% legend("t-statistics") %>% draw()
The command is called sliceSeries for a reason ...
sliceSeries(nrow = 5, ncol=5, begin=100, end=350) %>% anatomy(anatVol, low=700, high=1400) %>% overlay(stats, low=2, high=6, symmetric = T) %>% legend("t-statistics") %>% draw()
You can also have more than one slice series:
sliceSeries(nrow = 8, begin=100, end=350) %>% anatomy(anatVol, low=700, high=1400) %>% sliceSeries() %>% # if no arguments are specified, reuse previous sliceSeries args anatomy() %>% # if no arguments are specified, reuse previous anatomy call overlay(stats, low=2, high=6, symmetric = T) %>% legend("t-statistics") %>% draw()
And with some titles:
sliceSeries(nrow = 8, begin=100, end=350) %>% anatomy(anatVol, low=700, high=1400) %>% addtitle("Anatomy") %>% sliceSeries() %>% anatomy() %>% overlay(stats, low=2, high=6, symmetric = T) %>% addtitle("Stats") %>% legend("t-statistics") %>% draw()
And change the layout orientation
sliceSeries(ncol = 8, begin=100, end=350) %>% anatomy(anatVol, low=700, high=1400) %>% addtitle("Anatomy") %>% sliceSeries() %>% anatomy() %>% overlay(stats, low=2, high=6, symmetric = T) %>% addtitle("Stats") %>% legend("t-statistics") %>% draw(layout = "row")
Multiple legends
sliceSeries(ncol = 8, begin=100, end=350) %>% anatomy(anatVol, low=700, high=1400) %>% addtitle("Anatomy") %>% legend() %>% sliceSeries() %>% anatomy() %>% overlay(stats, low=2, high=6, symmetric = T) %>% addtitle("Stats") %>% legend("t-statistics") %>% draw(layout = "row")
Let's do multiple legends on the same slice series, going with a column layout
TODO: cannot use no-args version of anatomy() if asking for a legend
sliceSeries(nrow = 8, begin=100, end=350) %>% anatomy(anatVol, low=700, high=1400) %>% addtitle("Anatomy") %>% sliceSeries() %>% anatomy(anatVol, low=700, high=1400) %>% legend() %>% overlay(stats, low=2, high=6, symmetric = T) %>% addtitle("Stats") %>% legend("t-statistics") %>% draw()
It can also do contours
sliceSeries(nrow = 1, begin=200, end=300) %>% anatomy(anatVol, low=700, high=1400) %>% contours(anatVol, levels=c(1000, 1400), col="blue") %>% draw()
Of course contours can be mixed with sliceSeries as you please
sliceSeries(nrow = 1, begin=200, end=300) %>% anatomy(anatVol, low=700, high=1400) %>% sliceSeries() %>% anatomy() %>% contours(anatVol, levels=c(1000, 1400), col="blue") %>% sliceSeries() %>% contours(anatVol, levels=c(1000, 1400), col="blue") %>% draw()
Contours can be given different colours, linetypes, and widths
sliceSeries(nrow = 1, begin=200, end=300) %>% contours(anatVol, levels=c(1000, 1400), col=c("blue", "red"), lwd=1:2, lty=c(1,3)) %>% draw()
The most likely use is combined with stats - let's highlight the most significant:
sliceSeries(nrow = 1, begin=200, end=300) %>% anatomy(anatVol, low=700, high=1400) %>% overlay(stats, low=2, high=6, symmetric = T) %>% legend("t-statistics") %>% contours(abs(stats), levels=c(3,5), lwd=2, lty=c(3,1), col="green") %>% draw()
Contours can of course have legends, too.
sliceSeries(nrow = 1, begin=200, end=300) %>% anatomy(anatVol, low=700, high=1400) %>% overlay(stats, low=2, high=6, symmetric = T) %>% legend("t-statistics") %>% contours(abs(stats), levels=c(3,5), lwd=2, lty=c(3,1), col="green") %>% legend("Most sig.") %>% draw()
And contours can take on any colour scale
sliceSeries(nrow = 1, begin=200, end=300) %>% anatomy(anatVol, low=700, high=1400) %>% contours(abs(stats), levels=2:6, col=topo.colors(255), lty=3) %>% legend("t statistics") %>% draw()
And of course works in slice series with multiple slices too
sliceSeries(nrow=5, ncol=6, begin=70, end=400) %>% contours(anatVol, levels=c(1000, 1200, 1500), col=gray.colors(255)) %>% draw()
Opacity can be controlled with the alpha parameter to anatomy and overlay:
sliceSeries(nrow=5, begin=150, end=250) %>% anatomy(anatVol, low=700, high=1400) %>% overlay(stats, 2, 6, symmetric = T, alpha=0.1) %>% addtitle("alpha=0.1") %>% sliceSeries() %>% anatomy() %>% overlay(stats, 2, 6, symmetric = T, alpha=0.5) %>% addtitle("alpha=0.5") %>% sliceSeries() %>% anatomy() %>% overlay(stats, 2, 6, symmetric = T, alpha=0.9) %>% addtitle("alpha=0.9") %>% draw()
And you can add indicators of your slice selection
sliceSeries(nrow=5, begin=150, end=250) %>% anatomy(anatVol, low=700, high=1400) %>% overlay(stats, 2, 6, symmetric = T, alpha=0.1) %>% addtitle("alpha=0.1") %>% sliceSeries() %>% anatomy() %>% overlay(stats, 2, 6, symmetric = T, alpha=0.5) %>% addtitle("alpha=0.5") %>% sliceSeries() %>% anatomy() %>% overlay(stats, 2, 6, symmetric = T, alpha=0.9) %>% addtitle("alpha=0.9") %>% legend("t-statistics") %>% contourSliceIndicator(anatVol, c(700, 1400)) %>% draw()
If you'd rather display a slice underneath the slice indicators, you can do that too
sliceSeries(nrow=5, begin=150, end=250) %>% anatomy(anatVol, low=700, high=1400) %>% overlay(stats, 2, 6, symmetric = T, alpha=0.1) %>% addtitle("alpha=0.1") %>% sliceSeries() %>% anatomy() %>% overlay(stats, 2, 6, symmetric = T, alpha=0.5) %>% addtitle("alpha=0.5") %>% sliceSeries() %>% anatomy() %>% overlay(stats, 2, 6, symmetric = T, alpha=0.9) %>% addtitle("alpha=0.9") %>% legend("t-statistics") %>% anatomySliceIndicator(anatVol, 700, 1400) %>% draw()
Let's see some possible permutations of slice dimensions and sliceIndicator dimensions
sliceSeries(nrow=5, begin=150, end=250) %>% anatomy(anatVol, low=700, high=1400) %>% legend("t-statistics") %>% contourSliceIndicator(anatVol,c(700, 1400)) %>% draw() sliceSeries(nrow=5, begin=150, end=250, dimension = 1) %>% anatomy(anatVol, low=700, high=1400) %>% legend("t-statistics") %>% contourSliceIndicator(anatVol, c(700, 1400)) %>% draw() sliceSeries(nrow=5, begin=50, end=150, dimension = 3) %>% anatomy(anatVol, low=700, high=1400) %>% legend("t-statistics") %>% contourSliceIndicator(anatVol, c(700, 1400)) %>% draw() sliceSeries(nrow=5, begin=50, end=150, dimension = 3) %>% anatomy(anatVol, low=700, high=1400) %>% legend("t-statistics") %>% contourSliceIndicator(anatVol, c(700, 1400), dimension = 2) %>% draw()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.