Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Recently, I was reading Howard et. al., (2018) “Genome-wide meta-analysis of depression in 807,553 individuals identifies 102 independent variants with replication in a further 1,507,153 individuals” and saw a really cool 3D visualization of highlighted brain regions associated with depression:

After an exhaustive search I couldn’t find any reference to how this was done in the methods or supplementary information so I reached out to the authors. While I was awaiting a response, I also reached out to the Twitterverse to see if anyone knew of tools which could be used to create such a visualization.

Helmet Karim suggested that perhaps these images were created using BrainNet Viewer in MATLABso this was the first method I tried out.

Note: All of the methods covered in this article use what is called a brain Atlas overlayed as a maskon a normalized T1 MRI image. I’ve chosen to highlight the left hippocampus across these methods so that they are comparable.

### BrainNet Viewer

First follow the install instructions for BrainNet Viewer here then start the graphical user interface (GUI) up from the terminal.

Next select load file and choose a surface template surface template and a mapping file (i.e. a brain atlas). The package provides samples so I chose BrainMesh_ICBMI52_smoothed.nv and the [AAL90](http://neuro.imm.dtu.dk/wiki/Automated_Anatomical_Labeling) brain atlas which has labeled volumes for 90 brain regions.

Next there’s a pop-up with 7-sections of which layout, surface and volume are of interest to us.

In layout select which view you would like, I’ve chosen full view which will show eight different viewpoints.

In the surface tab you can select the transparency of the surface map — I’ve set it to 0.75.

In the volume tab select ROI drawing, deselect draw all and in the custom box put 37 (the code for hippocampus_L). Then select Ok.

### Mango

One of the members of Howard’s laboratory eventually got back to me saying that they used [Mango] to create the brain images and manually tinted the colors onto the brain masks to indicate beta/p values. I tried to get a detailed protocol from them but their response was essentially “RTFM

Mango has good video tutorials, user guide and forum (http://rii.uthscsa.edu/mango/forum/) but for those of us whose sole interest is creating a highlighted 3D brain image it’s a lot of material to go through. Therefore, I decided to create a detailed protocol of this process to save others time.

I decided to use the Hammers brain atlas and the sample image provided with Mango

Next select Add Overlay and choose the hippocampus_L.

Now select Image > Build Surface to create a 3D representation of the brain.

In this new pop-up GUI there’s a few things we want to do. First, change the background to white so this can be published in a manuscript. Second, change the transparency of this image to 0.75.

Under the View tab deselect the Crosshairs.

In the other panel select Analysis > Create Logical Overlays then in the surface panel select Shapes > Add Logical.

Then under Surface > Views you can select any orientation you like then Surface > Create Snapshot to save as a .png.

Here are three views of the hippocampus_L: anterior, left and superior:

### R Implementation

John Muschelli, an Assistant Scientist at Johns Hopkins Bloomberg School of Public Health who has authored numerous R packages (e.g. fslr) responded a couple weeks later to my tweet. He whipped up a gist to highlight a 3D brain image in R.

library(rgl)
library(misc3d)
library(neurobase)
if (!requireNamespace("aal")) {
devtools::install_github("muschellij2/aal")
} else {
library(aal)
}
if (!requireNamespace("MNITemplate")) {
devtools::install_github("jfortin1/MNITemplate")
} else {
library(MNITemplate)
}
img = aal_image()
cut <- 4500
dtemp <- dim(template)
# All of the sections you can label
labs = aal_get_labels()
# Pick the region of the brain you would like to highlight - in this case the hippocamus_L
hippocampus = labs$index[grep("Hippocampus_L", labs$name)]
mask = remake_img(vec = img %in% hippocampus, img = img)
### this would be the activation'' or surface you want to render
contour3d(template, x=1:dtemp[1], y=1:dtemp[2], z=1:dtemp[3], level = cut, alpha = 0.1, draw = TRUE)
contour3d(mask, level = c(0.5), alpha = c(0.5), add = TRUE, color=c("red") )
text3d(x=dtemp[1]/2, y=dtemp[2]/2, z = dtemp[3]*0.98, text="Top")
text3d(x=-0.98, y=dtemp[2]/2, z = dtemp[3]/2, text="Right")
rglwidget()

John Muschelli also teaches a couple of short courses on imaging in R of which I’m currently taking his [Neurohacking] course. I really appreciate him taking the time to do this.

If your interested in learning more about medical imaging in R be sure to check out Neuroconductor