# New extension: HDBrainExtraction for AI-based skull stripping

**URL:** https://discourse.slicer.org/t/new-extension-hdbrainextraction-for-ai-based-skull-stripping/24420
**Category:** Support
**Tags:** feature, segmentation, brain, ai
**Created:** [July 20, 2022, 8:50pm UTC](https://discourse.slicer.org/t/new-extension-hdbrainextraction-for-ai-based-skull-stripping/24420 "2022-07-20T20:50:41Z")
**Posts on this page:** 16
**Page:** 1

<div class="post-metadata">

### Author: ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)
#### Post date: [July 20, 2022, 8:50pm UTC](https://discourse.slicer.org/t/new-extension-hdbrainextraction-for-ai-based-skull-stripping/24420/1 "2022-07-20T20:50:41Z")

</div>

A new AI-based tool - [HDBrainExtracion extension](https://github.com/lassoan/SlicerHDBrainExtraction#hdbrainextraction) - is added to 3D Slicer for skull stripping (blanking out region outside the brain in MRI images). The model is trained on a large set of images and proven to be more robust than many other similar tools.

![](https://github.com/lassoan/SlicerHDBrainExtraction/raw/main/Screenshot01.jpg)

The extension is built by packaging the [HD-BET model provided by DKFZ (Heidelberg, Germany)](https://github.com/MIC-DKFZ/HD-BET). This extension can serve as a good example for others who intend to distribute their AI models via 3D Slicer.

---

<div class="post-metadata">

### Author: ![rbumm](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/rbumm/32/9404_2.png) [@rbumm](https://discourse.slicer.org/u/rbumm)
#### Post date: [July 21, 2022, 7:09am UTC](https://discourse.slicer.org/t/new-extension-hdbrainextraction-for-ai-based-skull-stripping/24420/2 "2022-07-21T07:09:51Z")

</div>

This is a very instructive and well-written extension, thank you @lassoan. Do you have any information on how HD-BET trained their skull stripping model in detail? The cited paper remains a bit unclear here. It would be interesting to have similar tissue stripping AI-based modules for other organs.

---

<div class="post-metadata">

### Author: ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)
#### Post date: [July 21, 2022, 7:48am UTC](https://discourse.slicer.org/t/new-extension-hdbrainextraction-for-ai-based-skull-stripping/24420/3 "2022-07-21T07:48:53Z")

</div>

I don’t have any more information other than what they described in their paper. You may contact the authors at the email provided in the paper or by submitting an issue in [their GitHub repository](https://github.com/MIC-DKFZ/HD-BET/) for more details.

---

<div class="post-metadata">

### Author: ![rbumm](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/rbumm/32/9404_2.png) [@rbumm](https://discourse.slicer.org/u/rbumm)
#### Post date: [July 21, 2022, 1:02pm UTC](https://discourse.slicer.org/t/new-extension-hdbrainextraction-for-ai-based-skull-stripping/24420/4 "2022-07-21T13:02:27Z")

</div>

Short feedback: Works great on a Windows 11 GTX 1060 laptop, but I needed to start Slicer in Admin mode to install the PyTorch extension upon the first run. Processing took about 5 min to complete (Device=auto), so it is probably not using the GPU yet.

 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/8/2/8201fa619796b74817ed93e90f265ee6ba2eb97c.png)

---

<div class="post-metadata">

### Author: ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)
#### Post date: [July 22, 2022, 6:11am UTC](https://discourse.slicer.org/t/new-extension-hdbrainextraction-for-ai-based-skull-stripping/24420/5 "2022-07-22T06:11:52Z")

</div>

Thanks for the feedback. What indicated that installing as admin user was necessary?

I’ve noticed that failed Pytorch installs may prevent proper installation. You may consider trying to reinstall Slicer from scratch (deleting the Slicer install folder completely) to see if it makes Slicer’s pytorch find the GPU.

Also make sure that in your NVIDIA settings Slicer is configured to use the GPU.

---

<div class="post-metadata">

### Author: ![rbumm](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/rbumm/32/9404_2.png) [@rbumm](https://discourse.slicer.org/u/rbumm)
#### Post date: [July 22, 2022, 6:29am UTC](https://discourse.slicer.org/t/new-extension-hdbrainextraction-for-ai-based-skull-stripping/24420/6 "2022-07-22T06:29:39Z")

</div>

I install HDBrainExtraction, it asks to install PyTorch too, I agree, then I restart and run the extension the first time and get:

 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/e/9/e9d9e2d89e5ccfb3f1ee07229935a76307d13052.jpeg)

---

<div class="post-metadata">

### Author: ![rbumm](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/rbumm/32/9404_2.png) [@rbumm](https://discourse.slicer.org/u/rbumm)
#### Post date: [July 22, 2022, 6:42am UTC](https://discourse.slicer.org/t/new-extension-hdbrainextraction-for-ai-based-skull-stripping/24420/7 "2022-07-22T06:42:16Z")

</div>

This exception was solved by applying this commit

> <https://github.com/fepegar/SlicerPyTorch/commit/b1f33d6527509a607576e544cf225a67bcabe437>
>
> The used functionality is removed in newer versions: https://github.com/pmeier/l…ight-the-torch/issues/41#issuecomment-1155279506

to the PyTorch utility module. Then the install runs normally, but unfortunately, it does not detect CUDA yet on my two systems. Using Slicer in Admin mode was mandatory, otherwise, the PyTorch Util was throwing exceptions.

---

<div class="post-metadata">

### Author: ![rbumm](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/rbumm/32/9404_2.png) [@rbumm](https://discourse.slicer.org/u/rbumm)
#### Post date: [July 22, 2022, 7:06am UTC](https://discourse.slicer.org/t/new-extension-hdbrainextraction-for-ai-based-skull-stripping/24420/8 "2022-07-22T07:06:29Z")

</div>

Very good performance on my desktop (RTX 3070 Ti): 20 s rendering time

 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/7/6/7698eee6d77201617e9166263b8787a519e3dee6.jpeg)

CUDA seems to be available on that system.

![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/3/1/3185f88f7067ae863b473132695a481bd3accce1.png)

---

<div class="post-metadata">

### Author: ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)
#### Post date: [July 22, 2022, 7:38am UTC](https://discourse.slicer.org/t/new-extension-hdbrainextraction-for-ai-based-skull-stripping/24420/9 "2022-07-22T07:38:47Z")

</div>

Thanks for the additional information.

If you encounter any issues then always try to update the extensions in the latest Slicer Stable Release, or install the latest Slicer Preview Release (extension updates are not available for preview releases).

---

<div class="post-metadata">

### Author: ![Gonzalo\_Rojas\_Costa](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/gonzalo_rojas_costa/32/5259_2.png) [@Gonzalo\_Rojas\_Costa](https://discourse.slicer.org/u/Gonzalo_Rojas_Costa)
#### Post date: [July 22, 2022, 2:31pm UTC](https://discourse.slicer.org/t/new-extension-hdbrainextraction-for-ai-based-skull-stripping/24420/10 "2022-07-22T14:31:05Z")

</div>

HDBrainExtraction is useful for non-volumetric T1 images?

---

<div class="post-metadata">

### Author: ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)
#### Post date: [July 23, 2022, 5:26am UTC](https://discourse.slicer.org/t/new-extension-hdbrainextraction-for-ai-based-skull-stripping/24420/11 "2022-07-23T05:26:45Z")

</div>

I would expect that the module only works for images that contains many slices and cover the full brain, but you can try it on síngle-slice images, too.

If you find that it does not work then you can train a new network specifically for síngle-slice images. You should be able to automatically generate training data from full-brain data sets.

---

<div class="post-metadata">

### Author: ![spichardo](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/spichardo/32/15092_2.png) [@spichardo](https://discourse.slicer.org/u/spichardo)
#### Post date: [July 29, 2022, 12:13am UTC](https://discourse.slicer.org/t/new-extension-hdbrainextraction-for-ai-based-skull-stripping/24420/12 "2022-07-29T00:13:11Z")

</div>

This is great… do you know if there is a way to hack the Pytorch installation to swap it to use the Metal-backend that is now available for M1/M2 processors?

---

<div class="post-metadata">

### Author: ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)
#### Post date: [July 29, 2022, 5:53am UTC](https://discourse.slicer.org/t/new-extension-hdbrainextraction-for-ai-based-skull-stripping/24420/13 "2022-07-29T05:53:49Z")

</div>

Wet use [light-the-torch](https://pypi.org/project/light-the-torch/) to install pytorch. Check out its documentation for ARM architecture compatibility. Note that Slicer runs on ARM macs through Rosetta emulation, which might complicate things a bit further.

---

<div class="post-metadata">

### Author: ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)
#### Post date: [December 30, 2022, 1:12am UTC](https://discourse.slicer.org/t/new-extension-hdbrainextraction-for-ai-based-skull-stripping/24420/15 "2022-12-30T01:12:04Z")

</div>

Let’s see if you get more information if you run the installation from the Windows terminal. Exit Slicer and run this command in the Command Prompt:

> “%localappdata%\NA-MIC\Slicer 5.2.1\bin\PythonSlicer.exe” -m pip install git+https://github.com/MIC-DKFZ/batchgenerators#egg=batchgenerators

---

<div class="post-metadata">

### Author: ![Tobias](https://avatars.discourse-cdn.com/v4/letter/t/c67d28/32.png) [@Tobias](https://discourse.slicer.org/u/Tobias)
#### Post date: [January 2, 2024, 7:31am UTC](https://discourse.slicer.org/t/new-extension-hdbrainextraction-for-ai-based-skull-stripping/24420/17 "2024-01-02T07:31:34Z")

</div>

This works very well! I was just wondering if it is possible to generate a mask with higher resolution?

---

<div class="post-metadata">

### Author: ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)
#### Post date: [January 2, 2024, 6:00pm UTC](https://discourse.slicer.org/t/new-extension-hdbrainextraction-for-ai-based-skull-stripping/24420/18 "2024-01-02T18:00:45Z")

</div>

You can get higher-resolution segmentation if you use a GPU. In CPU mode the resolution is automatically reduced to keep the computation time lower.
