# Thresholdmann: A Web tool for interactively creating adaptive thresholds to segment MRI data

Katja Heuer, Nicolas Traut, Roberto Toro

► To cite this version:

Katja Heuer, Nicolas Traut, Roberto Toro. Thresholdmann: A Web tool for interactively creating adaptive thresholds to segment MRI data. Journal of Open Source Software, 2024, 9 (97), pp.6336. 10.21105/joss.06336. pasteur-04621981

HAL Id: pasteur-04621981

https://pasteur.hal.science/pasteur-04621981

Submitted on 24 Jun 2024

HAL is a multi-disciplinary open access
archive for the deposit and dissemination of sci-
entific research documents, whether they are pub-
lished or not. The documents may come from
teaching and research institutions in France or
abroad, or from public or private research centers.

L'archive ouverte pluridisciplinaire HAL, est
destinée au dépôt et à la diffusion de documents
scientifiques de niveau recherche, publiés ou non,
émanant des établissements d'enseignement et de
recherche français ou étrangers, des laboratoires
publics ou privés.

<figure><img src="image_1.png" /></figure>

Distributed under a Creative Commons Attribution 4.0 International License
# Thresholdmann: A Web tool for interactively creating adaptive thresholds to segment MRI data.

Katja Heuer¹, Nicolas Traut¹, and Roberto Toro¹

1 Institut Pasteur, Université Paris Cité, Unité de Neuroanatomie Appliquée et Théorique, F-75015 Paris, France

DOI: 10.21105/joss.06336

## Software

- Review ⚙️

- Repository ⚙️

- Archive ⚙️

Editor: Adam Tyson ⚙️

## Reviewers:

- @sneakers-the-rat

- @62442katieb

- @anibalsolon

Submitted: 11 December 2023

Published: 03 May 2024

## License

Authors of papers retain copyright and release the work under a Creative Commons Attribution 4.0 International License (CC BY 4.0).

## Summary

