---
title: "How to Highlight 3D Brain Regions | Matthew Oldach"
url: "https://matthewoldach.com/writing/highlighting-3d-brain-regions/"
description: "Three approaches to highlighting brain regions with BrainNet Viewer, Mango and R, including the original screenshots and code."
---

1.  [Start](https://matthewoldach.com/)
2.  [Field Notes](https://matthewoldach.com/writing/)
3.  How to Highlight 3D Brain Regions

Visualisation · R · MATLAB

# How to Highlight 3D Brain Regions

[Matthew Oldach](https://matthewoldach.com/about/)2018-10-31

Three approaches to highlighting brain regions with BrainNet Viewer, Mango and R, including the original screenshots and code.

Recovered from the [original publication](https://medium.com/data-science/how-to-highlight-3d-brain-regions-2e6c15a35574). Historical tools and examples are preserved in context; this is not a claim that their integrations still run unchanged.

> Archive restoration: originally published on October 31, 2018. Recovered from Matthew’s Medium author feed with all 26 article images and original code. These are historical instructions; the software and package versions have not been revalidated. Figure credits and John Muschelli’s code contribution are preserved below.

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:

![Introduction: original article illustration 1](https://matthewoldach.com/_astro/brain-01.Dr-xbDE3_1gojRB.webp)

_Source: [https://goo.gl/7rY5KV](https://goo.gl/7rY5KV)_

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](https://twitter.com/MattOldach/status/1051909841529315328) to see if anyone knew of tools which could be used to create such a visualization.

[Helmet Karim](https://twitter.com/KarimH349) 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

![BrainNet Viewer: original article illustration 2](https://matthewoldach.com/_astro/brain-02.bH1J8Se9_Z2dGuTQ.webp)

First follow the install instructions for BrainNet Viewer [here](https://www.nitrc.org/docman/view.php/504/1280/BrainNet) then start the graphical user interface (GUI) up from the terminal.

![BrainNet Viewer: original article illustration 3](https://matthewoldach.com/_astro/brain-03.DKtfHs5n_1ThmPi.webp)

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)\]([http://neuro.imm.dtu.dk/wiki/Automated\_Anatomical\_Labeling](http://neuro.imm.dtu.dk/wiki/Automated_Anatomical_Labeling)) brain atlas which has labeled volumes for 90 brain regions.

![BrainNet Viewer: original article illustration 4](https://matthewoldach.com/_astro/brain-04.r1z-vdem_1uaMFw.webp)

![BrainNet Viewer: original article illustration 5](https://matthewoldach.com/_astro/brain-05.Xt5a6mmx_1z37tY.webp)

![BrainNet Viewer: original article illustration 6](https://matthewoldach.com/_astro/brain-06.B5s9YCe-_Z67Nk7.webp)

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.

![BrainNet Viewer: original article illustration 7](https://matthewoldach.com/_astro/brain-07.Bl5qCwyl_236NWu.webp)

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

![BrainNet Viewer: original article illustration 8](https://matthewoldach.com/_astro/brain-08.DrQ3OfuD_ZNJLyx.webp)

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**.

![BrainNet Viewer: original article illustration 9](https://matthewoldach.com/_astro/brain-09.DlFX7bXk_11jnaL.webp)

![BrainNet Viewer: original article illustration 10](https://matthewoldach.com/_astro/brain-10.CyV9v5AD_13lT3X.webp)

### Mango

I am currently in discussion with the Howard laboratory trying to get the exact methodology they used to create the image in their figure, but this how I believe they did it with \[[Mango](http://ric.uthscsa.edu/mango/download.html)\].

Mango has good [video tutorials](http://ric.uthscsa.edu/mango/videos.html), [user guide](http://rii.uthscsa.edu/mango/userguide.html) 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 download the [Hammers brain atlas](https://figshare.com/articles/Hammers_mith-n30r95_parietal_lobe_MRI_atlas_database/5024939) to use as the mask/overlay and the sample image provided with Mango

![Mango: original article illustration 11](https://matthewoldach.com/_astro/brain-11.DMdAyiPz_wvzL5.webp)

Next select Add Overlay and choose the hippocampus\_L.

![Mango: original article illustration 12](https://matthewoldach.com/_astro/brain-12.ClNoE1HC_ZumCxz.webp)

![Mango: original article illustration 13](https://matthewoldach.com/_astro/brain-13.B6TW-I7w_Z8m9Qm.webp)

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

![Mango: original article illustration 14](https://matthewoldach.com/_astro/brain-14.BaJWR-Bz_1lgiis.webp)

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**.

![Mango: original article illustration 15](https://matthewoldach.com/_astro/brain-15.lRv0Kp_0_4VM5u.webp)

![Mango: original article illustration 16](https://matthewoldach.com/_astro/brain-16.YKz20tW3_21fFPB.webp)

![Mango: original article illustration 17](https://matthewoldach.com/_astro/brain-17.BfmhCxNX_raV8w.webp)

![Mango: original article illustration 18](https://matthewoldach.com/_astro/brain-18.N2_iJTxZ_ucqA9.webp)

Under the View tab deselect the Crosshairs.

![Mango: original article illustration 19](https://matthewoldach.com/_astro/brain-19.MNngUMos_291wMk.webp)

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

![Mango: original article illustration 20](https://matthewoldach.com/_astro/brain-20.LxwaPAtd_wMMD.webp)

![Mango: original article illustration 21](https://matthewoldach.com/_astro/brain-21.DSO_Ua_E_8wJzc.webp)

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

![Mango: original article illustration 22](https://matthewoldach.com/_astro/brain-22.CVDst2mg_2bL1oD.webp)

Here are three views of the hippocampus\_L: **anterior**, **left** and **superior**:

![Mango: original article illustration 23](https://matthewoldach.com/_astro/brain-23.DfNIofbs_ZMfGvg.webp)

![Mango: original article illustration 24](https://matthewoldach.com/_astro/brain-24.D4BPWp08_1Prz9q.webp)

![Mango: original article illustration 25](https://matthewoldach.com/_astro/brain-25.Bs0TYNZr_IRYsm.webp)

### R Implementation

[John Muschelli](http://johnmuschelli.com/), 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()
template = readMNI(res = "2mm")
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") )
### add text
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()
```

![R Implementation: original article illustration 26](https://matthewoldach.com/_astro/brain-26.D8anGx1v_1XzJGx.webp)

John Muschelli also teaches a couple of short courses on imaging in R and I’m currently taking his \[[Neurohacking](https://www.coursera.org/learn/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](https://www.ncbi.nlm.nih.gov/pubmed/29325029)

If you find this article useful feel free to share it with others or recommend this article! 😃

As always, if you have any questions or comments feel free to leave your feedback below or you can always reach me on [LinkedIn](https://www.linkedin.com/in/matthewoldach/). Till then, see you in the next post! 😄

* * *

[← Back to Field Notes](https://matthewoldach.com/writing/)
