<p><div><div><div><div data-show-faces="false" data-height="21" data-width="100" data-layout="button_count" data-send="true" data-href="https://www.r-bloggers.com/how-to-highlight-3d-brain-regions/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="https://medium.com/@MattOldach_65321/how-to-highlight-3d-brain-regions-2e6c15a35574?source=rss-459e62b88a2a------2"> Stories by Matt.0 on Medium</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<p>Recently, I was reading Howard <em>et. al.,</em> (2018) “<strong>Genome-wide meta-analysis of depression in 807,553 individuals identifies 102 independent variants with replication in a further 1,507,153 individuals</strong>” and saw a really cool 3D visualization of highlighted brain regions associated with depression:</p>
<figure><img alt="" src="https://i1.wp.com/cdn-images-1.medium.com/max/879/1*X8-IvuHR-HeFQxt7LiW1PA.png?w=456&ssl=1" data-recalc-dims="1"><figcaption>Source: <a rel="nofollow" href="https://goo.gl/7rY5KV" target="_blank">https://goo.gl/7rY5KV</a></figcaption></figure>
<p>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 <a rel="nofollow" href="https://twitter.com/MattOldach/status/1051909841529315328" target="_blank">Twitterverse</a> to see if anyone knew of tools which could be used to create such a visualization.</p>
<p><a rel="nofollow" href="https://twitter.com/KarimH349" target="_blank">Helmet Karim</a> suggested that perhaps these images were created using BrainNet Viewer in MATLABso this was the first method I tried out.</p>
<p><em>Note</em>: 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.</p>
<h3>BrainNet Viewer</h3>
<figure><img alt="" src="https://i0.wp.com/cdn-images-1.medium.com/max/1000/1*XZR76fWm8jRJiD_N9eJGdw.jpeg?w=456&ssl=1" data-recalc-dims="1"></figure>
<p>First follow the install instructions for BrainNet Viewer <a rel="nofollow" href="https://www.nitrc.org/docman/view.php/504/1280/BrainNet" target="_blank">here</a> then start the graphical user interface (GUI) up from the terminal.</p>
<figure><img alt="" src="https://i2.wp.com/cdn-images-1.medium.com/max/1024/1*UvyKo-QodS6iTgv_s19T8g.png?w=456&ssl=1" data-recalc-dims="1"></figure>
<p>Next select load file and choose a surface template surface template and a mapping file (<em>i.e.</em> a brain atlas). The package provides samples so I chose BrainMesh_ICBMI52_smoothed.nv and the [<a rel="nofollow" href="http://neuro.imm.dtu.dk/wiki/Automated_Anatomical_Labeling" target="_blank">AAL90</a>](<a rel="nofollow" href="http://neuro.imm.dtu.dk/wiki/Automated_Anatomical_Labeling" target="_blank">http://neuro.imm.dtu.dk/wiki/Automated_Anatomical_Labeling</a>) brain atlas which has labeled volumes for 90 brain regions.</p>
<figure><img alt="" src="https://i1.wp.com/cdn-images-1.medium.com/max/1024/1*p1-bNjyTlhZLy9WyKhm5tA.png?w=456&ssl=1" data-recalc-dims="1"></figure>
<figure><img alt="" src="https://i2.wp.com/cdn-images-1.medium.com/max/1024/1*vg1pIqczG6oxBp0KgU-O_g.png?w=456&ssl=1" data-recalc-dims="1"></figure>
<figure><img alt="" src="https://i2.wp.com/cdn-images-1.medium.com/max/1024/1*28T7UZh9LkSBWtt4V_UNOw.png?w=456&ssl=1" data-recalc-dims="1"></figure>
<p>Next there’s a pop-up with 7-sections of which layout, surface and volume are of interest to us.</p>
<p>In layout select which view you would like, I’ve chosen full view which will show eight different viewpoints.</p>
<figure><img alt="" src="https://i2.wp.com/cdn-images-1.medium.com/max/1024/1*uP5BdGzmMBf7t_wgafJqTw.png?w=456&ssl=1" data-recalc-dims="1"></figure>
<p>In the surface tab you can select the transparency of the surface map — I’ve set it to <strong>0.75</strong>.</p>
<figure><img alt="" src="https://i0.wp.com/cdn-images-1.medium.com/max/1024/1*MyEktOl85KFT5bXsa5qDAw.png?w=456&ssl=1" data-recalc-dims="1"></figure>
<p>In the volume tab select ROI drawing, deselect draw all and in the custom box put <strong>37</strong> (the code for hippocampus_L). Then select <strong>Ok</strong>.</p>
<figure><img alt="" src="https://i1.wp.com/cdn-images-1.medium.com/max/1024/1*d8lsy9g3dT1ZBqNPBZPMYQ.png?w=456&ssl=1" data-recalc-dims="1"></figure>
<figure><img alt="" src="https://i2.wp.com/cdn-images-1.medium.com/max/1024/1*tBhk6wEj693xBN0KKTuMQw.png?w=456&ssl=1" data-recalc-dims="1"></figure>
<h3>Mango</h3>
<p>One of the members of Howard’s laboratory eventually got back to me saying that they used [<a rel="nofollow" href="http://ric.uthscsa.edu/mango/download.html" target="_blank">Mango</a>] 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 “<strong>RTFM</strong>”</p>
<figure><img alt="" src="https://i0.wp.com/cdn-images-1.medium.com/max/350/1*1tBCudZF2V12-BsXTQm4SQ.png?w=456&ssl=1" data-recalc-dims="1"><figcaption>Source: <a rel="nofollow" href="https://xkcd.com/293/" target="_blank">https://xkcd.com/293/</a></figcaption></figure>
<p>Mango has good <a rel="nofollow" href="http://ric.uthscsa.edu/mango/videos.html" target="_blank">video tutorials</a>, <a rel="nofollow" href="http://rii.uthscsa.edu/mango/userguide.html" target="_blank">user guide</a> and <a rel="nofollow" href="http://rii.uthscsa.edu/mango/forum/" target="_blank">forum</a> (<a rel="nofollow" href="http://rii.uthscsa.edu/mango/forum/" target="_blank">http://rii.uthscsa.edu/mango/forum/</a>) 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.</p>
<p>I decided to use the <a rel="nofollow" href="https://figshare.com/articles/Hammers_mith-n30r95_parietal_lobe_MRI_atlas_database/5024939" target="_blank">Hammers brain atlas</a> and the sample image provided with Mango</p>
<figure><img alt="" src="https://i0.wp.com/cdn-images-1.medium.com/max/1024/1*RRKOGI37hIS3NHrfnbCNEA.png?w=456&ssl=1" data-recalc-dims="1"></figure>
<p>Next select Add Overlay and choose the hippocampus_L.</p>
<figure><img alt="" src="https://i0.wp.com/cdn-images-1.medium.com/max/1024/1*bNXOHHgXGgvcildS8EhOJg.png?w=456&ssl=1" data-recalc-dims="1"></figure>
<figure><img alt="" src="https://i2.wp.com/cdn-images-1.medium.com/max/1024/1*PF4ycLtE5qxnDGRwe7aD-w.png?w=456&ssl=1" data-recalc-dims="1"></figure>
<p>Now select Image > Build Surface to create a 3D representation of the brain.</p>
<figure><img alt="" src="https://i2.wp.com/cdn-images-1.medium.com/max/1024/1*pjGJVJ0iGIqUfKjWWJuiGA.png?w=456&ssl=1" data-recalc-dims="1"></figure>
<p>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 <strong>0.75</strong>.</p>
<figure><img alt="" src="https://i1.wp.com/cdn-images-1.medium.com/max/1024/1*Vm2yBb0xkfTewc2LPjcQ6A.png?w=456&ssl=1" data-recalc-dims="1"></figure>
<figure><img alt="" src="https://i2.wp.com/cdn-images-1.medium.com/max/1024/1*WyWDETKfaT4NItcUslkAGg.png?w=456&ssl=1" data-recalc-dims="1"></figure>
<figure><img alt="" src="https://i2.wp.com/cdn-images-1.medium.com/max/1024/1*19CUugK1Iw6JixB3bCDh6g.png?w=456&ssl=1" data-recalc-dims="1"></figure>
<figure><img alt="" src="https://i1.wp.com/cdn-images-1.medium.com/max/1024/1*yXJINXCF1Qx-vC7msWJFoA.png?w=456&ssl=1" data-recalc-dims="1"></figure>
<p>Under the View tab deselect the Crosshairs.</p>
<figure><img alt="" src="https://i0.wp.com/cdn-images-1.medium.com/max/1024/1*8fs23uqjbryzrZBWb9elKA.png?w=456&ssl=1" data-recalc-dims="1"></figure>
<p>In the other panel select Analysis > Create Logical Overlays then in the surface panel select Shapes > Add Logical.</p>
<figure><img alt="" src="https://i2.wp.com/cdn-images-1.medium.com/max/1024/1*f0QqB_NamVkm3zEteDurZw.png?w=456&ssl=1" data-recalc-dims="1"></figure>
<figure><img alt="" src="https://i1.wp.com/cdn-images-1.medium.com/max/1024/1*4LmvIqv4B5_5pm-yXH18Ig.png?w=456&ssl=1" data-recalc-dims="1"></figure>
<p>Then under Surface > Views you can select any orientation you like then Surface > Create Snapshot to save as a .png.</p>
<figure><img alt="" src="https://i1.wp.com/cdn-images-1.medium.com/max/1024/1*YVm8LjXd0SdO5g5IrPEQDQ.png?w=456&ssl=1" data-recalc-dims="1"></figure>
<p>Here are three views of the hippocampus_L: <strong>anterior</strong>, <strong>left </strong>and <strong>superior</strong>:</p>
<figure><img alt="" src="https://i2.wp.com/cdn-images-1.medium.com/max/522/1*5LHvZKZVLmiT7sXgl3YGAg.png?w=456&ssl=1" data-recalc-dims="1"></figure>
<figure><img alt="" src="https://i1.wp.com/cdn-images-1.medium.com/max/522/1*tkhpUjZuhwbYY7C7l85S9Q.png?w=456&ssl=1" data-recalc-dims="1"></figure>
<figure><img alt="" src="https://i2.wp.com/cdn-images-1.medium.com/max/522/1*UzC-ngB8G7NoaOj5Bz8z0A.png?w=456&ssl=1" data-recalc-dims="1"></figure>
<h3>R Implementation</h3>
<p><a rel="nofollow" href="http://(https//www.google.com/url?sa=t&rct=j&q=&esrc=s&source=web&cd=1&cad=rja&uact=8&ved=2ahUKEwi4vIOS9K7eAhWnxFkKHR0OAh8QFjAAegQICRAB&url=http%3A%2F%2Fjohnmuschelli.com%2F&usg=AOvVaw3E8tutT1D7T-WIhUqDHGzM" target="_blank">John Muschelli</a><a rel="nofollow" href="https://www.google.com/url?sa=t&rct=j&q=&esrc=s&source=web&cd=1&cad=rja&uact=8&ved=2ahUKEwi4vIOS9K7eAhWnxFkKHR0OAh8QFjAAegQICRAB&url=http%3A%2F%2Fjohnmuschelli.com%2F&usg=AOvVaw3E8tutT1D7T-WIhUqDHGzM" target="_blank">,</a> an Assistant Scientist at Johns Hopkins Bloomberg School of Public Health who has authored numerous `R` packages (<em>e.g.</em> fslr) responded a couple weeks later to my tweet. He whipped up a gist to highlight a 3D brain image in R.</p>
<pre>library(rgl)<br>library(misc3d)<br>library(neurobase)<br>if (!requireNamespace(&quot;aal&quot;)) {<br>  devtools::install_github(&quot;muschellij2/aal&quot;)<br>} else {<br>  library(aal)<br>}<br>if (!requireNamespace(&quot;MNITemplate&quot;)) {<br>  devtools::install_github(&quot;jfortin1/MNITemplate&quot;)<br>} else {<br>  library(MNITemplate)<br>}</pre>
<pre>img = aal_image()<br>template = readMNI(res = &quot;2mm&quot;)<br>cut &lt;- 4500<br>dtemp &lt;- dim(template)</pre>
<pre># All of the sections you can label<br>labs = aal_get_labels()</pre>
<pre># Pick the region of the brain you would like to highlight - in this case the hippocamus_L<br>hippocampus = labs$index[grep(&quot;Hippocampus_L&quot;, labs$name)]</pre>
<pre>mask = remake_img(vec = img %in% hippocampus, img = img)</pre>
<pre>### this would be the ``activation'' or surface you want to render <br>contour3d(template, x=1:dtemp[1], y=1:dtemp[2], z=1:dtemp[3], level = cut, alpha = 0.1, draw = TRUE)<br>contour3d(mask, level = c(0.5), alpha = c(0.5), add = TRUE, color=c(&quot;red&quot;) )<br>### add text<br>text3d(x=dtemp[1]/2, y=dtemp[2]/2, z = dtemp[3]*0.98, text=&quot;Top&quot;)<br>text3d(x=-0.98, y=dtemp[2]/2, z = dtemp[3]/2, text=&quot;Right&quot;)<br>rglwidget()</pre>
<figure><img alt="" src="https://i1.wp.com/cdn-images-1.medium.com/max/672/1*O_A5iw2_diaJXXehO6-PWA.png?w=456&ssl=1" data-recalc-dims="1"></figure>
<p>John Muschelli also teaches a couple of short courses on imaging in R of which I’m currently taking his [<a rel="nofollow" href="https://www.coursera.org/learn/neurohacking" target="_blank">Neurohacking</a>] course. I really appreciate him taking the time to do this.</p>
<p>If your interested in learning more about medical imaging in R be sure to check out <a rel="nofollow" href="https://www.ncbi.nlm.nih.gov/pubmed/29325029" target="_blank">Neuroconductor</a></p>
<p>If you find this article useful feel free to share it with others or recommend this article! <img alt="😃" src="https://s.w.org/images/core/emoji/2.4/72x72/1f603.png" class="wp-smiley"></p>
<p>As always, if you have any questions or comments feel free to leave your feedback below or you can always reach me on <a rel="nofollow" href="https://www.linkedin.com/in/matthewoldach/" target="_blank">LinkedIn</a>. Till then, see you in the next post! <img alt="😄" src="https://s.w.org/images/core/emoji/2.4/72x72/1f604.png" class="wp-smiley"></p>
<p><img width="1" src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2e6c15a35574" height="1"></p>
	<p>
<div>
<div>To <strong>leave a comment</strong> for the author, please follow the link and comment on their blog: <strong><a href="https://medium.com/@MattOldach_65321/how-to-highlight-3d-brain-regions-2e6c15a35574?source=rss-459e62b88a2a------2"> Stories by Matt.0 on Medium</a></strong>.</div>
<hr>
<a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers.com</a> offers <strong><a rel="nofollow" href="https://feedburner.google.com/fb/a/mailverify?uri=RBloggers">daily e-mail updates</a></strong> about <a rel="nofollow" href="https://www.r-project.org/" title="The R Project for Statistical Computing">R</a> news and <a rel="nofollow" href="https://www.r-bloggers.com/search/tutorial" title="R tutorials">tutorials</a> on topics such as: <a rel="nofollow" href="https://www.r-bloggers.com/search/data%20science" title="Data science">Data science</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Big%20Data" title="Big Data">Big Data, <a rel="nofollow" href="https://www.r-users.com/" title="R jobs">R jobs</a>, visualization (<a rel="nofollow" href="https://www.r-bloggers.com/search/ggplot2" title="ggplot and ggplot2 tutorials">ggplot2</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/boxplot" title="Boxplots using lattice and ggplot2 tutorials">Boxplots</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/map" title="Maps and gis">maps</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/animation" title="Animation in R">animation</a>), programming (<a rel="nofollow" href="https://www.r-bloggers.com/search/RStudio" title="RStudio IDE for R">RStudio</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/sweave" title="Sweave and literate programming">Sweave</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/LaTeX" title="LaTeX in R">LaTeX</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/SQL" title="SQL and databases">SQL</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/eclipse" title="Eclipse IDE for R">Eclipse</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/git" title="git and github, Version Control System">git</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/hadoop" title="Large data in R using Hadoop">hadoop</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Web+Scraping" title="Web Scraping of google, facebook, yahoo, twitter and more using R">Web Scraping</a>) statistics (<a rel="nofollow" href="https://www.r-bloggers.com/search/regression" title="Regressions and ANOVA analysis tutorials">regression</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/PCA" title="principal component analysis tutorial">PCA</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/time+series" title="Time series">time series</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/trading" title="finance trading">trading</a>) and more...
<img width="1" alt="" src="http://feeds.feedburner.com/~r/RBloggers/~4/EPqRS0Lov_I" height="1"></a></div>