# SlicerBS for brain image segmentation

**URL:** <https://discourse.slicer.org/t/slicerbs-for-brain-image-segmentation/17676>\
**Category:** Development\
**Tags:** segmentation, extensions-manager, brain\
**Created:** [May 18, 2021, 2:03pm UTC](https://discourse.slicer.org/t/slicerbs-for-brain-image-segmentation/17676 "2021-05-18T14:03:54Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mehran](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/mehran/32/11080_2.png) [@Mehran](https://discourse.slicer.org/u/Mehran)\
**Post date:** [May 18, 2021, 2:03pm UTC](https://discourse.slicer.org/t/slicerbs-for-brain-image-segmentation/17676/1 "2021-05-18T14:03:54Z")

</div>

Dear members,  
I shared a new brain segmentation module using deep learning to extract brain and Tsallis entropy for segmentation. If you work on brain images, please have a look and let me know any feedback.  
You need to download SlicerBS ([GitHub - Mehrancd/SlicerBS: A Slicer module for brain extraction and segmentation](https://github.com/Mehrancd/SlicerBS)) and add it to Slicer-\>Edit-\>Application Settings-\>Modules, then add the path of the module to “Additional module paths” and restart. The module needs TensorFlow, scikit, etc. which automatically will be installed. If you receive an error, push apply again and probably will solve it. If you need a fast processing, you should increase the voxel size using “resample scaler volume” tool. More detail about algorithm: [https://doi.org/10.1016/j.mri.2019.11.002](https://doi.org/10.1016/j.mri.2019.11.002))  
and how to use: [SlicerBS: Extract and segment brain on MRI images into White Matter, Grey Matter and CSF - YouTube](https://www.youtube.com/watch?v=gH4dkXm3B2E&t=51s)  
Mehran

---

<div class="post-metadata">

**Author:** ![pieper](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/pieper/32/8_2.png) [@pieper](https://discourse.slicer.org/u/pieper)\
**Post date:** [May 18, 2021, 9:02pm UTC](https://discourse.slicer.org/t/slicerbs-for-brain-image-segmentation/17676/2 "2021-05-18T21:02:20Z")

</div>

Cool work, thanks for making it available 👍

---

<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:** [May 19, 2021, 4:42am UTC](https://discourse.slicer.org/t/slicerbs-for-brain-image-segmentation/17676/3 "2021-05-19T04:42:17Z")

</div>

Thank you, this is really nice work! It took 36 minutes on my ultrabook (including downloading and installing all dependencies), but it gave meaningful results for the MRHead volume with default options:

 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/4/d/4dc0e218fc41c4fc8a61c4e7a9e19554f54246a4.jpeg)

A few suggestions:

- Save segmentation result into a segmentation node. It takes just a few lines of Python script to convert a labelmap volume node to segmentation node. Set the correct segment names.
- Ask the user before starting to download&install enourmous packages, such as tensorflow (right now, the application may remain unresponsive for so long during the installation that, most users would think that the application crashed. See an example in the [script repository](https://slicer.readthedocs.io/en/latest/developer_guide/script_repository.html#install-a-python-package).
- Instead of lengthy explanation of what the user should do in what order, simplify the user interface. For example, you could create two sections: brain mask extraction and brain segmentation. Remove the “Only extract brain mask” option and instead disable brain segmentation section until a valid brain mask is created or selected. Add a node selector for brain mask (the user may have a brain mask computed already). Disable segmentation section until a valid brain mask is selected. Add more meaningful names for q, alpha, beta, gamma parameters (you can keep the letters in a parentheses in parentheses after the meaningful name, for cross-referencing with the cited paper). Describe meaning of each parameter in tooltips, in a way that is relevant for end uses (description of “Brain extract param” is a good example, it is understandable for the end user).
- Fix typos: “param” (use full word - parameter), “higer” in tooltip, tooltip contradicts with help text (higher “brain extract param” will result in larger or smaller volume? larger would be a bit more intuitive).
- I would recommend to rename the extension to have a more descriptive name, such as TsallisBrainSegmentation. SlicerBS is not descriptive enough and in North America you don’t want your extension to be associated with [BS](https://www.urbandictionary.com/define.php?term=BS).
- Remove ` __pycache__ ` folders from the repository
- Submit this to the extension manager so that users can find it and install it much more easily.

---

<div class="post-metadata">

**Author:** ![Mehran](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/mehran/32/11080_2.png) [@Mehran](https://discourse.slicer.org/u/Mehran)\
**Post date:** [May 19, 2021, 6:39am UTC](https://discourse.slicer.org/t/slicerbs-for-brain-image-segmentation/17676/4 "2021-05-19T06:39:35Z")

</div>

Thanks @lassoan for the great suggestions which I was waiting for.

---

<div class="post-metadata">

**Author:** ![Mehran](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/mehran/32/11080_2.png) [@Mehran](https://discourse.slicer.org/u/Mehran)\
**Post date:** [May 28, 2021, 8:33am UTC](https://discourse.slicer.org/t/slicerbs-for-brain-image-segmentation/17676/5 "2021-05-28T08:33:50Z")

</div>

Thanks @lassoan again. I tried to follow the comments and improve the module (except some which I did not know how) with a new name 🙂 . In addition, I fixed some issues to improve the accuracy. Please have a look and let me know your feedback. You can resample the head image (e.g., 2x2x2) to decrease time consumption considerably.

> **[GitHub - Mehrancd/TsallisBrainSegmentation: A Slicer module for brain...](https://github.com/Mehrancd/TsallisBrainSegmentation)**
>
> A Slicer module for brain extraction and segmentation - GitHub - Mehrancd/TsallisBrainSegmentation: A Slicer module for brain extraction and segmentation

 ![TBS](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/7/7/772b5eac639e6b4adb19e288410e9e1f6b615579.jpeg)

---

<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:** [May 28, 2021, 8:48pm UTC](https://discourse.slicer.org/t/slicerbs-for-brain-image-segmentation/17676/6 "2021-05-28T20:48:43Z")

</div>

Great, thanks for the update! If you have any specific question (any problems or suggestions that you could not fix) then let us know. If everything is ready then [send a pull request to the ExtensionsIndex](https://slicer.readthedocs.io/en/latest/developer_guide/extensions.html#distributing-an-extension).

---

<div class="post-metadata">

**Author:** ![slicer365](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/slicer365/32/67549_2.png) [@slicer365](https://discourse.slicer.org/u/slicer365)\
**Post date:** [May 29, 2021, 12:39pm UTC](https://discourse.slicer.org/t/slicerbs-for-brain-image-segmentation/17676/7 "2021-05-29T12:39:50Z")

</div>

I don’t know why I always fail to install tensorflow.

---

<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:** [May 29, 2021, 1:01pm UTC](https://discourse.slicer.org/t/slicerbs-for-brain-image-segmentation/17676/8 "2021-05-29T13:01:08Z")

</div>

The pip install looks good. You have a few harmless warnings:

1. Since you don’t use the command-line from Slicer’s Python environment it is perfectly fine to not adding scripts to the path.
2. If you want, you can update pip, but it very rarely makes any difference.

The error is in your Python code: you call `GetDimensions()` method for a variable that is set to `None`. I would recommend to set up a debugger as described [here](https://github.com/SlicerRt/SlicerDebuggingTools#debuggingtools-extension-for-3d-slicer), because then you don’t need to guess what’s happening or add temporary log messages, but you can very easily step through the code and see what goes wrong.

---

<div class="post-metadata">

**Author:** ![Mehran](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/mehran/32/11080_2.png) [@Mehran](https://discourse.slicer.org/u/Mehran)\
**Post date:** [May 29, 2021, 1:55pm UTC](https://discourse.slicer.org/t/slicerbs-for-brain-image-segmentation/17676/9 "2021-05-29T13:55:33Z")

</div>

try the latest version might solve it.

---

<div class="post-metadata">

**Author:** ![danielgreenwood](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/danielgreenwood/32/11113_2.png) [@danielgreenwood](https://discourse.slicer.org/u/danielgreenwood)\
**Post date:** [May 31, 2021, 6:43pm UTC](https://discourse.slicer.org/t/slicerbs-for-brain-image-segmentation/17676/10 "2021-05-31T18:43:10Z")

</div>

Great work and very useful to know. Thanks for sharing, I appreciate this work! 👍

---

<div class="post-metadata">

**Author:** ![Mehran](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/mehran/32/11080_2.png) [@Mehran](https://discourse.slicer.org/u/Mehran)\
**Post date:** [May 31, 2021, 6:49pm UTC](https://discourse.slicer.org/t/slicerbs-for-brain-image-segmentation/17676/11 "2021-05-31T18:49:36Z")

</div>

Thanks @danielgreenwood

---

<div class="post-metadata">

**Author:** ![zhang\_han](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/zhang_han/32/66574_2.png) [@zhang\_han](https://discourse.slicer.org/u/zhang_han)\
**Post date:** [August 17, 2023, 3:01am UTC](https://discourse.slicer.org/t/slicerbs-for-brain-image-segmentation/17676/12 "2023-08-17T03:01:17Z")

</div>

Thanks for sharing, I want to save the segmentation result as obj file separately, can this plugin save the segmentation result into the segmentation node separately?

---

<div class="post-metadata">

**Author:** ![Mehran](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/mehran/32/11080_2.png) [@Mehran](https://discourse.slicer.org/u/Mehran)\
**Post date:** [August 17, 2023, 8:52am UTC](https://discourse.slicer.org/t/slicerbs-for-brain-image-segmentation/17676/13 "2023-08-17T08:52:16Z")

</div>

Hi @zhang_han , if I understand well, you want to save label map as segmentation node. To to this, you only need to right-click on label and convert it to segmentation node in Data module. you also can convert each label (GM, WM, CSF) again to binary label map using right-click in the same module.

---

<div class="post-metadata">

**Author:** ![zhang\_han](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/zhang_han/32/66574_2.png) [@zhang\_han](https://discourse.slicer.org/u/zhang_han)\
**Post date:** [August 18, 2023, 3:49am UTC](https://discourse.slicer.org/t/slicerbs-for-brain-image-segmentation/17676/14 "2023-08-18T03:49:23Z")

</div>

I’ve successfully exported the file. Thanks for your response!