Brain extraction and segmentation are the first step for most neuroimaging analyses. Automatic methods work well in adult human brains, but produce unreliable results in non-human data, due to muscle tissue, skull, and luminosity gradients. Thresholdmann (https://neuroanatomy.github.io/thresholdmann) is an open source Web tool for the interactive application of space-varying thresholds to Nifti volumes. No download or installation are required and all processing is done on the user's computer. Nifti volumes are dragged and dropped onto the Web app and become available for visual exploration in a stereotaxic viewer. A space-varying threshold is then created by setting control points, each with their own local threshold. Each point can be repositioned or removed, and each local threshold can be adjusted in real time using sliders or entering their values numerically. The threshold direction can be switched to allow segmentation of the structure of interest in different imaging modalities, such as T1 and T2 weighted contrasts. The opacity of the mask and the brightness and contrast of the MRI image can be adjusted via sliders. A 3D model of the thresholded mask can be computed to inspect the result in an interactive 3D render. Finally, the thresholded mask, the space varying threshold and the list of control points can be saved for later use in scripted workflows, able to reproduce the thresholded volume from the original data.

## Statement of need

Brain extraction and segmentation are required for most analyses of neuroimaging data. Obtaining appropriate masks can be particularly difficult in non-human brain imaging, as standard automatic tools struggle with the surrounding muscle tissue, skull, and strong luminosity gradients. A simple interactive threshold is intuitive and fast to apply, and can often provide a rather good initial guess. However, because of luminosity gradients, the threshold that works for one brain region is likely to fail in another.

Thresholdmann complements the variety of existing brain segmentation tools, providing an easy interface to manually control the segmentation on a local scale across different brain imaging modalities and image contrast gradients. The masks produced by Thresholdmann can serve as a starting point for more detailed manual editing using tools such as BrainBox (https://brainbox.pasteur.fr) (Heuer et al., 2016) or ITK-SNAP (http://www.itksnap.org) (Yushkevich et al., 2006). This interactive approach is especially valuable for non-human brain imaging data, where automatic approaches often require extensive manual adjustment anyway (Messinger et al., 2020; Milham et al., 2020, 2022). We have used Thresholdmann successfully to create initial brain masks for a variety of vertebrate brains – including many non-human primate datasets (Heuer et al., 2019; Magielse et al., 2023) – as well as developmental data. Small Web tools, such as Thresholdmann or Reorient (https://neuroanatomy.github.io/reorient) (Heuer & Toro, 2020), focused on solving a single problem, can become helpful additions to the methodological toolbox of neuroimagers.
# Thresholdmann: A Web tool for interactively creating adaptive thresholds to segment MRI data.

Katja Heuer¹, Nicolas Traut¹, and Roberto Toro¹

1 Institut Pasteur, Université Paris Cité, Unité de Neuroanatomie Appliquée et Théorique, F-75015 Paris, France

DOI: 10.21105/joss.06336

## Software

- Review ⚙️

- Repository ⚙️

- Archive ⚙️

Editor: Adam Tyson ⚙️

## Reviewers:

- @sneakers-the-rat

- @62442katieb

- @anibalsolon

Submitted: 11 December 2023

Published: 03 May 2024

## License

Authors of papers retain copyright and release the work under a Creative Commons Attribution 4.0 International License (CC BY 4.0).

## Summary

Brain extraction and segmentation are the first step for most neuroimaging analyses. Automatic methods work well in adult human brains, but produce unreliable results in non-human data, due to muscle tissue, skull, and luminosity gradients. Thresholdmann (https://neuroanatomy.github.io/thresholdmann) is an open source Web tool for the interactive application of space-varying thresholds to Nifti volumes. No download or installation are required and all processing is done on the user's computer. Nifti volumes are dragged and dropped onto the Web app and become available for visual exploration in a stereotaxic viewer. A space-varying threshold is then created by setting control points, each with their own local threshold. Each point can be repositioned or removed, and each local threshold can be adjusted in real time using sliders or entering their values numerically. The threshold direction can be switched to allow segmentation of the structure of interest in different imaging modalities, such as T1 and T2 weighted contrasts. The opacity of the mask and the brightness and contrast of the MRI image can be adjusted via sliders. A 3D model of the thresholded mask can be computed to inspect the result in an interactive 3D render. Finally, the thresholded mask, the space varying threshold and the list of control points can be saved for later use in scripted workflows, able to reproduce the thresholded volume from the original data.

## Statement of need

Brain extraction and segmentation are required for most analyses of neuroimaging data. Obtaining appropriate masks can be particularly difficult in non-human brain imaging, as standard automatic tools struggle with the surrounding muscle tissue, skull, and strong luminosity gradients. A simple interactive threshold is intuitive and fast to apply, and can often provide a rather good initial guess. However, because of luminosity gradients, the threshold that works for one brain region is likely to fail in another.

Thresholdmann complements the variety of existing brain segmentation tools, providing an easy interface to manually control the segmentation on a local scale across different brain imaging modalities and image contrast gradients. The masks produced by Thresholdmann can serve as a starting point for more detailed manual editing using tools such as BrainBox (https://brainbox.pasteur.fr) (Heuer et al., 2016) or ITK-SNAP (http://www.itksnap.org) (Yushkevich et al., 2006). This interactive approach is especially valuable for non-human brain imaging data, where automatic approaches often require extensive manual adjustment anyway (Messinger et al., 2020; Milham et al., 2020, 2022). We have used Thresholdmann successfully to create initial brain masks for a variety of vertebrate brains – including many non-human primate datasets (Heuer et al., 2019; Magielse et al., 2023) – as well as developmental data. Small Web tools, such as Thresholdmann or Reorient (https://neuroanatomy.github.io/reorient) (Heuer & Toro, 2020), focused on solving a single problem, can become helpful additions to the methodological toolbox of neuroimagers.
Methods

The spatially-varying threshold is computed from a number of control points. Each control point has a position $x_i$ and a threshold value $v_i$ that can be adjusted interactively. At each point $x$ of the volume, the local threshold is computed as a weighted function of the control points. The weight associated to the $i$-th control point at position $x$ is given by:

$$w_i(x) = \frac{1}{(x - x_i)^2 + \epsilon},$$

where $\epsilon$ is a small number used to prevent a division by 0 at the exact position of control points. The value of the threshold at position $x$ is the obtained as:

$$v(x) = \frac{\sum_{i}^{n} v_i w_i(x)}{W(x)},$$

where $W(x)$ is the sum of all weights, given by:

$$W(x) = \sum_{i}^{n} w_i(x).$$

Additionally, we add a "background" threshold value which makes the action of the control points localised. The background value is independent of the distance and is given a small constant weight. In that manner, positions far from all control points get the background threshold value.

Thresholdmann was coded in JavaScript and runs from a GitHub page. Code style was verified using ESLint (https://eslint.org). Unit tests and end-to-end tests were implemented using Mocha (https://mochajs.org) and Playwright (https://playwright.dev). Modifications in the code are continuously tested using CircleCI (https://circleci.com).
Methods

The spatially-varying threshold is computed from a number of control points. Each control point has a position $x_i$ and a threshold value $v_i$ that can be adjusted interactively. At each point $x$ of the volume, the local threshold is computed as a weighted function of the control points. The weight associated to the $i$-th control point at position $x$ is given by:

$$w_i(x) = \frac{1}{(x - x_i)^2 + \epsilon},$$

where $\epsilon$ is a small number used to prevent a division by 0 at the exact position of control points. The value of the threshold at position $x$ is the obtained as:

$$v(x) = \frac{\sum_{i}^{n} v_i w_i(x)}{W(x)},$$

where $W(x)$ is the sum of all weights, given by:

$$W(x) = \sum_{i}^{n} w_i(x).$$

Additionally, we add a "background" threshold value which makes the action of the control points localised. The background value is independent of the distance and is given a small constant weight. In that manner, positions far from all control points get the background threshold value.

Thresholdmann was coded in JavaScript and runs from a GitHub page. Code style was verified using ESLint (https://eslint.org). Unit tests and end-to-end tests were implemented using Mocha (https://mochajs.org) and Playwright (https://playwright.dev). Modifications in the code are continuously tested using CircleCI (https://circleci.com).
Figures

<figure><img src="image_1.png" /><figcaption>**Figure 1: Interface and 3D viewer.** The left panel allows to select different control point actions, set the thresholding direction, switch between the threshold mask or value view, open the 3D viewer, load or save the work, change the opacity of the mask, the brightness and contrast of the MRI, and information about the imaging data. The **central panel** is a stereotaxic viewer which allows the user to move through the slices using the slider at the bottom, to switch between the 3 stereotaxic planes, and to interactively set, move or remove control points. Users can view the threshold mask, or the corresponding threshold value space. The **right panel** shows for each control point the stereotaxic coordinates, an adjustment slider to change the local threshold, and the threshold value. The selected control point is highlighted in the panel and the viewer jumps to the corresponding slice. The **interactive 3D viewer** opens in a separate browser window.</figcaption></figure>
Figures

<figure><img src="image_2.png" /><figcaption>**Figure 1:** **Interface and 3D viewer.** The left panel allows to select different control point actions, set the thresholding direction, switch between the threshold mask or value view, open the 3D viewer, load or save the work, change the opacity of the mask, the brightness and contrast of the MRI, and information about the imaging data. The **central panel** is a stereotaxic viewer which allows the user to move through the slices using the slider at the bottom, to switch between the 3 stereotaxic planes, and to interactively set, move or remove control points. Users can view the threshold mask, or the corresponding threshold value space. The **right panel** shows for each control point the stereotaxic coordinates, an adjustment slider to change the local threshold, and the threshold value. The selected control point is highlighted in the panel and the viewer jumps to the corresponding slice. The **interactive 3D viewer** opens in a separate browser window.</figcaption></figure>
<figure><img src="image_2.png" /><figcaption>**Figure 2:** Usage example: Placing control points. Control points (blue dots) are added by clicking at the desired position in the viewer. This adds a slider to the right, which can be used to locally adapt the threshold. The figure describes the progressive addition of control points to create a mask of the brain for a macaque from Prime-DE site "amu" (Brochier et al., 2019; Milham et al., 2020).</figcaption></figure>

<figure><img src="image_3.png" /><figcaption>**Figure 3:** Usage example: Resulting mask and space-varying threshold. Threshold mask and corresponding threshold value. These volumes are updated in real time and can both be inspected interactively. The set of control points and the mask can be downloaded.</figcaption></figure>
<figure><img src="image_3.png" /><figcaption>**Figure 2:** Usage example: Placing control points. Control points (blue dots) are added by clicking at the desired position in the viewer. This adds a slider to the right, which can be used to locally adapt the threshold. The figure describes the progressive addition of control points to create a mask of the brain for a macaque from Prime-DE site "amu" (Brochier et al., 2019; Milham et al., 2020).</figcaption></figure>

<figure><img src="image_4.png" /><figcaption>**Figure 3:** Usage example: Resulting mask and space-varying threshold. Threshold mask and corresponding threshold value. These volumes are updated in real time and can both be inspected interactively. The set of control points and the mask can be downloaded.</figcaption></figure>
<figure><img src="image_4.png" /><figcaption>**Figure 4:** Usage example: Final mask. We downloaded the mask presented above based on the shown set of eight control points. The brain region was sufficiently disjoint from the rest of the head so that a mathematical morphology closing was enough to completely separate it. The figure shows stereotaxic planes and a surface reconstruction of the mask.</figcaption></figure>

## Acknowledgements

We thank Demian Wassermann for discussions about radial basis functions that inspired the first version of our tool. Funded by project DMOBE (ANR-21-CE45-0016) and the European Union's Horizon 2020 research and innovation programme under the Marie Skłodowska-Curie grant agreement No101033485 (KH Individual Fellowship).

## References

Brochier, T., Belin, P., Chavanne, F., Velly, L., Bodin, C., Renaud, L., Martin, M., Boes, L., Sein, J., Nazarian, B., & al., et. (2019). *Macaca mulatta* structural and diffusion weighted *MRI data*. Zenodo. https://doi.org/10.5281/ZENODO.3402456

Heuer, K., Ghosh, S., Robinson Sterling, A., & Toro, R. (2016). Open neuroimaging laboratory. *Research Ideas and Outcomes*, 2, e9113. https://doi.org/10.3897/rio.2.e9113

Heuer, K., Gulban, O. F., Bazin, P.-L., Osoianu, A., Valabregue, R., Santin, M., Herbin, M., & Toro, R. (2019). Evolution of neocortical folding: A phylogenetic comparative analysis of MRI from 34 primate species. *Cortex*, 118, 275-291. https://doi.org/10.1016/j.cortex.2019.04.011

Heuer, K., & Toro, R. (2020). Reorient: A web tool for reorienting and cropping MRI data. *Journal of Open Source Software*, 5(55), 2670. https://doi.org/10.21105/joss.02670

Magielse, N., Toro, R., Steigauf, V., Abbaspour, M., Eickhoff, S. B., Heuer, K., & Valk, S. L. (2023). Phylogenetic comparative analysis of the cerebello-cerebral system in 34 species highlights primate-general expansion of cerebellar crura i-II. *Communications Biology*, 6, 1188. https://doi.org/10.1038/s42003-023-05553-z

Messinger, A., Sirmpilatze, N., Heuer, K., Loh, K. K., Mars, R. B., Sein, J., Xu, T., Glen, D., Jung, B., Seidlitz, J., & al., et. (2020). A collaborative resource platform for non-human primate neuroimaging. *NeurolImage*, 226, 117519. https://doi.org/10.1016/j.neuroimage.2020.117519

Milham, M., Petkov, C. I., Belin, P., Ben Hamed, S., Evrard, H., Fair, D., Fox, A., Froudist-Walsh, S., Hayashi, T., & al., et. (2022). Toward next-generation primate neuroscience: A collaboration-based strategic plan for integrative neuroimaging. *Neuron*, 110(1), 16-20. https://doi.org/10.1016/j.neuron.2021.10.015

Milham, M., Petkov, C. I., Margulies, D. S., Schroeder, C. E., Basso, M. A., Belin, P., Fair, D. A., Fox, A., Kastner, S., Mars, R. B., & al., et. (2020). Accelerating the evolution of nonhuman primate neuroimaging. *Neuron*, 105(4), 600-603. https://doi.org/10.1016/j.neuron.2019.12.023
<figure><img src="image_5.png" /><figcaption>**Figure 4: Usage example: Final mask.** We downloaded the mask presented above based on the shown set of eight control points. The brain region was sufficiently disjoint from the rest of the head so that a mathematical morphology closing was enough to completely separate it. The figure shows stereotaxic planes and a surface reconstruction of the mask.</figcaption></figure>

## Acknowledgements

We thank Demian Wassermann for discussions about radial basis functions that inspired the first version of our tool. Funded by project DMOBE (ANR-21-CE45-0016) and the European Union's Horizon 2020 research and innovation programme under the Marie Skłodowska-Curie grant agreement No101033485 (KH Individual Fellowship).

## References

Brochier, T., Belin, P., Chavanne, F., Velly, L., Bodin, C., Renaud, L., Martin, M., Boes, L., Sein, J., Nazarian, B., & al., et. (2019). *Macaca mulatta* structural and diffusion weighted *MRI data*. Zenodo. https://doi.org/10.5281/ZENODO.3402456

Heuer, K., Ghosh, S., Robinson Sterling, A., & Toro, R. (2016). Open neuroimaging laboratory. *Research Ideas and Outcomes*, 2, e9113. https://doi.org/10.3897/rio.2.e9113

Heuer, K., Gulban, O. F., Bazin, P.-L., Osoianu, A., Valabregue, R., Santin, M., Herbin, M., & Toro, R. (2019). Evolution of neocortical folding: A phylogenetic comparative analysis of MRI from 34 primate species. *Cortex*, 118, 275-291. https://doi.org/10.1016/j.cortex.2019.04.011

Heuer, K., & Toro, R. (2020). Reorient: A web tool for reorienting and cropping MRI data. *Journal of Open Source Software*, 5(55), 2670. https://doi.org/10.21105/joss.02670

Magielse, N., Toro, R., Steigauf, V., Abbaspour, M., Eickhoff, S. B., Heuer, K., & Valk, S. L. (2023). Phylogenetic comparative analysis of the cerebello-cerebral system in 34 species highlights primate-general expansion of cerebellar crura i-II. *Communications Biology*, 6, 1188. https://doi.org/10.1038/s42003-023-05553-z

Messinger, A., Sirmpilatze, N., Heuer, K., Loh, K. K., Mars, R. B., Sein, J., Xu, T., Glen, D., Jung, B., Seidlitz, J., & al., et. (2020). A collaborative resource platform for non-human primate neuroimaging. *NeurolImage*, 226, 117519. https://doi.org/10.1016/j.neuroimage.2020.117519

Milham, M., Petkov, C. I., Belin, P., Ben Hamed, S., Evrard, H., Fair, D., Fox, A., Froudist-Walsh, S., Hayashi, T., & al., et. (2022). Toward next-generation primate neuroscience: A collaboration-based strategic plan for integrative neuroimaging. *Neuron*, 110(1), 16-20. https://doi.org/10.1016/j.neuron.2021.10.015

Milham, M., Petkov, C. I., Margulies, D. S., Schroeder, C. E., Basso, M. A., Belin, P., Fair, D. A., Fox, A., Kastner, S., Mars, R. B., & al., et. (2020). Accelerating the evolution of nonhuman primate neuroimaging. *Neuron*, 105(4), 600-603. https://doi.org/10.1016/j.neuron.2019.12.023
Yushkevich, P. A., Piven, J., Hazlett, H. C., Smith, R. G., Ho, S., Gee, J. C., & Gerig, G. (2006). User-guided 3D active contour segmentation of anatomical structures: Significantly improved efficiency and reliability. *NeuroImage*, 31(3), 1116–1128. https://doi.org/10.1016/j.neuroimage.2006.01.015
Yushkevich, P. A., Piven, J., Hazlett, H. C., Smith, R. G., Ho, S., Gee, J. C., & Gerig, G. (2006). User-guided 3D active contour segmentation of anatomical structures: Significantly improved efficiency and reliability. *NeuroImage*, 31(3), 1116–1128. https://doi.org/10.1016/j.neuroimage.2006.01.015