# A modular framework for multi-scale tissue imaging and neuronal segmentation

Simone Cauzzo, Ester Bruno, David Boulet, Paul Nazac, Miriam Basile, Alejandro Luis Callara, Federico Tozzi, Arti Ahluwalia, Chiara Magliaro, Lydia Danglot, et al.

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

## To cite this version:

Simone Cauzzo, Ester Bruno, David Boulet, Paul Nazac, Miriam Basile, et al. A modular framework for multi-scale tissue imaging and neuronal segmentation. Nature Communications, 2024, 15 (1), pp.4102. 10.1038/s41467-024-48146-y. inserm-04604576

HAL Id: inserm-04604576

https://inserm.hal.science/inserm-04604576

Submitted on 7 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_2.png" /></figure>
# A modular framework for multi-scale tissue imaging and neuronal segmentation

Simone Cauzzo, Ester Bruno, David Boulet, Paul Nazac, Miriam Basile, Alejandro Luis Callara, Federico Tozzi, Arti Ahluwalia, Chiara Magliaro, Lydia Danglot, et al.

► To cite this version:

Simone Cauzzo, Ester Bruno, David Boulet, Paul Nazac, Miriam Basile, et al. A modular framework for multi-scale tissue imaging and neuronal segmentation. Nature Communications, 2024, 15 (1), pp.4102. 10.1038/s41467-024-48146-y. inserm-04604576

HAL Id: inserm-04604576

https://inserm.hal.science/inserm-04604576v1

Submitted on 7 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>
<figure><img src="image_3.png" /></figure>

# A modular framework for multi-scale tissue imaging and neuronal segmentation

Received: 20 April 2023

Accepted: 23 April 2024

Published online: 22 May 2024

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

Check for updates

Simone Cauzzo<sup>1,2</sup>✉, Ester Bruno<sup>1,3</sup>, David Boulet<sup>4,5</sup>, Paul Nazac<sup>5</sup>, Miriam Basile<sup>3</sup>, Alejandro Luis Callara<sup>1,3</sup>, Federico Tozzi<sup>1,3</sup>, Arti Ahluwalia<sup>1,3</sup>, Chiara Magliaro<sup>1,3</sup>, Lydia Danglot<sup>4,5,6</sup>✉ & Nicola Vanello<sup>1,3,6</sup>✉

The development of robust tools for segmenting cellular and sub-cellular neuronal structures lags behind the massive production of high-resolution 3D images of neurons in brain tissue. The challenges are principally related to high neuronal density and low signal-to-noise characteristics in thick samples, as well as the heterogeneity of data acquired with different imaging methods. To address this issue, we design a framework which includes sample preparation for high resolution imaging and image analysis. Specifically, we set up a method for labeling thick samples and develop SENPAI, a scalable algorithm for segmenting neurons at cellular and sub-cellular scales in conventional and super-resolution STimulated Emission Depletion (STED) microscopy images of brain tissues. Further, we propose a validation paradigm for testing segmentation performance when a manual ground-truth may not exhaustively describe neuronal arborization. We show that SENPAI provides accurate multi-scale segmentation, from entire neurons down to spines, outperforming state-of-the-art tools. The framework will empower image processing of complex neuronal circuitries.

Describing the mammalian brain connectome at the cellular and sub-cellular scales is one of the holy grails in neuroscience<sup>1-3</sup>. The brain comprises billions of densely packed neurons<sup>4</sup>. Isolating single cells in their native arrangement within brain tissue represents a crucial step for describing neuronal shape, size and complexity, which enables in turn the characterization of cell types and the identification of any morphological abnormalities characterizing neuropathies<sup>2,5</sup>. Dendritic spines are tiny membranous protrusions on dendritic shafts that can be contacted by glutamatergic axons to form excitatory glutamatergic synapses. Spine morphology was first described by Ramon Y Cajal in 1888 using the Golgi Technique<sup>6</sup>. Their 3D morphology can be studied using the gold standard 3D electron microscopy (as reviewed in Harris et al. and Rasia-Filho et al.<sup>7,8</sup>). Dendritic spines can harbor various morphologies, from stubby

spines (short bulges of the membrane) to mushroom shapes (with thin necks and bulbous heads)<sup>9</sup>. More recently, based on ultrastructural analysis of mouse neocortical dendritic spine necks, the existence of subtypes of spines has been questioned, and a continuum of spine morphologies has instead been proposed<sup>10</sup>. Dendritic spines receive electric inputs which are locally regulated by spine neck geometry and resistance<sup>11,12</sup>. Furthermore, spine shape and density are linked to synaptic function, such as learning, memory and motivation<sup>13,14</sup> and changes in synaptic activity are associated with alterations in spine shape, size and number<sup>15,16</sup>. Structural alterations of spiny synapses are found in the pathogenesis of major neurological disorders (ASD, schizophrenia and Alzheimer's disease)<sup>17-19</sup>. Reduction in spine density and synaptic loss are found in patients with Alzheimer's disease and Mild Cognitive Impairment

<footnote n="1">¹Research Center “E. Piaggio”, University of Pisa, Pisa, Italy. ²Parkinson’s Disease and Movement Disorders Unit, Center for Rare Neurological Diseases (ERN-RND), Department of Neurosciences, University of Padova, Padova, Italy. ³Dipartimento di Ingegneria dell’Informazione, University of Pisa, Pisa, Italy. ⁴Université Paris Cité, Institute of Psychiatry and Neuroscience of Paris (IPNP), INSERM U1266, Neurlmag Core Facility, 75014 Paris, France. ⁵Université Paris Cité, Institute of Psychiatry and Neuroscience of Paris (IPNP), INSERM U1266, Membrane traffic and diseased brain, 75014 Paris, France. ⁶These authors jointly supervised this work: Lydia Danglot, Nicola Vanello. ✉e-mail: simone.cauzzo@unipd.it; lydia.danglot@inserm.fr; nicola.vanello@unipi.it</footnote>
<figure><img src="image_2.png" /></figure>

# A modular framework for multi-scale tissue imaging and neuronal segmentation

Received: 20 April 2023

Accepted: 23 April 2024

Published online: 22 May 2024

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

Check for updates

Simone Cauzzo<sup>1,2</sup>✉, Ester Bruno<sup>1,3</sup>, David Boulet<sup>4,5</sup>, Paul Nazac<sup>5</sup>, Miriam Basile<sup>3</sup>, Alejandro Luis Callara<sup>1,3</sup>, Federico Tozzi<sup>1,3</sup>, Arti Ahluwalia<sup>1,3</sup>, Chiara Magliaro<sup>1,3</sup>, Lydia Danglot<sup>4,5,6</sup>✉ & Nicola Vanello<sup>1,3,6</sup>✉

The development of robust tools for segmenting cellular and sub-cellular neuronal structures lags behind the massive production of high-resolution 3D images of neurons in brain tissue. The challenges are principally related to high neuronal density and low signal-to-noise characteristics in thick samples, as well as the heterogeneity of data acquired with different imaging methods. To address this issue, we design a framework which includes sample preparation for high resolution imaging and image analysis. Specifically, we set up a method for labeling thick samples and develop SENPAI, a scalable algorithm for segmenting neurons at cellular and sub-cellular scales in conventional and super-resolution STimulated Emission Depletion (STED) microscopy images of brain tissues. Further, we propose a validation paradigm for testing segmentation performance when a manual ground-truth may not exhaustively describe neuronal arborization. We show that SENPAI provides accurate multi-scale segmentation, from entire neurons down to spines, outperforming state-of-the-art tools. The framework will empower image processing of complex neuronal circuitries.

Describing the mammalian brain connectome at the cellular and sub-cellular scales is one of the holy grails in neuroscience<sup>1-3</sup>. The brain comprises billions of densely packed neurons<sup>4</sup>. Isolating single cells in their native arrangement within brain tissue represents a crucial step for describing neuronal shape, size and complexity, which enables in turn the characterization of cell types and the identification of any morphological abnormalities characterizing neuropathies<sup>2,5</sup>. Dendritic spines are tiny membranous protrusions on dendritic shafts that can be contacted by glutamatergic axons to form excitatory glutamatergic synapses. Spine morphology was first described by Ramon Y Cajal in 1888 using the Golgi Technique<sup>6</sup>. Their 3D morphology can be studied using the gold standard 3D electron microscopy (as reviewed in Harris et al. and Rasia-Filho et al.<sup>7,8</sup>). Dendritic spines can harbor various morphologies, from stubby

spines (short bulges of the membrane) to mushroom shapes (with thin necks and bulbous heads)<sup>9</sup>. More recently, based on ultrastructural analysis of mouse neocortical dendritic spine necks, the existence of subtypes of spines has been questioned, and a continuum of spine morphologies has instead been proposed<sup>10</sup>. Dendritic spines receive electric inputs which are locally regulated by spine neck geometry and resistance<sup>11,12</sup>. Furthermore, spine shape and density are linked to synaptic function, such as learning, memory and motivation<sup>13,14</sup> and changes in synaptic activity are associated with alterations in spine shape, size and number<sup>15,16</sup>. Structural alterations of spiny synapses are found in the pathogenesis of major neurological disorders (ASD, schizophrenia and Alzheimer's disease)<sup>17-19</sup>. Reduction in spine density and synaptic loss are found in patients with Alzheimer's disease and Mild Cognitive Impairment

<footnote n="1">¹Research Center “E. Piaggio”, University of Pisa, Pisa, Italy. ²Parkinson’s Disease and Movement Disorders Unit, Center for Rare Neurological Diseases (ERN-RND), Department of Neurosciences, University of Padova, Padova, Italy. ³Dipartimento di Ingegneria dell’Informazione, University of Pisa, Pisa, Italy. ⁴Université Paris Cité, Institute of Psychiatry and Neuroscience of Paris (IPNP), INSERM U1266, Neurlmag Core Facility, 75014 Paris, France. ⁵Université Paris Cité, Institute of Psychiatry and Neuroscience of Paris (IPNP), INSERM U1266, Membrane traffic and diseased brain, 75014 Paris, France. ⁶These authors jointly supervised this work: Lydia Danglot, Nicola Vanello. ✉e-mail: simone.cauzzo@unipd.it; lydia.danglot@inserm.fr; nicola.vanello@unipi.it</footnote>
(MCI)¹⁷,²⁰,²¹, suggesting their collective and individual role in brain dysfunctions¹⁸,²¹.

Several imaging methods have been developed to explore neu-
ronal structures at different spatial scales. Among these, single²² and
multi-photon confocal microscopy²³ are the cardinal tools to visualize
neurons from ex vivo or in vivo samples within their native environ-
ment, since they offer deep imaging solutions, with lateral and axial
resolutions from 180 nm in the XY plane to 500 nm in the Z direction,
respectively²⁴. On the other hand, super-resolution microscopy (e.g.,
STimulated Emission Depletion-STED), enables the characterization
of tiny dendritic spines²⁵⁻²⁸. However, brain tissue is prone to scattering
which limits the imaging depth (Z) in the tissue. The performance of
both confocal and super-resolution imaging can be improved via tissue
clearing and refractive index matching²⁹, which enable the acquisition
of larger sample volumes with improved signal-to-noise and contrast-
to-noise ratio (SNR and CNR), while maintaining low laser power³⁰.

Parallel to the advances in brain tissue labeling and imaging at both the micro and nanoscale, automatic algorithms aimed at high-fidelity three-dimensional (3D) reconstruction of single neurons have been extensively developed. Recent reviews on the topic²,³¹ provide a categorization point for more than forty algorithms (see Supplementary Table 1), each one exploiting key aspects of image properties (e.g., signal-to-noise ratio, point-spread-function, image contrast) and/or neuron features (e.g., axon tubularity, soma sphericity, tree-like structure) for developing a custom neuron reconstruction strategy. As such, their success is strongly influenced by both the acquisition modality and cell type and by the kind of features they rely on. For example, local methods based on a progressive propagation of the tracing or segmentation from a reference point are particularly sensitive to noise or local inhomogeneity, while global methods based on SNR will fail at handling smooth changes in SNR across the image stack. For this reason, developing general-purpose solutions is often impracticable. Some of these issues are partially solved by meta methods, i.e. modules that can be used on top of base tracing or segmentation algorithms to solve specific problems and improve the result (e.g., G-cut³² for post-hoc separation of interweaving neurons and UltraTracer³³ for increasing the scalability of tracing algorithms to large image stacks). It is worth highlighting that most of the algorithms for neuron segmentation from microscopy images proposed cannot isolate neurons acquired with different imaging modalities, and only few of them are able to deal with densely packed cells³²,³⁴⁻³⁶.

Similar considerations apply to methods based on Artificial
Intelligence (AI) approaches such as machine learning and deep
learning (for a summary categorization see Tables 3 and 5 in Chen
et al.³⁷), which have been successfully introduced thanks to the avail-
ability of high quality and large training datasets³⁸⁻⁴⁰. For the same
reasons, convolutional neural networks were recently introduced³⁸⁻⁴⁰.
AI approaches are in fact rapidly emerging as a solution to the complex
problem of neuronal reconstruction in microscopy images. However,
their direct application to previously unseen data (e.g., different
acquisition modality, cell type, SNR levels) strongly depends on the
training set (e.g., type of data, number of training examples), or ad-hoc
solutions (e.g., transfer learning⁴¹,⁴²), limiting their generalizability.
Although considerable effort is now being made to achieve explain-
ability in deep learning models⁴³, their black-box nature makes it dif-
ficult for users to exercise control over common issues such as over- or
under-segmentation. In addition, existing algorithms based on deep-
learning currently struggle in dealing with separating multiple struc-
tures within an image block³⁷ and to retrieve information beyond the
limits posed by image resolution, i.e., for spine morphology or spine
neck reconstruction. Finally, independent of the method used, manual
correction and fine-tuning of the automatic results by experts are still
required⁴⁴.

Neuroimaging data obtained from clarified tissues³, a genre of
methods which clear high opacity tissue lipids, represent unique

features in terms of both image quality (e.g., enhanced signal intensity, SNR, CNR) and the capability of imaging densely packed cells in a 3D arrangement<sup>2,34,45,46</sup>. But, the generalizability of neuron reconstruction algorithms is even lower when dealing with images from densely packed neurons. Moreover, the outcomes of such algorithms and tools are compared with a manually segmented ground truth reconstruction, which is time consuming, difficult to achieve and prone to human bias.

In the light of these challenges, we have designed a framework for extracting faithful morphological information from brain tissues at the neuronal and sub-neuronal level via imaging and image processing tools. Specifically, we developed a method for processing and acquiring brain tissue which returns large volume datasets representing neurons with an improved image quality. Then, we present a data-driven approach—SENPAI (SEgmentation of Neurons using PArtial derivative Information)—for neuron segmentation from 3D optical images. SENPAI benefits from image topological information and K-means clustering to provide faithful descriptions of isolated neuronal morphologies at multiple levels of detail which does not rely on constructing models of image signal and/or noise. Decision-making routines select classes representing neuronal structures in the image. K-means based segmentation is complemented by a parcellation step exploiting topographic distances. We employ morphological reconstruction and the watershed transform to ensure the correct separation of neurons when they are closely packed. The same strategy is used for the grouping and assignment of small spines to the body of a specific dendritic tree in high-resolution datasets without detectable necks.

Here we demonstrate the performance of the proposed approach using images from both confocal and super-resolution STED microscopy. As a proof of concept, we focused on the L7GFP mouse line which expresses cytosolic GFP in cerebellar Purkinje cells. As these cells are particularly densely packed, we cleared the samples to improve imaging depth. Thanks to deep super-resolution 3D STED imaging we were able to resolve dendritic spines over wide dendritic trunks. The algorithm was tested against state-of-the-art software and manual segmentation. Specifically, we compared the complexity of the resulting segmentations and assessed their performance in the detection and correct assignation of dendritic spines to neurons. Furthermore, we provide an original validation paradigm for evaluating the quality of segmentation, in which morphometrics extracted from the segmented neurons are compared with reliable quantitative indices of Purkinje cell morphology available in the literature⁴⁷. To evaluate the generalizability of the segmentation algorithm to other neuron types and imaging modalities, we tested SENPAI's performance using open datasets comprising both cultured and ex-vivo neurons. This study represents a significant advancement in the state-of-the-art for the comparison of segmented neurons, particularly when a reliable manually segmented ground-truth is not available and/or achievable.

Results

Labeling and super-resolution STED imaging of thick samples

Purkinje cells are characterized by a dendritic tree studded with
numerous dendritic spines, receiving roughly 200,000 synapses⁴⁸. To
unravel their morphology, we cleared thick slices of L7GFP mouse
brain samples²⁹,³⁰ and processed them for long-term immunochem-
istry. The pre-processing steps and the labeling strategy are shown in
Fig. 1A–C (see Methods for details).

To access several scale levels of information (from tissue slices with populations of cells, to the cell environment, a single dendritic tree, and local spine density) we set up the acquisition of correlative imaging using both low magnification for tissue scanning (20x) and high-resolution imaging (93x) of dendritic spine with either confocal or 3D STED microscopy. Reconstitution of wide mosaic brain area requires the use of tile imaging acquisitions that are very sensitive to
(MCI)¹⁷,²⁰,²¹, suggesting their collective and individual role in brain dysfunctions¹⁸,²¹.

Several imaging methods have been developed to explore neu-
ronal structures at different spatial scales. Among these, single²² and
multi-photon confocal microscopy²³ are the cardinal tools to visualize
neurons from ex vivo or in vivo samples within their native environ-
ment, since they offer deep imaging solutions, with lateral and axial
resolutions from 180 nm in the XY plane to 500 nm in the Z direction,
respectively²⁴. On the other hand, super-resolution microscopy (e.g.,
STimulated Emission Depletion-STED), enables the characterization
of tiny dendritic spines²⁵⁻²⁸. However, brain tissue is prone to scattering
which limits the imaging depth (Z) in the tissue. The performance of
both confocal and super-resolution imaging can be improved via tissue
clearing and refractive index matching²⁹, which enable the acquisition
of larger sample volumes with improved signal-to-noise and contrast-
to-noise ratio (SNR and CNR), while maintaining low laser power³⁰.

Parallel to the advances in brain tissue labeling and imaging at both the micro and nanoscale, automatic algorithms aimed at high-fidelity three-dimensional (3D) reconstruction of single neurons have been extensively developed. Recent reviews on the topic<sup>2,31</sup> provide a categorization point for more than forty algorithms (see Supplementary Table 1), each one exploiting key aspects of image properties (e.g., signal-to-noise ratio, point-spread-function, image contrast) and/or neuron features (e.g., axon tubularity, soma sphericity, tree-like structure) for developing a custom neuron reconstruction strategy. As such, their success is strongly influenced by both the acquisition modality and cell type and by the kind of features they rely on. For example, local methods based on a progressive propagation of the tracing or segmentation from a reference point are particularly sensitive to noise or local inhomogeneity, while global methods based on SNR will fail at handling smooth changes in SNR across the image stack. For this reason, developing general-purpose solutions is often impracticable. Some of these issues are partially solved by meta methods, i.e. modules that can be used on top of base tracing or segmentation algorithms to solve specific problems and improve the result (e.g., G-cut<sup>32</sup> for post-hoc separation of interweaving neurons and UltraTracer<sup>33</sup> for increasing the scalability of tracing algorithms to large image stacks). It is worth highlighting that most of the algorithms for neuron segmentation from microscopy images proposed cannot isolate neurons acquired with different imaging modalities, and only few of them are able to deal with densely packed cells<sup>32,34-36</sup>.

Similar considerations apply to methods based on Artificial
Intelligence (AI) approaches such as machine learning and deep
learning (for a summary categorization see Tables 3 and 5 in Chen
et al.³⁷), which have been successfully introduced thanks to the avail-
ability of high quality and large training datasets³⁸⁻⁴⁰. For the same
reasons, convolutional neural networks were recently introduced³⁸⁻⁴⁰.
AI approaches are in fact rapidly emerging as a solution to the complex
problem of neuronal reconstruction in microscopy images. However,
their direct application to previously unseen data (e.g., different
acquisition modality, cell type, SNR levels) strongly depends on the
training set (e.g., type of data, number of training examples), or ad-hoc
solutions (e.g., transfer learning⁴¹,⁴²), limiting their generalizability.
Although considerable effort is now being made to achieve explain-
ability in deep learning models⁴³, their black-box nature makes it dif-
ficult for users to exercise control over common issues such as over- or
under-segmentation. In addition, existing algorithms based on deep-
learning currently struggle in dealing with separating multiple struc-
tures within an image block³⁷ and to retrieve information beyond the
limits posed by image resolution, i.e., for spine morphology or spine
neck reconstruction. Finally, independent of the method used, manual
correction and fine-tuning of the automatic results by experts are still
required⁴⁴.

Neuroimaging data obtained from clarified tissues³, a genre of
methods which clear high opacity tissue lipids, represent unique

features in terms of both image quality (e.g., enhanced signal intensity, SNR, CNR) and the capability of imaging densely packed cells in a 3D arrangement<sup>2,34,45,46</sup>. But, the generalizability of neuron reconstruction algorithms is even lower when dealing with images from densely packed neurons. Moreover, the outcomes of such algorithms and tools are compared with a manually segmented ground truth reconstruction, which is time consuming, difficult to achieve and prone to human bias.

In the light of these challenges, we have designed a framework for extracting faithful morphological information from brain tissues at the neuronal and sub-neuronal level via imaging and image processing tools. Specifically, we developed a method for processing and acquiring brain tissue which returns large volume datasets representing neurons with an improved image quality. Then, we present a data-driven approach—SENPAI (SEgmentation of Neurons using PArtial derivative Information)—for neuron segmentation from 3D optical images. SENPAI benefits from image topological information and K-means clustering to provide faithful descriptions of isolated neuronal morphologies at multiple levels of detail which does not rely on constructing models of image signal and/or noise. Decision-making routines select classes representing neuronal structures in the image. K-means based segmentation is complemented by a parcellation step exploiting topographic distances. We employ morphological reconstruction and the watershed transform to ensure the correct separation of neurons when they are closely packed. The same strategy is used for the grouping and assignment of small spines to the body of a specific dendritic tree in high-resolution datasets without detectable necks.

Here we demonstrate the performance of the proposed approach using images from both confocal and super-resolution STED microscopy. As a proof of concept, we focused on the L7GFP mouse line which expresses cytosolic GFP in cerebellar Purkinje cells. As these cells are particularly densely packed, we cleared the samples to improve imaging depth. Thanks to deep super-resolution 3D STED imaging we were able to resolve dendritic spines over wide dendritic trunks. The algorithm was tested against state-of-the-art software and manual segmentation. Specifically, we compared the complexity of the resulting segmentations and assessed their performance in the detection and correct assignation of dendritic spines to neurons. Furthermore, we provide an original validation paradigm for evaluating the quality of segmentation, in which morphometrics extracted from the segmented neurons are compared with reliable quantitative indices of Purkinje cell morphology available in the literature⁴⁷. To evaluate the generalizability of the segmentation algorithm to other neuron types and imaging modalities, we tested SENPAI's performance using open datasets comprising both cultured and ex-vivo neurons. This study represents a significant advancement in the state-of-the-art for the comparison of segmented neurons, particularly when a reliable manually segmented ground-truth is not available and/or achievable.

Results

Labeling and super-resolution STED imaging of thick samples

Purkinje cells are characterized by a dendritic tree studded with
numerous dendritic spines, receiving roughly 200,000 synapses⁴⁸. To
unravel their morphology, we cleared thick slices of L7GFP mouse
brain samples²⁹,³⁰ and processed them for long-term immunochem-
istry. The pre-processing steps and the labeling strategy are shown in
Fig. 1A–C (see Methods for details).

To access several scale levels of information (from tissue slices with populations of cells, to the cell environment, a single dendritic tree, and local spine density) we set up the acquisition of correlative imaging using both low magnification for tissue scanning (20x) and high-resolution imaging (93x) of dendritic spine with either confocal or 3D STED microscopy. Reconstitution of wide mosaic brain area requires the use of tile imaging acquisitions that are very sensitive to
<figure><img src="image_5.png" /></figure>

<figure><img src="image_6.png" /><figcaption>**Fig. 1** | Labeling strategy for thick imaging in 3D super-resolution STED microscopy. A Embedding the tissue in hydrogel and cutting 6 slices (0.5–1 mm thick) using a vibratome. B Passive clearing via incubation in clarity solution. C Labeling protocol using primary and secondary fluorescent dedicated STED antibodies. D–G Floating slices mounted on a slide in the center of a homemade PVC spacer. H, I Spacer hole filled with prolong gold mounting media and covered with super-resolution 0.17 mm glass coverslip. Depending on slice thickness, several spacers can be stacked to keep coverslip parallel to the slide. J, K Spacers and</figcaption></figure>

coverslip sealed to the slide with silicone. L Confocal tile imaging of the cerebellum. M Confocal zoom in over Purkinje cells with 20x objective. N Conventional 3D confocal imaging over the Purkinje cell layer with dedicated Zoom in (O) around the cell body. P Single slice of 3D STED microscopy, revealing dendritic spine (white arrows) decorating the entire dendritic tree. Q 3D rendering of multiple 3D STED stacked slices showing the high density of dendritic spines within depth. Scale bar: 10 microns.
<figure><img src="image_4.png" /></figure>

<figure><img src="image_5.png" /><figcaption>**Fig. 1** | Labeling strategy for thick imaging in 3D super-resolution STED microscopy. A Embedding the tissue in hydrogel and cutting 6 slices (0.5–1 mm thick) using a vibratome. B Passive clearing via incubation in clarity solution. C Labeling protocol using primary and secondary fluorescent dedicated STED antibodies. D–G Floating slices mounted on a slide in the center of a homemade PVC spacer. H, I Spacer hole filled with prolong gold mounting media and covered with super-resolution 0.17 mm glass coverslip. Depending on slice thickness, several spacers can be stacked to keep coverslip parallel to the slide. J, K Spacers and</figcaption></figure>

coverslip sealed to the slide with silicone. L Confocal tile imaging of the cerebellum. M Confocal zoom in over Purkinje cells with 20x objective. N Conventional 3D confocal imaging over the Purkinje cell layer with dedicated Zoom in (O) around the cell body. P Single slice of 3D STED microscopy, revealing dendritic spine (white arrows) decorating the entire dendritic tree. Q 3D rendering of multiple 3D STED stacked slices showing the high density of dendritic spines within depth. Scale bar: 10 microns.
stage and sample flatness. Thus, to optimize sample flatness and working distance objective, we carefully designed custom-made spacers of calibrated thickness (300 microns thick PVC sheets) allowing light penetration directly into the samples without passing through thick mounting media layers. Using this device, glass coverslips were sealed parallel to the slice surface, allowing deep imaging using 93x 3D STED objective with 300 microns working distance (Fig. 1 D-J). Wide areas could be imaged over the cerebellum using tile 3D imaging with a 20x glycerol objective (Fig. 1L, M) that could be correlated to confocal (Fig. 1N, O) and 3D STED imaging (Fig. 1P, Q) at higher magnification (93x). As shown in Fig. 1, Purkinje cells are exquisitely packed in undulating layers, and dendritic trees can be inferred from conventional confocal microscopy. However, dendritic spines can be resolved more efficiently using 3D STED microscopy (Fig. 1P, Q and Supplementary Movie 1). Because cell and spine densities are high, manual segmentation would be quite time consuming and prone to human bias. Automatic segmentation using conventional thresholding method is not really efficient, since local intensity within Purkinje cells is quite different (Fig. 1P): dendritic trunk intensity is very high (yellow), whereas spine heads have moderate intensity (pink) and spine necks are pretty dark (deep purple). We thus designed the SENPAI pipeline to meet these biological and technical challenges.

## General workflow of SENPAI: step 1—segmentation

SENPAI is developed as a two-step automated workflow for reconstructing neuron morphology starting from 3D optical images (Fig. 2).

As intensity variations are very high in Purkinje cells, we choose to use model-independent topological information. The segmentation strategy in SENPAI consists of a K-means clustering of the image dataset in a 4-dimensional feature space defined by the intensity and the three second derivatives of the image intensity computed along the three main spatial axes (Fig. 2B). Six clusters, or classes of voxels are thus automatically identified and sorted by assigning numeric labels based on the average image intensity within each class, starting from the lowest (class 1) (Fig. 2C). The clusters are then automatically labeled as neuronal structure or background, based on their feature values. The way the image space is subdivided highlights inner and outer borders along the three main directions (Fig. 2D). Neuronal shape correlates with highest average image intensity classes that present negative values for the averages of the three second derivatives (Fig. 2B, C). However, thanks to the use of spatial derivatives, all classes span large intensity ranges: neuronal classes, despite showing high intensity values on average, are thus able to include low-intensity image regions; similarly, non-neuronal classes, despite showing low average intensity, also include high-intensity background regions (see Supplementary Fig. 1). This subdivision was observed to be stable across tests performed on different images (see Supplementary Fig. 1). 3D Gaussian image smoothing with user-defined size can be applied to modulate the values of the second-order derivatives. As the clustering can be focused on different levels of detail, it allows highlighting structures at different scales. This guarantees SENPAI's scalability and versatility since a final multiscale result can be obtained by merging two segmentations after applying different levels of smoothing to the original image (Fig. 2D).

## General workflow of SENPAI: step 2—parcellation

On datasets representing entire neuronal populations, branches belonging to different cells are close to one another (Fig. 1N-Q) and thus not discernible. As a result, segmentation algorithms may fail in isolating single neurons, or may succeed, but at the cost of providing more conservative (i.e., poor) segmentations. Similarly, in higher-resolution datasets, when the goal is to study spine shape and density, the difficulty of segmenting spine necks impairs the assignation of the spine to the corresponding dendrite. To overcome these issues, we included a second parcellation step in SENPAI based on the use of

morphological reconstruction and on the application of the watershed transform.

Morphological reconstruction is an iterative image transformation technique used to smooth out some less relevant local maxima or minima⁴⁶, while the watershed transform is employed to subdivide the image space into regions assigned to objects having outstanding intensity with respect to the background⁵⁰. For each neuronal core, i.e., the most discernable portion of an imaged neuron, we define a single well (via morphological reconstruction) and an associated catchment basin employing a watershed transform. A different label is associated with each catchment basin to compose the parcellation process. When applied to isolate single neurons, i.e., to separate merged structures, neuronal cores can be easily defined by marking the soma or the thickest arbor observable for each neuron. On the other hand, when applied to merge unconnected structures, such as spines and their corresponding dendrite, the neuronal core consists of the dendrite branch (Fig. 2E).

## Comparison with other segmentation or tracing algorithms

Confocal images of cleared mouse brain tissue samples (see Methods and Figs. 1–2) were used to compare the segmentation of neurons obtained using SENPAI with those performed with four state-of-the-art algorithms, namely, the automatic HK-Means segmentation plugin⁵¹ included in the software Icy⁵² (hereinafter HK-Icy), the semi-automatic tracing software NeuroGPS³⁵, the semi-automatic segmentation software Ilastik³³ and the semi-automatic tracing software NeuTube⁵⁴. When single neuron identification failed with a specific algorithm, we parcellated its outcome using the step 2 of the SENPAI workflow to provide a reconstruction comparable with the others. The example in Fig. 3 shows how neuron segmentations performed by SENPAI and HK-Icy result in a notably denser and more intricate outcomes than those from NeuTube and NeuroGPS, while Ilastik provides richer segmentations whose complexity lies in between. We also report the 27 single-neuron reconstructions obtained with SENPAI and the state-of-the-art tools and used to test and validate SENPAI in Supplementary Figs. 2, 3 and 4.

We also compared the segmentation performance of SENPAI, HK-Icy, Ilastik, NeuroGPS and NeuTube in terms of the area under the curve (AUC) obtained through Sholl analysis, a method used to quantify dendritic structure⁵⁵ (see Fig. 4A). SENPAI, HK-Icy and Ilastik show significantly higher values with respect to Neutube and NeuroGPS (Friedman test, *p* < 10⁻¹⁶, and post-hoc comparisons with Tukey's honest significant difference criterion, *p* < 10⁻², Fig. 4B, right) indicating a higher sensitivity to complex dendritic arbor detection. Additionally, we compared the area-to-volume ratio of the segmentations provided by SENPAI, HK-icy and Ilastik (Fig. 4B, left). It should be noted that this index cannot be extracted for NeuroGPS and NeuTube, since they do not provide volumetric information. While HK-Icy and Ilastik show similar values, SENPAI provides significantly higher area-over-volume ratios (Friedman test, *p* < 10⁻⁸, and post-hoc comparisons with Tukey's honest significant difference criterion, *p* < 10⁻⁵).

## Comparison against documented information on Purkinje cell morphometrics

Purkinje neurons branch extensively and almost completely fill spaces with little overlap⁵⁶. They have been reconstructed using tools such as NeuroMorpho.org⁵⁷ from public repositories of single injected neurons³⁸,⁵⁹ and several parameters have been used in the literature to describe their morphology. The availability of summary statistics describing the topology and morphology of neuronal populations allows for the validation of new reconstructions when the ground truth for the specific sample is lacking or the manual gold standard cannot be obtained due to high density neuronal packing. Vormberg and co-authors⁴⁷ described the topological and morphological properties of six types of neurons (including Purkinje cells) by means of the
stage and sample flatness. Thus, to optimize sample flatness and working distance objective, we carefully designed custom-made spacers of calibrated thickness (300 microns thick PVC sheets) allowing light penetration directly into the samples without passing through thick mounting media layers. Using this device, glass coverslips were sealed parallel to the slice surface, allowing deep imaging using 93x 3D STED objective with 300 microns working distance (Fig. 1 D-J). Wide areas could be imaged over the cerebellum using tile 3D imaging with a 20x glycerol objective (Fig. 1L, M) that could be correlated to confocal (Fig. 1N, O) and 3D STED imaging (Fig. 1P, Q) at higher magnification (93x). As shown in Fig. 1, Purkinje cells are exquisitely packed in undulating layers, and dendritic trees can be inferred from conventional confocal microscopy. However, dendritic spines can be resolved more efficiently using 3D STED microscopy (Fig. 1P, Q and Supplementary Movie 1). Because cell and spine densities are high, manual segmentation would be quite time consuming and prone to human bias. Automatic segmentation using conventional thresholding method is not really efficient, since local intensity within Purkinje cells is quite different (Fig. 1P): dendritic trunk intensity is very high (yellow), whereas spine heads have moderate intensity (pink) and spine necks are pretty dark (deep purple). We thus designed the SENPAI pipeline to meet these biological and technical challenges.

## General workflow of SENPAI: step 1—segmentation

SENPAI is developed as a two-step automated workflow for reconstructing neuron morphology starting from 3D optical images (Fig. 2).

As intensity variations are very high in Purkinje cells, we choose to use model-independent topological information. The segmentation strategy in SENPAI consists of a K-means clustering of the image dataset in a 4-dimensional feature space defined by the intensity and the three second derivatives of the image intensity computed along the three main spatial axes (Fig. 2B). Six clusters, or classes of voxels are thus automatically identified and sorted by assigning numeric labels based on the average image intensity within each class, starting from the lowest (class 1) (Fig. 2C). The clusters are then automatically labeled as neuronal structure or background, based on their feature values. The way the image space is subdivided highlights inner and outer borders along the three main directions (Fig. 2D). Neuronal shape correlates with highest average image intensity classes that present negative values for the averages of the three second derivatives (Fig. 2B, C). However, thanks to the use of spatial derivatives, all classes span large intensity ranges: neuronal classes, despite showing high intensity values on average, are thus able to include low-intensity image regions; similarly, non-neuronal classes, despite showing low average intensity, also include high-intensity background regions (see Supplementary Fig. 1). This subdivision was observed to be stable across tests performed on different images (see Supplementary Fig. 1). 3D Gaussian image smoothing with user-defined size can be applied to modulate the values of the second-order derivatives. As the clustering can be focused on different levels of detail, it allows highlighting structures at different scales. This guarantees SENPAI's scalability and versatility since a final multiscale result can be obtained by merging two segmentations after applying different levels of smoothing to the original image (Fig. 2D).

## General workflow of SENPAI: step 2—parcellation

On datasets representing entire neuronal populations, branches belonging to different cells are close to one another (Fig. 1N-Q) and thus not discernible. As a result, segmentation algorithms may fail in isolating single neurons, or may succeed, but at the cost of providing more conservative (i.e., poor) segmentations. Similarly, in higher-resolution datasets, when the goal is to study spine shape and density, the difficulty of segmenting spine necks impairs the assignation of the spine to the corresponding dendrite. To overcome these issues, we included a second parcellation step in SENPAI based on the use of

morphological reconstruction and on the application of the watershed transform.

Morphological reconstruction is an iterative image transformation technique used to smooth out some less relevant local maxima or minima⁴⁶, while the watershed transform is employed to subdivide the image space into regions assigned to objects having outstanding intensity with respect to the background⁵⁰. For each neuronal core, i.e., the most discernable portion of an imaged neuron, we define a single well (via morphological reconstruction) and an associated catchment basin employing a watershed transform. A different label is associated with each catchment basin to compose the parcellation process. When applied to isolate single neurons, i.e., to separate merged structures, neuronal cores can be easily defined by marking the soma or the thickest arbor observable for each neuron. On the other hand, when applied to merge unconnected structures, such as spines and their corresponding dendrite, the neuronal core consists of the dendrite branch (Fig. 2E).

## Comparison with other segmentation or tracing algorithms

Confocal images of cleared mouse brain tissue samples (see Methods and Figs. 1–2) were used to compare the segmentation of neurons obtained using SENPAI with those performed with four state-of-the-art algorithms, namely, the automatic HK-Means segmentation plugin⁵¹ included in the software Icy⁵² (hereinafter HK-Icy), the semi-automatic tracing software NeuroGPS³⁵, the semi-automatic segmentation software Ilastik³³ and the semi-automatic tracing software NeuTube⁵⁴. When single neuron identification failed with a specific algorithm, we parcellated its outcome using the step 2 of the SENPAI workflow to provide a reconstruction comparable with the others. The example in Fig. 3 shows how neuron segmentations performed by SENPAI and HK-Icy result in a notably denser and more intricate outcomes than those from NeuTube and NeuroGPS, while Ilastik provides richer segmentations whose complexity lies in between. We also report the 27 single-neuron reconstructions obtained with SENPAI and the state-of-the-art tools and used to test and validate SENPAI in Supplementary Figs. 2, 3 and 4.

We also compared the segmentation performance of SENPAI, HK-Icy, Ilastik, NeuroGPS and NeuTube in terms of the area under the curve (AUC) obtained through Sholl analysis, a method used to quantify dendritic structure⁵⁵ (see Fig. 4A). SENPAI, HK-Icy and Ilastik show significantly higher values with respect to Neutube and NeuroGPS (Friedman test, *p* < 10⁻¹⁶, and post-hoc comparisons with Tukey's honest significant difference criterion, *p* < 10⁻², Fig. 4B, right) indicating a higher sensitivity to complex dendritic arbor detection. Additionally, we compared the area-to-volume ratio of the segmentations provided by SENPAI, HK-icy and Ilastik (Fig. 4B, left). It should be noted that this index cannot be extracted for NeuroGPS and NeuTube, since they do not provide volumetric information. While HK-Icy and Ilastik show similar values, SENPAI provides significantly higher area-over-volume ratios (Friedman test, *p* < 10⁻⁸, and post-hoc comparisons with Tukey's honest significant difference criterion, *p* < 10⁻⁵).

## Comparison against documented information on Purkinje cell morphometrics

Purkinje neurons branch extensively and almost completely fill spaces with little overlap⁵⁶. They have been reconstructed using tools such as NeuroMorpho.org⁵⁷ from public repositories of single injected neurons³⁸,⁵⁹ and several parameters have been used in the literature to describe their morphology. The availability of summary statistics describing the topology and morphology of neuronal populations allows for the validation of new reconstructions when the ground truth for the specific sample is lacking or the manual gold standard cannot be obtained due to high density neuronal packing. Vormberg and co-authors⁴⁷ described the topological and morphological properties of six types of neurons (including Purkinje cells) by means of the
<figure><img src="image_7.png" /><figcaption>**Fig. 2** | **The SENPAI algorithm.** A Test datasets: 40x confocal (left) and 93x STED (right). SENPAI was tested on cleared samples using confocal 40x (27 neurons) and 93x STED (5 neuron branches) datasets. B The SENPAI rationale, based on the selection of classes displaying negative values of the second derivative along the three main axes. C Rationale for the estimation of the K parameter of the K-means clustering: the selected K is the one for which the histograms of second-order derivatives show three different classes achieving maximal average value: here, from the histogram of $D^2x$ (second derivative along the x axis), class 3 (cyan) encodes outer borders along the x direction, as it is the only class with values clearly above 0; similarly, class 4 encodes outer borders along the y direction ($D^2y$ histogram); class 2 along the z direction ($D^2z$ histogram); class 1 encodes both low- and high-intensity homogeneous image portions, and is labeled as background along with classes 2, 3 and 4. D SENPAI workflow-Step 1: K-means clustering, performed on the unsmoothed image (top) and optionally, in parallel, on the image smoothed</figcaption></figure>

with a 3D Gaussian filter (below). Class selection is performed independently on K-means classes (color-coded as in (C) for each clustering level). Resulting binarized images (green for clustering level 1, pink for clustering level 2, white for the overlap) are merged by logic OR. E SENPAI workflow-Step 2 for neuron separation: the segmented image is parcellated using morphological reconstruction and 3D watershed transform computed on the morphologically reconstructed grayscale image and applied to the binary segmentation. Left: raw image; Right: isolation of connected structures belonging to the same neuron; soma markers (yellow, placed by user) define wells for the catchment basins (edges in gray). F SENPAI workflow-Step 2 applied to spine assignation. Left: raw image; Middle: 3D rendering; Left: 2D rendering of the parcellation with the connection of a neuronal portion (e.g., a dendrite branch) to smaller clusters (i.e., dendritic spines). Groups of neuronal clusters assigned to a single neuronal entity are displayed in different colors in their relative catchment basin (gray).

centripetal Horton-Strahler ordering (SO, see Fig. 5A). This is a well-known index of branching complexity, which accounts for nine different parameters. These include: (i) Strahler Number (SN), i.e., the maximal SO assigned to a segment in the neuronal tree. A further four topological parameters are defined: (ii) Normalized Number of

Segments per SO, (iii) Normalized Number of Branches per SO, (iv) Branch Bifurcation Ratio, (v) Normalized Topological Subtree Size per SO. The final four metric parameters are: (vi) Normalized Branch Diameter per SO, (vii) Total Normalized Dendritic Length per SO, (viii) Normalized Average Segment Length per SO, and (ix) Normalized
<figure><img src="image_6.png" /><figcaption>B Rationale: use of derivatives</figcaption></figure>

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

1) Intensity profile along a cross-section of a dendritic branch with smooth transitions at the borders.

2) The first derivative is direction-dependent.

3) The second derivative encodes all the inner edges of the transition with negative values.

<figure><img src="image_8.png" /><figcaption>D 3D Segmentation</figcaption></figure>

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

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

CLASS SELECTION

3 classes encoding outer borders along the 3 axes are discarded, together with lower-intensity classes

<figure><img src="image_11.png" /><figcaption>E 3D Parcellation: neuron separation on standard resolution 40x</figcaption></figure>

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

<figure><img src="image_13.png" /><figcaption>F 3D Parcellation: spine assignation on high resolution 93x</figcaption></figure>

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

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

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

**Fig. 2** | **The SENPAI algorithm.** A Test datasets: 40x confocal (left) and 93x STED (right). SENPAI was tested on cleared samples using confocal 40x (27 neurons) and 93x STED (5 neuron branches) datasets. B The SENPAI rationale, based on the selection of classes displaying negative values of the second derivative along the three main axes. C Rationale for the estimation of the K parameter of the K-means clustering: the selected K is the one for which the histograms of second-order derivatives show three different classes achieving maximal average value: here, from the histogram of D²x (second derivative along the x axis), class 3 (cyan) encodes outer borders along the x direction, as it is the only class with values clearly above 0; similarly, class 4 encodes outer borders along the y direction (D²y histogram); class 2 along the z direction (D²z histogram); class 1 encodes both low-and high-intensity homogeneous image portions, and is labeled as background along with classes 2, 3 and 4. D SENPAI workflow-Step 1: K-means clustering, performed on the unsmoothed image (top) and optionally, in parallel, on the image smoothed

with a 3D Gaussian filter (below). Class selection is performed independently on K-means classes (color-coded as in (C) for each clustering level). Resulting binarized images (green for clustering level 1, pink for clustering level 2, white for the overlap) are merged by logic OR. E SENPAI workflow-Step 2 for neuron separation: the segmented image is parcellated using morphological reconstruction and 3D watershed transform computed on the morphologically reconstructed grayscale image and applied to the binary segmentation. Left: raw image; Right: isolation of connected structures belonging to the same neuron; soma markers (yellow, placed by user) define wells for the catchment basins (edges in gray). F SENPAI workflow-Step 2 applied to spine assignation. Left: raw image; Middle: 3D rendering; Left: 2D rendering of the parcellation with the connection of a neuronal portion (e.g., a dendrite branch) to smaller clusters (i.e., dendritic spines). Groups of neuronal clusters assigned to a single neuronal entity are displayed in different colors in their relative catchment basin (gray).

centripetal Horton-Strahler ordering (SO, see Fig. 5A). This is a well-known index of branching complexity, which accounts for nine different parameters. These include: (i) Strahler Number (SN), i.e., the maximal SO assigned to a segment in the neuronal tree. A further four topological parameters are defined: (ii) Normalized Number of

Segments per SO, (iii) Normalized Number of Branches per SO, (iv) Branch Bifurcation Ratio, (v) Normalized Topological Subtree Size per SO. The final four metric parameters are: (vi) Normalized Branch Diameter per SO, (vii) Total Normalized Dendritic Length per SO, (viii) Normalized Average Segment Length per SO, and (ix) Normalized
<figure><img src="image_8.png" /><figcaption>**Fig. 3 |** 3D visualization of the original confocal dataset and comparison of the performance of the algorithms tested against SENPAI. Dataset acquired with a confocal microscope equipped with a 40x objective (details in Methods). All images are produced with the Icy GUI. Tracings are converted to volumetric segmentations</figcaption></figure>

with the SWC2IMG ImageJ plugin<sup>87</sup>. The same 10 neighboring neurons and one exemplary single neuron are depicted using the same color code for all tools. A further example is depicted within a 3D rendering of the original image in Supplementary Movie 2.

Average Branch Length per SO. While topological parameters are universal to binary tree-like structures, metric parameters can be used to differentiate cell types. For example, total dendritic length reveals the dimensionality of dendritic trees, with shallow slopes for planar trees, e.g., as in Purkinje cells, and pronounced slopes for 3D trees.

Using an ad hoc script developed in Matlab (see Methods) (Fig. 5B), we extracted the SO for skeletonized neurons obtained from

SENPAI, HK-Icy, NeuroGPS, NeuTube and Ilastik. The SOs were compared with those obtained by Vormberg et al. for Purkinje cells. The results are shown in Fig. 5C and detailed in the Supplementary Information (Supplementary Table 2).

SENPAI and HK-Icy achieved segmentations with the same SN mode as that identified by Vormberg et al. for Purkinje cells, with SENPAI scoring more hits. All measures reported in Fig. 5C show that
<figure><img src="image_17.png" /><figcaption>**Fig. 3** | 3D visualization of the original confocal dataset and comparison of the performance of the algorithms tested against SENPAI. Dataset acquired with a confocal microscope equipped with a 40x objective (details in Methods). All images are produced with the Icy GUI. Tracings are converted to volumetric segmentations</figcaption></figure>

with the SWC2IMG ImageJ plugin<sup>87</sup>. The same 10 neighboring neurons and one exemplary single neuron are depicted using the same color code for all tools. A further example is depicted within a 3D rendering of the original image in Supplementary Movie 2.

Average Branch Length per SO. While topological parameters are universal to binary tree-like structures, metric parameters can be used to differentiate cell types. For example, total dendritic length reveals the dimensionality of dendritic trees, with shallow slopes for planar trees, e.g., as in Purkinje cells, and pronounced slopes for 3D trees.

Using an ad hoc script developed in Matlab (see Methods) (Fig. 5B), we extracted the SO for skeletonized neurons obtained from

SENPAI, HK-Icy, NeuroGPS, NeuTube and Ilastik. The SOs were compared with those obtained by Vormberg et al. for Purkinje cells. The results are shown in Fig. 5C and detailed in the Supplementary Information (Supplementary Table 2).

SENPAI and HK-Icy achieved segmentations with the same SN mode as that identified by Vormberg et al. for Purkinje cells, with SENPAI scoring more hits. All measures reported in Fig. 5C show that
A Area under the Sholl curve

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

Sphere radius

Counting of dendritic
intersections for a 3D
sphere centered on the
root node with increasing
radius

B 40x statistics

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

AUC of Sholl analysis

<figure><img src="image_11.png" /><figcaption>**Fig. 4 | Quantitative comparison of the segmentations on 40x images.**</figcaption></figure>

A Schematization of the rationale behind 3D Sholl Analysis: we compute the Area Under the Curve (AUC) for the number of crossings of each neuronal structure for a sphere with increasing radius centered on the root node (i.e., the soma centroid); B Quantitative comparison for segmentations from 27 neurons on 40x images; left: Area-Volume ratio for SENPAI (magenta), HK-Icy (blue) and Ilastik (green) (two-sided Friedman test, *p* = 1.02 * 10⁻⁹, horizontal bars mark significant differences as

determined with post-hoc comparison using Tukey's honest significant criterion, *p* < 10⁻⁵); right: AUC of the Sholl analysis across segmentations obtained with SENPAI (magenta), HK-Icy (blue), Ilastik (green), NeuroGPS (red) and NeuTube (gray), (two-sided Friedman test, *p* = 6.81 * 10⁻¹⁷, horizontal bars mark significant differences as determined with post-hoc comparison using Tukey's honest sig- nificant criterion, *p* < 10⁻²). Source data are provided as a Source Data file.

the segmentations obtained with HK-Icy and SENPAI have similar
metrics to those described in Vormberg et al., while the results
obtained with NeuTube and NeuroGPS differ. Ilastik achieved a lower
SN mode (5), although results are close to those of HK-Icy and SENPAI.
In addition, SENPAI outperforms the other algorithms matching the
steepest decay for the normalized number of segments (slope = -1.23)
found for Purkinje cells in the reference work and presenting smaller
deviations in the curves of subtree size and total dendritic length.

Comparison with other algorithms in the segmentation of
super-resolution datasets

In addition to the confocal 40x datasets, we also applied SENPAI to
L7GFP cleared mouse cerebellum slices imaged with a LEICA SP8 STED
3DX equipped with a 93x objective (see Methods), again comparing its
performance with state-of-the-art tools (HK-Icy and the automatic
segmentation algorithm Ilastik⁵³) and ground-truth manual segmen-
tation (obtained via the ManSegTool⁶⁰). The resulting segmentations
of five dendritic branches in the STED dataset are reported in Fig. 6.

Further analyses were performed to compare the branch areas
and volumes obtained from the automatic tools with those obtained
with the manual segmentation. We observed consistent differences
between SENPAI and HK-Icy and Ilastik. Specifically, while Ilastik
delivers volumes (Fig. 6B, left) that are significantly larger than those
from the manual segmentations (volume normalized with respect to
the ground-truth, median ± median absolute deviation (MAD) 1.91 ±
1.08) along with consistently larger area estimates, (area normalized
with respect to the ground-truth, median±MAD 1.45 ± 0.42), SENPAI
and HK-Icy's outcomes are very close to ManSegTool's (SENPAI area
median±MAD 0.88 ± 0.30, SENPAI volume median±MAD 0.86 ± 0.49,
HK-Icy area median±MAD 0.83 ± 1.00, HK-Icy volume median±MAD
0.75 ± 1.13). Particularly relevant is the analysis based on the Dice
coefficient⁶¹ (Fig. 6C), which quantifies the similarity between shapes
(ideal = 1). Considering the whole dendritic branches, SENPAI
achieves the highest Dice values for all the five of them, while Ilastik
performs worst for all dendritic branches but one (SENPAI Dice
median±MAD 0.81 ± 0.02, HK-Icy Dice median±MAD 0.78 ± 0.11,
A Area under the Sholl curve

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

Sphere radius

Counting of dendritic
intersections for a 3D
sphere centered on the
root node with increasing
radius

B 40x statistics

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

AUC of Sholl analysis

<figure><img src="image_20.png" /><figcaption>Fig. 4 | Quantitative comparison of the segmentations on 40x images.</figcaption></figure>

A Schematization of the rationale behind 3D Sholl Analysis: we compute the Area Under the Curve (AUC) for the number of crossings of each neuronal structure for a sphere with increasing radius centered on the root node (i.e., the soma centroid); B Quantitative comparison for segmentations from 27 neurons on 40x images; left: Area-Volume ratio for SENPAI (magenta), HK-Icy (blue) and Ilastik (green) (two-sided Friedman test, *p* = 1.02 * 10⁻⁹, horizontal bars mark significant differences as

determined with post-hoc comparison using Tukey's honest significant criterion, *p* < 10⁻⁵); right: AUC of the Sholl analysis across segmentations obtained with SENPAI (magenta), HK-Icy (blue), Ilastik (green), NeuroGPS (red) and NeuTube (gray), (two-sided Friedman test, *p* = 6.81 * 10⁻¹⁷, horizontal bars mark significant differences as determined with post-hoc comparison using Tukey's honest sig- nificant criterion, *p* < 10⁻²). Source data are provided as a Source Data file.

the segmentations obtained with HK-Icy and SENPAI have similar
metrics to those described in Vormberg et al., while the results
obtained with NeuTube and NeuroGPS differ. Ilastik achieved a lower
SN mode (5), although results are close to those of HK-Icy and SENPAI.
In addition, SENPAI outperforms the other algorithms matching the
steepest decay for the normalized number of segments (slope = -1.23)
found for Purkinje cells in the reference work and presenting smaller
deviations in the curves of subtree size and total dendritic length.

Comparison with other algorithms in the segmentation of
super-resolution datasets

In addition to the confocal 40x datasets, we also applied SENPAI to
L7GFP cleared mouse cerebellum slices imaged with a LEICA SP8 STED
3DX equipped with a 93x objective (see Methods), again comparing its
performance with state-of-the-art tools (HK-Icy and the automatic
segmentation algorithm Ilastik⁵³) and ground-truth manual segmen-
tation (obtained via the ManSegTool⁶⁰). The resulting segmentations
of five dendritic branches in the STED dataset are reported in Fig. 6.

Further analyses were performed to compare the branch areas
and volumes obtained from the automatic tools with those obtained
with the manual segmentation. We observed consistent differences
between SENPAI and HK-Icy and Ilastik. Specifically, while Ilastik
delivers volumes (Fig. 6B, left) that are significantly larger than those
from the manual segmentations (volume normalized with respect to
the ground-truth, median ± median absolute deviation (MAD) 1.91 ±
1.08) along with consistently larger area estimates, (area normalized
with respect to the ground-truth, median±MAD 1.45 ± 0.42), SENPAI
and HK-Icy's outcomes are very close to ManSegTool's (SENPAI area
median±MAD 0.88 ± 0.30, SENPAI volume median±MAD 0.86 ± 0.49,
HK-Icy area median±MAD 0.83 ± 1.00, HK-Icy volume median±MAD
0.75 ± 1.13). Particularly relevant is the analysis based on the Dice
coefficient⁶¹ (Fig. 6C), which quantifies the similarity between shapes
(ideal = 1). Considering the whole dendritic branches, SENPAI
achieves the highest Dice values for all the five of them, while Ilastik
performs worst for all dendritic branches but one (SENPAI Dice
median±MAD 0.81 ± 0.02, HK-Icy Dice median±MAD 0.78 ± 0.11,
<figure><img src="image_12.png" /><figcaption>**Fig. 5** | Comparison against documented information on Purkinje cell morphometrics, based on Strahler Ordering. A Schematization of SO and of the meaning of some of the extracted features; B Schematization of the validation pipeline; C Graphical comparison of the SO of Purkinje cells found in the literature and measured on the neurons segmented with SENPAI and the state-of-the-art tools. The parameters based on the SO reported by Vormberg et al. on six types of</figcaption></figure>

neuronal cells (left, edited from Vormberg et al.) and computed on 27 Purkinje neurons segmented with SENPAI (magenta), HK-Icy (blue), Ilastik (green), NeuroGPS (red) and NeuTube (gray) from 40x images (right). It should be noted that the parameters, with the exception of the Branch Bifurcation Ratio, were computed only for neurons whose SN was equal to their mode, in line with Vormberg et al. Source data are provided as a Source Data file.

Ilastik Dice median±MAD 0.68 ± 0.05). We performed the same analysis with a focus on spines, excluding those voxels that were labeled as belonging to the dendrite by manual segmentation. To avoid bias introduced by oversegmentation of the dendrite, we repeated

the analysis recursively dilating the dendrite mask. All points are reported in Fig. 6C (bottom). SENPAI performs best again and is matched only for dendrite Ne by HK-Icy (for the first iteration, SENPAI Dice median±MAD 0.64 ± 0.07, HK-Icy Dice median±MAD
<figure><img src="image_21.png" /><figcaption>**Fig. 5** | Comparison against documented information on Purkinje cell morphometrics, based on Strahler Ordering. A Schematization of SO and of the meaning of some of the extracted features; B Schematization of the validation pipeline; C Graphical comparison of the SO of Purkinje cells found in the literature and measured on the neurons segmented with SENPAI and the state-of-the-art tools. The parameters based on the SO reported by Vormberg et al. on six types of</figcaption></figure>

neuronal cells (left, edited from Vormberg et al.) and computed on 27 Purkinje neurons segmented with SENPAI (magenta), HK-Icy (blue), Ilastik (green), NeuroGPS (red) and NeuTube (gray) from 40x images (right). It should be noted that the parameters, with the exception of the Branch Bifurcation Ratio, were computed only for neurons whose SN was equal to their mode, in line with Vormberg et al. Source data are provided as a Source Data file.

Ilastik Dice median±MAD 0.68±0.05). We performed the same analysis with a focus on spines, excluding those voxels that were labeled as belonging to the dendrite by manual segmentation. To avoid bias introduced by oversegmentation of the dendrite, we repeated

the analysis recursively dilating the dendrite mask. All points are reported in Fig. 6C (bottom). SENPAI performs best again and is matched only for dendrite Ne by HK-Icy (for the first iteration, SENPAI Dice median±MAD 0.64±0.07, HK-Icy Dice median±MAD
<figure><img src="image_13.png" /><figcaption>B 93x statistics: Area and Volume</figcaption></figure>

<figure><img src="image_14.png" /><figcaption>C 93x statistics: Dice Analysis</figcaption></figure>

<figure><img src="image_15.png" /><figcaption>D 93x spine count</figcaption></figure>

<table><thead><tr><th rowspan="2"></th><th rowspan="2">Manually<br>detected<br>spines</th><th colspan="5">SENPAI</th><th colspan="5">HK-Icy</th><th colspan="5">Ilastik</th></tr><tr><th>FP</th><th>FN</th><th>TP</th><th>S%</th><th>P%</th><th>FP</th><th>FN</th><th>TP</th><th>S%</th><th>P%</th><th>FP</th><th>FN</th><th>TP</th><th>S%</th><th>P%</th></tr></thead><tbody><tr><th>Na</th><td>111</td><td>13</td><td>8</td><td>103</td><td>93</td><td>89</td><td>10</td><td>79</td><td>32</td><td>39</td><td>70</td><td>22</td><td>3</td><td>108</td><td>97</td><td>83</td></tr><tr><th>Nb</th><td>48</td><td>3</td><td>4</td><td>48</td><td>91</td><td>94</td><td>4</td><td>8</td><td>48</td><td>82</td><td>90</td><td>5</td><td>4</td><td>48</td><td>92</td><td>91</td></tr><tr><th>Nc</th><td>53</td><td>5</td><td>2</td><td>53</td><td>96</td><td>91</td><td>17</td><td>9</td><td>53</td><td>79</td><td>66</td><td>21</td><td>1</td><td>53</td><td>98</td><td>72</td></tr><tr><th>Nd</th><td>20</td><td>0</td><td>2</td><td>18</td><td>91</td><td>100</td><td>2</td><td>0</td><td>20</td><td>100</td><td>90</td><td>4</td><td>0</td><td>20</td><td>100</td><td>83</td></tr><tr><th>Ne</th><td>21</td><td>3</td><td>0</td><td>21</td><td>100</td><td>88</td><td>6</td><td>8</td><td>21</td><td>62</td><td>68</td><td>6</td><td>0</td><td>21</td><td>100</td><td>78</td></tr><tr><th>Mean</th><td></td><td></td><td></td><td></td><td></td><td>94</td><td>92</td><td></td><td></td><td></td><td>74</td><td>82</td><td></td><td></td><td></td><td>98</td><td>81</td></tr></tbody></table>

**Fig. 6 | Segmentations of 5 dendritic branches—Na to Ne—and their localization within a 3D multistack 93x STED dataset.** A Left: the dendritic branches Na to Ne contained within a single stack and employed here for the validation of SENPAI are highlighted in red. Right: we compare the segmentations obtained with the state-of-the-art algorithms. The segmentations were performed with SENPAI, HK-Icy, Ilastik and manual segmentation by ManSegTool. Algorithm segmentations of the whole image are underlaid in gray, while the parcellation outcomes are highlighted in red. B Quantitative comparison for the segmentations of the 5 dendritic branches; volume and area obtained with SENPAI, Ilastik and HK-Icy. The values are normalized with respect to manual segmentations. HK-Icy and Ilastik were integrated with the SENPAI parcellation step to, respectively, assign spines to the dendrite and separate touching dendrites from each other (volume result showed significant differences; Friedman *p* = 0.015; post-hoc with Conover's test highlighted Ilastik

difference to both SENPAI and HK-Icy, *p* < 0.01, highlighted with gray bars).

C Quantitative comparison of the segmentations of the dendritic branches; the Dice coefficient was used to compare the segmentations obtained with the algorithms against the manual segmentation, considering the whole neuron (top) and the only spines (bottom). An ideal algorithm would give a Dice coefficient of 1. The analysis on the spines was conducted by masking out the manual segmentation of the dendrite (both whole neuron and average spine Dice coefficients from SENPAI were different to both Ilastik and HK-Icy; Friedman tests *p* = 0.015; post-hoc with Conover's tests, *p* < 0.01). D Table summarizing algorithm performance in terms of spine detection. Spines were counted in the manual segmentation, then we defined False Positives (FP) and False Negatives (FN), True Positives (TP), the Sensitivity (S% = % of TP over TP + FN) and the Precision (P% = % of TP over TP + FP) for SENPAI, HK-Icy and Ilastik. Source data are provided as a Source Data file.

0.50 ± 0.14, Ilastik Dice median ± MAD 0.43 ± 0.10). Merging the information in Fig. 6C, Ilastik clearly oversegments while HK-Icy undersegments.

Spine-by-spine reconstructions obtained with SENPAI, Ilastik and HK-Icy with the manual segmentation were also compared and reported in Fig. 6D. For each of the three algorithms we counted the number of true positives, false positives and false negatives and estimated specificity and precision in spine detection. Due to higher false negatives, SENPAI gives slightly lower specificity with respect to Ilastik, but performs best in terms of precision. On average, SENPAI is better than HK-Icy on all topological and morphological metrics and performs better than Ilastik in terms of morphological reconstruction and number of false positives.

## Generalization to other neuron types and imaging modalities

To support the generalizability of the SENPAI pipeline, we tested the algorithm on multiple neuron types from different species (rat, mouse and human) and in different conditions (tissues and cultured cells, in uncleared samples and acquired with different imaging modalities—see Supplementary Information). The neuron types we segmented include human pyramidal neurons, mouse and rat pyramidal neurons, human cultured excitatory neurons, mouse cultured excitatory neurons, and mouse retinal neurons. The imaging modalities, other than confocal and confocal STED, include two-photon (2P) microscopy. We report both quantitative and qualitative evaluations, that attest to the generalizability of our reconstruction algorithm across different imaging modalities and neuron types.
<figure><img src="image_22.png" /><figcaption>B 93x statistics: Area and Volume</figcaption></figure>

<figure><img src="image_23.png" /><figcaption>C 93x statistics: Dice Analysis</figcaption></figure>

<figure><img src="image_24.png" /><figcaption>D 93x spine count</figcaption></figure>

<table><thead><tr><th rowspan="2"></th><th rowspan="2">Manually<br>detected<br>spines</th><th colspan="5">SENPAI</th><th colspan="5">HK-Icy</th><th colspan="5">Ilastik</th></tr><tr><th>FP</th><th>FN</th><th>TP</th><th>S%</th><th>P%</th><th>FP</th><th>FN</th><th>TP</th><th>S%</th><th>P%</th><th>FP</th><th>FN</th><th>TP</th><th>S%</th><th>P%</th></tr></thead><tbody><tr><th>Na</th><td>111</td><td>13</td><td>8</td><td>103</td><td>93</td><td>89</td><td>10</td><td>79</td><td>32</td><td>39</td><td>70</td><td>22</td><td>3</td><td>108</td><td>97</td><td>83</td></tr><tr><th>Nb</th><td>48</td><td>3</td><td>4</td><td>48</td><td>91</td><td>94</td><td>4</td><td>8</td><td>48</td><td>82</td><td>90</td><td>5</td><td>4</td><td>48</td><td>92</td><td>91</td></tr><tr><th>Nc</th><td>53</td><td>5</td><td>2</td><td>53</td><td>96</td><td>91</td><td>17</td><td>9</td><td>53</td><td>79</td><td>66</td><td>21</td><td>1</td><td>53</td><td>98</td><td>72</td></tr><tr><th>Nd</th><td>20</td><td>0</td><td>2</td><td>18</td><td>91</td><td>100</td><td>2</td><td>0</td><td>20</td><td>100</td><td>90</td><td>4</td><td>0</td><td>20</td><td>100</td><td>83</td></tr><tr><th>Ne</th><td>21</td><td>3</td><td>0</td><td>21</td><td>100</td><td>88</td><td>6</td><td>8</td><td>21</td><td>62</td><td>68</td><td>6</td><td>0</td><td>21</td><td>100</td><td>78</td></tr><tr><th>Mean</th><td></td><td></td><td></td><td></td><td></td><td>94</td><td>92</td><td></td><td></td><td></td><td>74</td><td>82</td><td></td><td></td><td></td><td>98</td><td>81</td></tr></tbody></table>

**Fig. 6 | Segmentations of 5 dendritic branches—Na to Ne—and their localization within a 3D multistack 93x STED dataset.** A Left: the dendritic branches Na to Ne contained within a single stack and employed here for the validation of SENPAI are highlighted in red. Right: we compare the segmentations obtained with the state-of-the-art algorithms. The segmentations were performed with SENPAI, HK-Icy, Ilastik and manual segmentation by ManSegTool. Algorithm segmentations of the whole image are underlaid in gray, while the parcellation outcomes are highlighted in red. B Quantitative comparison for the segmentations of the 5 dendritic branches; volume and area obtained with SENPAI, Ilastik and HK-Icy. The values are normalized with respect to manual segmentations. HK-Icy and Ilastik were integrated with the SENPAI parcellation step to, respectively, assign spines to the dendrite and separate touching dendrites from each other (volume result showed significant differences; Friedman *p* = 0.015; post-hoc with Conover's test highlighted Ilastik

difference to both SENPAI and HK-Icy, *p* < 0.01, highlighted with gray bars).

C Quantitative comparison of the segmentations of the dendritic branches; the Dice coefficient was used to compare the segmentations obtained with the algorithms against the manual segmentation, considering the whole neuron (top) and the only spines (bottom). An ideal algorithm would give a Dice coefficient of 1. The analysis on the spines was conducted by masking out the manual segmentation of the dendrite (both whole neuron and average spine Dice coefficients from SENPAI were different to both Ilastik and HK-Icy; Friedman tests *p* = 0.015; post-hoc with Conover's tests, *p* < 0.01). D Table summarizing algorithm performance in terms of spine detection. Spines were counted in the manual segmentation, then we defined False Positives (FP) and False Negatives (FN), True Positives (TP), the Sensitivity (S% = % of TP over TP + FN) and the Precision (P% = % of TP over TP + FP) for SENPAI, HK-Icy and Ilastik. Source data are provided as a Source Data file.

0.50 ± 0.14, Ilastik Dice median±MAD 0.43 ± 0.10). Merging the information in Fig. 6C, Ilastik clearly oversegments while HK-Icy undersegments.

Spine-by-spine reconstructions obtained with SENPAI, Ilastik and HK-Icy with the manual segmentation were also compared and reported in Fig. 6D. For each of the three algorithms we counted the number of true positives, false positives and false negatives and estimated specificity and precision in spine detection. Due to higher false negatives, SENPAI gives slightly lower specificity with respect to Ilastik, but performs best in terms of precision. On average, SENPAI is better than HK-Icy on all topological and morphological metrics and performs better than Ilastik in terms of morphological reconstruction and number of false positives.

## Generalization to other neuron types and imaging modalities

To support the generalizability of the SENPAI pipeline, we tested the algorithm on multiple neuron types from different species (rat, mouse and human) and in different conditions (tissues and cultured cells, in uncleared samples and acquired with different imaging modalities—see Supplementary Information). The neuron types we segmented include human pyramidal neurons, mouse and rat pyramidal neurons, human cultured excitatory neurons, mouse cultured excitatory neurons, and mouse retinal neurons. The imaging modalities, other than confocal and confocal STED, include two-photon (2P) microscopy. We report both quantitative and qualitative evaluations, that attest to the generalizability of our reconstruction algorithm across different imaging modalities and neuron types.
<figure><img src="image_16.png" /><figcaption>**Fig. 7** | Exemplary results obtained on non-clarified samples. For both images we report the maximum projection on the left, the segmentation obtained with SENPAI on the middle (depth color-coded, cold colors indicate deeper planes), and the skeletonization of the segmentation on the right, as obtained using the NeuTube software. **Above** Exemplary dataset (m16_cing_1_9_cropped_neurona.v3dpbd, human pyramidal cell labeled with Lucifer Yellow and acquired through confocal microscopy, resolution 0.24 µm x 0.24 µm x 0.42 µm) from Benavides-Piccione et al.⁷² available from the BigNeuron gold166 standard⁶³. **Below** 3D stack of cultured rat hippocampal pyramidal cells (pixel size 91.41 nm x 91.41 nm x 280 nm). Further tests on non-clarified samples are reported in the Supplementary Information.</figcaption></figure>

Among the tested datasets of native (uncleared) tissue tested with SENPAI, 34 belong to the BigNeuron GOLD166 dataset. On the BigNeuron bench-testing platform⁴⁴,⁶²⁻⁶⁵, among 35 of the most popular state-of-the-art algorithms, SENPAI scored in the top-three for five metrics over eight, and in the top-eleven for the remaining three metrics (see Supplementary Note 10 in the Supplementary Information). An exemplary result is reported in Fig. 7, upper panels.

A further uncleared image tested is the Neuro-GPS test dataset made available by the authors of Neuro-GPS (see Supplementary Note 11 in the Supplementary Information). Additionally, at the INSERM facilities, four more datasets were produced with rat hippocampal neurons: two datasets including a whole labeled neuron in the field of view, and two higher-resolution datasets from confocal and 3D-STED imaging the same dendritic branch with its spines. The results obtained from these four datasets are presented in Supplementary Notes 12 and 13, and Supplementary Figs. 18 and 19 in the Supplementary Information. Moreover, an exemplary result is reported in Fig. 7, lower panels.

## Discussion

Mapping the structural layout of the brain at different scales is a major challenge in neuroscience⁶⁶. At the cellular level, deciphering neuronal structure and connectivity in situ is particularly difficult because of limitations in imaging depth in vivo. Consequently, imaging thick tissue samples containing densely packed cells requires considerable manipulation both in vivo and ex vivo. Once images are acquired, a further challenge is to analyse and quantify neuronal structure and morphology with high fidelity and reproducibility. To address these challenges, we have developed a framework for clearing and staining thick brain slices which can be imaged using confocal, 2P or super-resolution microscopy.

At the spine level, super-resolution STED combined with FRAP allowed to assess spines morphogenesis both in mice live slices and in vivo⁶⁷⁻⁷⁰. Single cell micro-injection and confocal microscopy recently provided a useful tool for spine classification by allowing to analyze a huge database of >7000 individually 3D reconstructed dendritic spines from human pyramidal cells⁷¹,⁷². Here, we propose to
<figure><img src="image_25.png" /><figcaption>**Fig. 7** | Exemplary results obtained on non-clarified samples. For both images we report the maximum projection on the left, the segmentation obtained with SENPAI on the middle (depth color-coded, cold colors indicate deeper planes), and the skeletonization of the segmentation on the right, as obtained using the NeuTube software. **Above** Exemplary dataset (m16_cing_1_9_cropped_neurona.v3dpbd, human pyramidal cell labeled with Lucifer Yellow and acquired through confocal microscopy, resolution 0.24 µm x 0.24 µm x 0.42 µm) from Benavides-Piccione et al.⁷² available from the BigNeuron gold166 standard⁶³. **Below** 3D stack of cultured rat hippocampal pyramidal cells (pixel size 91.41 nm x 91.41 nm x 280 nm). Further tests on non-clarified samples are reported in the Supplementary Information.</figcaption></figure>

Among the tested datasets of native (uncleared) tissue tested with SENPAI, 34 belong to the BigNeuron GOLD166 dataset. On the BigNeuron bench-testing platform⁴⁴,⁶²⁻⁶⁵, among 35 of the most popular state-of-the-art algorithms, SENPAI scored in the top-three for five metrics over eight, and in the top-eleven for the remaining three metrics (see Supplementary Note 10 in the Supplementary Information). An exemplary result is reported in Fig. 7, upper panels.

A further uncleared image tested is the Neuro-GPS test dataset made available by the authors of Neuro-GPS (see Supplementary Note 11 in the Supplementary Information). Additionally, at the INSERM facilities, four more datasets were produced with rat hippocampal neurons: two datasets including a whole labeled neuron in the field of view, and two higher-resolution datasets from confocal and 3D-STED imaging the same dendritic branch with its spines. The results obtained from these four datasets are presented in Supplementary Notes 12 and 13, and Supplementary Figs. 18 and 19 in the Supplementary Information. Moreover, an exemplary result is reported in Fig. 7, lower panels.

## Discussion

Mapping the structural layout of the brain at different scales is a major challenge in neuroscience⁶⁶. At the cellular level, deciphering neuronal structure and connectivity in situ is particularly difficult because of limitations in imaging depth in vivo. Consequently, imaging thick tissue samples containing densely packed cells requires considerable manipulation both in vivo and ex vivo. Once images are acquired, a further challenge is to analyse and quantify neuronal structure and morphology with high fidelity and reproducibility. To address these challenges, we have developed a framework for clearing and staining thick brain slices which can be imaged using confocal, 2P or super-resolution microscopy.

At the spine level, super-resolution STED combined with FRAP allowed to assess spines morphogenesis both in mice live slices and in vivo⁶⁷⁻⁷⁰. Single cell micro-injection and confocal microscopy recently provided a useful tool for spine classification by allowing to analyze a huge database of >7000 individually 3D reconstructed dendritic spines from human pyramidal cells⁷¹,⁷². Here, we propose to
complete this panorama with a pipeline that leaves single-cell injection
behind and enables the structural analysis of deep tissue images.

The pipeline is based on SENPAI, a two-step segmentation and parcellation tool which returns morphologically faithful segmentations of neurons and their branches at micron and sub-micron scales, preserving surface details as well as multi-scale structure complexity, providing enhanced robustness to signal inhomogeneity even across thick samples. It exploits image intensity and its second order derivatives in space that were previously proposed for edge detection and structure modeling<sup>3,74</sup>. This second order derivatives analysis allows SENPAI to highlight surfaces enclosing higher signal regions, independent of the cross-sectional or intra-slice signal changes. It also optimizes data information usage by merging local segmentation with image parcellation based on global image intensity distribution. As such, the pipeline allows characterizing neuronal arborization, dendritic branch diameters or local spine density more accurately and faithfully than current algorithms and image processing tools (see Supplementary Figs. 2–4). Because it is model free and acquisition method-independent, tissular level organization at low magnification and structural nanoscale morphometry of dendritic spines using super-resolution microscopy can be easily correlated without the need for methods such as single cell injection<sup>66,73–75</sup>.

SENPAI's performance was compared with state-of-the-art tools,
and, when available, manual segmentation. Here we show that it
achieves excellent results on different imaging modalities, such as
standard confocal and STED. Moreover, SENPAI provides a finer
description of isolated neurons while minimizing user effort in tuning
the algorithm parameters: only the selection of the 3D Gaussian filter
size and the soma identification to run the parcellation step are
required.

Comparing performance with current tools and algorithms using 40x confocal microscope datasets, SENPAI outperforms NeuroGPS and NeuTube as it returns isolated neurons with a significantly higher arborization (Figs. 3–5). Indeed, the semi-automatic tracing with NeuTube is strongly limited by user sensitivity to the thinnest low-intensity branches. On the other hand, NeuroGPS could not achieve dense tracings even when lowering the segmentation threshold to the minimum. This is confirmed by the validation based on SO (Horton-Strahler ordering), which highlights that the segmentations provided by SENPAI and HK-Icy are clearly more consistent with quantitative information on Purkinje neuron morphology available in literature (Fig. 5). NeuroGPS provided sparse tracing of dendritic branches, many of which were not connected to any soma. NeuTube captured the basic morphology of a neuron in its native arrangement only for a small subset of neurons and it achieved SNs >4. Although SENPAI and HK-Icy showed similar performance, segmented structure density was observed to have a strong z-direction dependency for HK-Icy, compared to SENPAI. Undoubtedly, such a dependency is intimately linked to non-homogeneous pixel intensity and image contrast across sections (see Supplementary Fig. 7) and it could be related to the fact that segmentation in HK-Icy is based on intensity values and thus does not exploit any topological information.

For the 93x datasets obtained with STED, the results—in terms of assigned spines to the correct dendritic branch—were compared with manual segmentations performed with ManSegTool. All the approaches tested accurately reconstruct the dendritic branch of interest (Fig. 6A). Ilastik clearly results in over-segmentation with respect to the manual ground truth, with false positive assignments (Fig. 6A and D) and over-estimated areas and volumes both at the whole branch and at the spine level (Fig. 6B), while SENPAI correctly segments and assigns the spines in 5 out of 6 of the cases investigated (Fig. 6A, C) and provides estimates for area and volume in line with the manual ground-truth (Fig. 6B).

As far as neuronal tree reconstruction is concerned, most of the
state-of-the-art tools for revealing neuronal arborization or dendritic

spines require a further step for reliably comparing their outcomes
with the ones obtained with SENPAI. For instance, HK-Icy deals with a
considerable number of parameters to be tuned for reaching a rea-
sonable segmentation, but even tuning the parameters for maximizing
the segmentation density without losing structural complexity (details
on the parametric optimization reported in Supplementary Fig. 7), the
algorithm returns a unique object including all the neurons that should
be separated. This is also true for spine detection on 93x datasets,
indeed, neither HK-Icy nor Ilastik provide any assignation criteria for
the spines disconnected to the neuron body. Therefore, we observed
that a parcellation step is needed to overcome the limitations of these
state-of-the-art tools. This proves the need, particularly in the specific
context of dense packed scenarios, typical of mammalian brain tissues,
for a built-in codified criterion for the assignment and separation of
objects of interest at different scales, be they branches or spines. We
provide this versatile feature in SENPAI.

Although SENPAI was shown to be robust in the segmentation of
single-cell scenarios, with different cell morphologies and imaging
modalities, its unique contribution to the scientific community is the
ability to deal with dense scenarios from cleared samples, a context
that is particularly challenging for existing algorithms. Moreover, the
SENPAI pipeline allows for reconstructing large groups of neurons
down to the single spine level with a single, unified approach across
different scenarios. This result is achieved thanks to the upgrade of the
K-means clustering approach using the topological information at
different scales, along with proper class selection criteria for neuronal
structure identification. Another relevant feature is the development
and integration with a parcellation step, based on watershed transform
of the intensity image. This allows successfully isolating single neurons
in different scenarios as well as performing an automatic assignment of
spines to the relevant dendrite. Indeed, increasing magnification is
often unfeasible, and it comes at the cost of shrinking the field of view.
In these cases, spine neck segmentation is impaired by resolution
limits. Using the watershed transform on the intensity image, we
provide an efficient parcellation step for the automatic assignment of
spines. Spine assignment is a crucial step preliminary to neck recon-
struction. The latter can be achieved either using model-based<sup>75–77</sup> or
data-driven<sup>78,79</sup> approaches.

Our results are also promising in the context of the segmentation
of confocal imaging from brain samples. We report here the complex
arborizations of Purkinje cells in their native arrangement such as
those in Fig. 1. This scenario was chosen as a proof of concept since
Purkinje cells are known to be highly densely arranged within the
murine cerebellum. These reconstructions are unique since they pro-
vide fine segmentation of several neighboring cells with a very dense
arborization. SENPAI provides a faithful panorama of the whole forest,
where other solutions usually only provide segmentation of single cells
isolated by fluorescent reporter injection. Thanks to its capability of
imaging and segmenting complex dendritic arbors, the pipeline here
proposed is a powerful tool that can be directly applied to transgenic
reporter mouse lines. Indeed, in contrast to sparse injections for single
cell imaging which are applied to thin live slices, SENPAI can be directly
used on live or fixed thick blocks of tissue to quickly segment
genetically-labeled neighboring cells.

Furthermore, we demonstrate the ability of the SENPAI pipeline to
reconcile low magnification topographical maps from various brain
regions (using either confocal or lightsheet) with super-resolution data
giving access to the nanoscale level of the synapse. We also emphasize
the relevance of the quality assessment of segmentations from ex vivo
samples by using accurate morphological descriptors presented in
literature. This validation paradigm might overcome the limitation of
manual segmentations on dense images as gold standard for neuron
segmentation. In fact, our results suggest that manual approaches
cannot always be considered the ground truth since they may result in
poor segmentations especially in large volume acquisitions whose
complete this panorama with a pipeline that leaves single-cell injection
behind and enables the structural analysis of deep tissue images.

The pipeline is based on SENPAI, a two-step segmentation and parcellation tool which returns morphologically faithful segmentations of neurons and their branches at micron and sub-micron scales, preserving surface details as well as multi-scale structure complexity, providing enhanced robustness to signal inhomogeneity even across thick samples. It exploits image intensity and its second order derivatives in space that were previously proposed for edge detection and structure modeling<sup>3,74</sup>. This second order derivatives analysis allows SENPAI to highlight surfaces enclosing higher signal regions, independent of the cross-sectional or intra-slice signal changes. It also optimizes data information usage by merging local segmentation with image parcellation based on global image intensity distribution. As such, the pipeline allows characterizing neuronal arborization, dendritic branch diameters or local spine density more accurately and faithfully than current algorithms and image processing tools (see Supplementary Figs. 2–4). Because it is model free and acquisition method-independent, tissular level organization at low magnification and structural nanoscale morphometry of dendritic spines using super-resolution microscopy can be easily correlated without the need for methods such as single cell injection<sup>66,73–75</sup>.

SENPAI's performance was compared with state-of-the-art tools,
and, when available, manual segmentation. Here we show that it
achieves excellent results on different imaging modalities, such as
standard confocal and STED. Moreover, SENPAI provides a finer
description of isolated neurons while minimizing user effort in tuning
the algorithm parameters: only the selection of the 3D Gaussian filter
size and the soma identification to run the parcellation step are
required.

Comparing performance with current tools and algorithms using 40x confocal microscope datasets, SENPAI outperforms NeuroGPS and NeuTube as it returns isolated neurons with a significantly higher arborization (Figs. 3–5). Indeed, the semi-automatic tracing with NeuTube is strongly limited by user sensitivity to the thinnest low-intensity branches. On the other hand, NeuroGPS could not achieve dense tracings even when lowering the segmentation threshold to the minimum. This is confirmed by the validation based on SO (Horton-Strahler ordering), which highlights that the segmentations provided by SENPAI and HK-Icy are clearly more consistent with quantitative information on Purkinje neuron morphology available in literature (Fig. 5). NeuroGPS provided sparse tracing of dendritic branches, many of which were not connected to any soma. NeuTube captured the basic morphology of a neuron in its native arrangement only for a small subset of neurons and it achieved SNs >4. Although SENPAI and HK-Icy showed similar performance, segmented structure density was observed to have a strong z-direction dependency for HK-Icy, compared to SENPAI. Undoubtedly, such a dependency is intimately linked to non-homogeneous pixel intensity and image contrast across sections (see Supplementary Fig. 7) and it could be related to the fact that segmentation in HK-Icy is based on intensity values and thus does not exploit any topological information.

For the 93x datasets obtained with STED, the results—in terms of assigned spines to the correct dendritic branch—were compared with manual segmentations performed with ManSegTool. All the approaches tested accurately reconstruct the dendritic branch of interest (Fig. 6A). Ilastik clearly results in over-segmentation with respect to the manual ground truth, with false positive assignments (Fig. 6A and D) and over-estimated areas and volumes both at the whole branch and at the spine level (Fig. 6B), while SENPAI correctly segments and assigns the spines in 5 out of 6 of the cases investigated (Fig. 6A, C) and provides estimates for area and volume in line with the manual ground-truth (Fig. 6B).

As far as neuronal tree reconstruction is concerned, most of the
state-of-the-art tools for revealing neuronal arborization or dendritic

spines require a further step for reliably comparing their outcomes
with the ones obtained with SENPAI. For instance, HK-Icy deals with a
considerable number of parameters to be tuned for reaching a rea-
sonable segmentation, but even tuning the parameters for maximizing
the segmentation density without losing structural complexity (details
on the parametric optimization reported in Supplementary Fig. 7), the
algorithm returns a unique object including all the neurons that should
be separated. This is also true for spine detection on 93x datasets,
indeed, neither HK-Icy nor Ilastik provide any assignation criteria for
the spines disconnected to the neuron body. Therefore, we observed
that a parcellation step is needed to overcome the limitations of these
state-of-the-art tools. This proves the need, particularly in the specific
context of dense packed scenarios, typical of mammalian brain tissues,
for a built-in codified criterion for the assignment and separation of
objects of interest at different scales, be they branches or spines. We
provide this versatile feature in SENPAI.

Although SENPAI was shown to be robust in the segmentation of single-cell scenarios, with different cell morphologies and imaging modalities, its unique contribution to the scientific community is the ability to deal with dense scenarios from cleared samples, a context that is particularly challenging for existing algorithms. Moreover, the SENPAI pipeline allows for reconstructing large groups of neurons down to the single spine level with a single, unified approach across different scenarios. This result is achieved thanks to the upgrade of the K-means clustering approach using the topological information at different scales, along with proper class selection criteria for neuronal structure identification. Another relevant feature is the development and integration with a parcellation step, based on watershed transform of the intensity image. This allows successfully isolating single neurons in different scenarios as well as performing an automatic assignment of spines to the relevant dendrite. Indeed, increasing magnification is often unfeasible, and it comes at the cost of shrinking the field of view. In these cases, spine neck segmentation is impaired by resolution limits. Using the watershed transform on the intensity image, we provide an efficient parcellation step for the automatic assignment of spines. Spine assignment is a crucial step preliminary to neck reconstruction. The latter can be achieved either using model-based<sup>75–77</sup> or data-driven<sup>78,79</sup> approaches.

Our results are also promising in the context of the segmentation
of confocal imaging from brain samples. We report here the complex
arborizations of Purkinje cells in their native arrangement such as
those in Fig. 1. This scenario was chosen as a proof of concept since
Purkinje cells are known to be highly densely arranged within the
murine cerebellum. These reconstructions are unique since they pro-
vide fine segmentation of several neighboring cells with a very dense
arborization. SENPAI provides a faithful panorama of the whole forest,
where other solutions usually only provide segmentation of single cells
isolated by fluorescent reporter injection. Thanks to its capability of
imaging and segmenting complex dendritic arbors, the pipeline here
proposed is a powerful tool that can be directly applied to transgenic
reporter mouse lines. Indeed, in contrast to sparse injections for single
cell imaging which are applied to thin live slices, SENPAI can be directly
used on live or fixed thick blocks of tissue to quickly segment
genetically-labeled neighboring cells.

Furthermore, we demonstrate the ability of the SENPAI pipeline to reconcile low magnification topographical maps from various brain regions (using either confocal or lightsheet) with super-resolution data giving access to the nanoscale level of the synapse. We also emphasize the relevance of the quality assessment of segmentations from ex vivo samples by using accurate morphological descriptors presented in literature. This validation paradigm might overcome the limitation of manual segmentations on dense images as gold standard for neuron segmentation. In fact, our results suggest that manual approaches cannot always be considered the ground truth since they may result in poor segmentations especially in large volume acquisitions whose
resolution is comparable to the size of crucial details of the image (e.g., thin neuronal branches). To this end, we propose an alternative method for evaluating automated segmentation algorithms through comparison with available knowledge on cell morphometrics (e.g., ramification density of Purkinje cells).

SENPAI was successfully tested on samples prepared using different methods (non-cleared tissue, cells in culture) acquired with multiple acquisition modalities, such as confocal, 3D STED and 2P, and different neuron types. It should be noted that several other imaging and labeling modalities that are specific to some parts of the neuron, e.g., membright for the membranes²⁵ or phalloidin for spine heads⁸⁰ are used by researchers. In all the cases where local inhomogeneities characterize neuronal structures, e.g., for non-uniform distribution of staining across the cell, SENPAI might show a suboptimal behavior. Specifically, the use of spatial derivatives, that are sensitive to image intensity changes, might lead to hollow 3D segmentations or poorly connected reconstruction of the dendrites. In some cases, such as those presented in the Supplementary Information, the 3D spatial smoothing preprocessing step resulted in increased neuronal structure homogeneity and consequently accentuated the behavior of second order derivatives. Further preprocessing steps might thus be needed to improve the generalizability of SENPAI to specific staining and imaging modalities.

It is worth noting that deep learning is now emerging as a potential solution to the complex problem of neuronal reconstruction from microscopy images. Yet, the time needed for training deep-learning models, as well as the fact that they heavily depend on the heterogeneity of training data, still limits their application to a variety of problems, such as single neuron segmentation. In addition, algorithms available in the state-of-the-art still struggle when dealing with separating multiple neurons within an image block³⁷. Moreover, they do not easily allow performing semi-supervised tasks to provide control over under- and over-segmentation. As far as we know, no deep learning solution is yet able to segment microscopy images acquired using different modalities. Nonetheless, several groups are working on this (e.g., ebrains.eu) and likely future efforts will combine automatic algorithms like SENPAI and deep learning analysis to improve 3D neuronal segmentation.

Other future developments will include the application of SENPAI to cleared samples from other brain regions, to fully evaluate the potential of the proposed framework. We will also explore the possibility of estimating the path of spines necks even when the algorithm is not able to connect the spine with the main neuronal body and to provide the user with the possibility of characterizing spine population in terms of density and morphology.

In conclusion, we report a two-step segmentation and parcellation method -SENPAI- which can be combined with brain tissue preparation and labeling to isolate neurons from densely packed neighborhoods and return morphologically faithful segmentations of the cells and their branches at micron and sub-micron scales. The pipeline preserves surface details as well as multi-scale structural complexity, providing enhanced robustness to signal inhomogeneity even across thick samples. We show that SENPAI is superior in performance and robustness with respect to other segmentation algorithms and can be used across scales for different imaging modalities and different types of neuron or brain tissue samples. SENPAI can be exploited as a stand-alone, open-source pipeline to support the development of connectome maps and improve our understanding of the brain's structure and consequently its functional behavior.

## Methods

### Labeling and imaging of brain slices

We used the L7GFP mouse line, expressing cytosolic EGFP within dendrites, axons and soma of Purkinje cells under the L7 promoter. Mice were housed in rooms maintained at 22 ± 2 C, 65% humidity, and artificial light between 08:00 a.m. and 08:00 p.m. Male 3 month-old

mice were anesthetized (7% chloral hydrate) and intracardiacally perfused with 20 mL of ice-cold Phosphate Buffered Saline (PBS 1X, Sigma-Aldrich, Milan, Italy) followed by 20 mL of ice-cold hydrogel solution (4% acrylamide, 0.05% bis-acrylamide (Biorad Lab Inc., California, USA)), 4% formaldehyde (PFA, Sigma-Aldrich) and 0.25% VA-044 thermally triggered initiator (Wako Chemicals, Neuss, Germany). Brains were extracted and immersed in hydrogel solution for 3 days in the dark at 4 °C. Samples were placed under a vacuum for 10 min for bubble removal and to facilitate acrylamide polymerization and incubated at 37 °C overnight. The cerebellum were then cut in slices of 0.5–1 mm using a Leica VT1200S vibratome. Slices were then incubated in two sequential baths of clarity solution (200 mM Boric Acid (Farmitalia Carlo Erba spa, Italy) and 4% Sodium Dodecyl Sulfate (SDS, Sigma-Aldrich) pH 8.5) at 37 °C for 3 and 5 days respectively. After clarification, the slices were washed in PBS, incubated in blocking solution in an Eppendorf tube on a wheel at room temperature (PBS 0.2% triton 0.25% cold water fish gelatin 3% donkey serum) for 1 h and then incubated in primary antibody solution for at least 2 weeks on a wheel at 4 degrees. Antibody solution was composed of washing buffer (PBS supplemented with 0.2% triton-0.12% cold water fish gelatin (SIGMA G7765)-0.5% donkey serum (Jackson ImmunoResearch) and chicken anti GFP from Aves labs diluted to 1/1000). After 3 washes in washing buffer (1 h each) at RT, slices were incubated for at least 1 week at 4 °C under gentle agitation in washing solution supplemented with Donkey anti Chicken antibody coupled to Alexa 594 diluted at 1/500 (Thermofisher). Slices were then washed 3 times and mounted on a glass slide. To build horizontal calibrated spacers, PVC cover binders (300 microns thick from Fellowes) were punched with a hammer drill so that they remained very flat and horizontal and could surround the cleared slices. Several spacers could be stacked depending on slice thickness to adjust the height of the mounting. The spacer well was then filled with prolong gold and covered with a 0.17 mm (super-resolution #1.5) Menzel Gläser glass coverslip. Spacers and coverslip were sealed to the slide using Twinsil Picodent bi-component silicone.

Confocal and STED images were acquired with a confocal laser scanning microscope LEICA SP8 STED 3DX equipped with a 20x/0.75NA and 93x/1.3 NA glycerol immersion objective or a 40x NA1.3 oil objective and with 3 hybrid detectors (HyDs). The specimens were excited with a pulsed white-light laser (598 nm) and depleted with a pulsed 775 nm depletion laser to acquire nanoscale imaging (fluorescence beyond 600 nm was detected using SMD HyD detector, dedicated bandwidths are indicated in the metadata on Zenodo; refer to the Data Availability section). Depletion laser power balance (between 2D and 3D) was adapted depending on transparency sample laser to optimize resolution and preserve signal in depth. Confocal images of rat hippocampal pyramidal cells in culture were taken with 40x NA 1.3 Leica oil objective with a pixel size of 91.41 nm x 91.41 nm x 280 nm, bandwidth 603–644 nm.

3D-STED was used with a 93x NA1.3 glycerol objective. Images were averaged 16 times in line and acquired with a magnification zoom >3. Excitation laser was adjusted to avoid any saturated pixels. Rat hippocampal pyramidal cells in culture were acquired with voxel size of 40 x 40 x 130 nm within a Z stack of 21 slices (bandwidth 598–631 nm). Cerebellum Purkinje cells were acquired with voxel size of 62 x 62 x 60 nm (bandwidth 605–777 nm) within a Z stack of 319 (Fig. 1) or 35 slices (Fig. 2).

## SENPAI

SENPAI is an automated tool implemented in Matlab (The MathWorks Inc., United States) and released as a freely available toolbox at: https://github.com/cauzzo-s5/SENPAI. It can be used to reconstruct neuronal morphology, from spine detection and morphometry up to whole neuron arborization, starting from 3D optical images from any type of microscope including confocal, multiphoton, STED, etc. It implements two fundamental steps: a segmentation step and a parcellation step.
resolution is comparable to the size of crucial details of the image (e.g., thin neuronal branches). To this end, we propose an alternative method for evaluating automated segmentation algorithms through comparison with available knowledge on cell morphometrics (e.g., ramification density of Purkinje cells).

SENPAI was successfully tested on samples prepared using different methods (non-cleared tissue, cells in culture) acquired with multiple acquisition modalities, such as confocal, 3D STED and 2P, and different neuron types. It should be noted that several other imaging and labeling modalities that are specific to some parts of the neuron, e.g., membright for the membranes²⁵ or phalloidin for spine heads⁸⁰ are used by researchers. In all the cases where local inhomogeneities characterize neuronal structures, e.g., for non-uniform distribution of staining across the cell, SENPAI might show a suboptimal behavior. Specifically, the use of spatial derivatives, that are sensitive to image intensity changes, might lead to hollow 3D segmentations or poorly connected reconstruction of the dendrites. In some cases, such as those presented in the Supplementary Information, the 3D spatial smoothing preprocessing step resulted in increased neuronal structure homogeneity and consequently accentuated the behavior of second order derivatives. Further preprocessing steps might thus be needed to improve the generalizability of SENPAI to specific staining and imaging modalities.

It is worth noting that deep learning is now emerging as a potential solution to the complex problem of neuronal reconstruction from microscopy images. Yet, the time needed for training deep-learning models, as well as the fact that they heavily depend on the heterogeneity of training data, still limits their application to a variety of problems, such as single neuron segmentation. In addition, algorithms available in the state-of-the-art still struggle when dealing with separating multiple neurons within an image block³⁷. Moreover, they do not easily allow performing semi-supervised tasks to provide control over under- and over-segmentation. As far as we know, no deep learning solution is yet able to segment microscopy images acquired using different modalities. Nonetheless, several groups are working on this (e.g., ebrains.eu) and likely future efforts will combine automatic algorithms like SENPAI and deep learning analysis to improve 3D neuronal segmentation.

Other future developments will include the application of SENPAI to cleared samples from other brain regions, to fully evaluate the potential of the proposed framework. We will also explore the possibility of estimating the path of spines necks even when the algorithm is not able to connect the spine with the main neuronal body and to provide the user with the possibility of characterizing spine population in terms of density and morphology.

In conclusion, we report a two-step segmentation and parcellation method -SENPAI- which can be combined with brain tissue preparation and labeling to isolate neurons from densely packed neighborhoods and return morphologically faithful segmentations of the cells and their branches at micron and sub-micron scales. The pipeline preserves surface details as well as multi-scale structural complexity, providing enhanced robustness to signal inhomogeneity even across thick samples. We show that SENPAI is superior in performance and robustness with respect to other segmentation algorithms and can be used across scales for different imaging modalities and different types of neuron or brain tissue samples. SENPAI can be exploited as a stand-alone, open-source pipeline to support the development of connectome maps and improve our understanding of the brain's structure and consequently its functional behavior.

## Methods

### Labeling and imaging of brain slices

We used the L7GFP mouse line, expressing cytosolic EGFP within dendrites, axons and soma of Purkinje cells under the L7 promoter. Mice were housed in rooms maintained at 22 ± 2 C, 65% humidity, and artificial light between 08:00 a.m. and 08:00 p.m. Male 3 month-old

mice were anesthetized (7% chloral hydrate) and intracardiacally perfused with 20 mL of ice-cold Phosphate Buffered Saline (PBS 1X, Sigma-Aldrich, Milan, Italy) followed by 20 mL of ice-cold hydrogel solution (4% acrylamide, 0.05% bis-acrylamide (Biorad Lab Inc., California, USA)), 4% formaldehyde (PFA, Sigma-Aldrich) and 0.25% VA-044 thermally triggered initiator (Wako Chemicals, Neuss, Germany). Brains were extracted and immersed in hydrogel solution for 3 days in the dark at 4 °C. Samples were placed under a vacuum for 10 min for bubble removal and to facilitate acrylamide polymerization and incubated at 37 °C overnight. The cerebellum were then cut in slices of 0.5–1 mm using a Leica VT1200S vibratome. Slices were then incubated in two sequential baths of clarity solution (200 mM Boric Acid (Farmitalia Carlo Erba spa, Italy) and 4% Sodium Dodecyl Sulfate (SDS, Sigma-Aldrich) pH 8.5) at 37 °C for 3 and 5 days respectively. After clarification, the slices were washed in PBS, incubated in blocking solution in an Eppendorf tube on a wheel at room temperature (PBS 0.2% triton 0.25% cold water fish gelatin 3% donkey serum) for 1 h and then incubated in primary antibody solution for at least 2 weeks on a wheel at 4 degrees. Antibody solution was composed of washing buffer (PBS supplemented with 0.2% triton-0.12% cold water fish gelatin (SIGMA G7765)-0.5% donkey serum (Jackson ImmunoResearch) and chicken anti GFP from Aves labs diluted to 1/1000). After 3 washes in washing buffer (1 h each) at RT, slices were incubated for at least 1 week at 4 °C under gentle agitation in washing solution supplemented with Donkey anti Chicken antibody coupled to Alexa 594 diluted at 1/500 (Thermofisher). Slices were then washed 3 times and mounted on a glass slide. To build horizontal calibrated spacers, PVC cover binders (300 microns thick from Fellowes) were punched with a hammer drill so that they remained very flat and horizontal and could surround the cleared slices. Several spacers could be stacked depending on slice thickness to adjust the height of the mounting. The spacer well was then filled with prolong gold and covered with a 0.17 mm (super-resolution #1.5) Menzel Gläser glass coverslip. Spacers and coverslip were sealed to the slide using Twinsil Picodent bi-component silicone.

Confocal and STED images were acquired with a confocal laser scanning microscope LEICA SP8 STED 3DX equipped with a 20x/0.75NA and 93x/1.3 NA glycerol immersion objective or a 40x NA1.3 oil objective and with 3 hybrid detectors (HyDs). The specimens were excited with a pulsed white-light laser (598 nm) and depleted with a pulsed 775 nm depletion laser to acquire nanoscale imaging (fluorescence beyond 600 nm was detected using SMD HyD detector, dedicated bandwidths are indicated in the metadata on Zenodo; refer to the Data Availability section). Depletion laser power balance (between 2D and 3D) was adapted depending on transparency sample laser to optimize resolution and preserve signal in depth. Confocal images of rat hippocampal pyramidal cells in culture were taken with 40x NA 1.3 Leica oil objective with a pixel size of 91.41 nm x 91.41 nm x 280 nm, bandwidth 603–644 nm.

3D-STED was used with a 93x NA1.3 glycerol objective. Images were averaged 16 times in line and acquired with a magnification zoom >3. Excitation laser was adjusted to avoid any saturated pixels. Rat hippocampal pyramidal cells in culture were acquired with voxel size of 40 x 40 x 130 nm within a Z stack of 21 slices (bandwidth 598–631 nm). Cerebellum Purkinje cells were acquired with voxel size of 62 x 62 x 60 nm (bandwidth 605–777 nm) within a Z stack of 319 (Fig. 1) or 35 slices (Fig. 2).

## SENPAI

SENPAI is an automated tool implemented in Matlab (The MathWorks Inc., United States) and released as a freely available toolbox at: https://github.com/cauzzo-s5/SENPAI. It can be used to reconstruct neuronal morphology, from spine detection and morphometry up to whole neuron arborization, starting from 3D optical images from any type of microscope including confocal, multiphoton, STED, etc. It implements two fundamental steps: a segmentation step and a parcellation step.
**Segmentation step.** The first step to obtain faithful three-dimensional neuron reconstructions is to isolate neurons from the background. SENPAI tackles this step through its core segmentation algorithm, a topology-informed K-means clustering. Briefly, the K-means portions of n observations ($X_1, ..., X_n$) defined on a d-dimensional space into K clusters, by minimizing the within-cluster variances⁸¹. In SENPAI, the space is made of $d=4$ features of interest, comprising the pixel intensity of the image and second order spatial derivatives computed along the three main cartesian axes, while the n observations are represented by the total number of pixels entering the K-means. Since K-means convergence may be affected by initial conditions, additional hyperparameters, such as the number of replicates and the maximum number of iterations to reach convergence are included (in SENPAI, replicates are set to 10, and for each replicate, a maximum of 1000 iterations is allowed). To reduce the computational load for the K-means, a subset of background pixels is excluded from the clustering. This is tackled by simple thresholding, although more sophisticated methods could be used⁸². Preprocessing steps might include pointwise transformations (e.g., logarithmic), to adjust the image dynamics. Moreover, since the K-means may be computationally expensive, it can also be run on smaller user-defined cropped datasets to limit memory usage. Each 3D structure defined by a high-intensity cluster on a low-intensity background is characterized by intensity gradients at the boundaries, coded in the second derivative by a positive peak at the external boundary and a negative peak at the internal one. A key feature of SENPAI's K-means clustering is the choice of the number of classes K, and the means by which such classes are interpreted and used for segmentation. The algorithm iteratively searches for the smallest K that allows to have (i) a class encoding positive values of the second order derivatives for each direction in the 3D space (representing the outer borders of the neuron structures), (ii) each direction (x, y, z) is encoded in a different class. Then, for a given number of classes K, SENPAI identifies neurons by sorting and selecting the clusters obtained. Sorting is based on average pixel intensity values of each cluster, from the lowest to the highest. Then, the clusters associated with the neuronal structures are given by all the clusters with the highest average pixel intensity values and with all the second order derivates whose values are negative (these clusters represent signal from the neuron body see Fig. 2B, C). The union of the selected classes gives the final segmentation.

An optional parameter is the size of the pre-filtering kernel, which represents one of the salient features of SENPAI and allows focusing on multiple levels of detail of the image. First, the dataset is filtered using a 3D Gaussian filter and derivatives are computed. After the pre-filter step, the K-means clustering is performed on the pixel intensity of the unsmoothed dataset, and second order spatial derivatives computed on the smoothed image. This pre-filtering step can also be performed twice in a row by using two smoothing levels. This option allows capturing structures at different scales, since it eliminates spurious and unwanted boundaries, e.g., those within thick branches or big somata. When multiple levels of smoothing are used, the resulting segmentations are merged to compose the final segmentation (Fig. 2D).

However, since inhomogeneities in pixel intensity within big neuronal structures (e.g., the soma) cannot all be smoothed and may be identified as boundaries—leading to false negatives—, a function for filling such holes is implemented within the segmentation. Similarly, spurious small clusters (<7 voxels, the smallest 3D symmetrical structure) detected from inhomogeneities in the background are eliminated.

**Parcellation step.** The second step of the algorithm aims at isolating single neurons from the foreground identified via the K-means clustering. To this end, SENPAI performs a parcellation procedure based on the watershed transform. This defines a catchment basin for each structure, which allows marking the regions/pixels that belong to a

particular structure and those that do not pertain to it. The parcellation serves two purposes: when dealing with single neuron reconstruction: first it splits neurons that may have been merged in a single structure, while when dealing with spine segmentation, it groups together disconnected structures. Thus, the parcellation is performed through two different functions.

The catchment basins are produced for each marked core. The cores are defined automatically in the super-resolution case, by imposing a threshold on the size of the clusters composing the segmented image. While big clusters are labeled as cores, smaller clusters are labeled as spines to be assigned to such cores. On the other hand, for standard microscopy, cores correspond to somata. These can be marked by the user thanks to a GUI implemented in SENPAI.

Once the cores are defined, the original grayscale dataset is filtered with a 3-by-3-by-3 median filter, and its complement is obtained. A morphological reconstruction is applied on this latter, so that the regional intensity minima outside the cores are eliminated. A watershed transform produces one catchment basin for each remaining regional minimum.

The parcellation can be modified a posteriori, thanks to a routine to visually assess the quality of the segmentation neuron-by-neuron, and to set additional markers on spuriously assigned branches. Incorrect assignments are usually caused by the presence of branches of neurons whose soma lies outside the acquired dataset. Operationally, this is done thanks to a function within the SENPAI toolkit, implemented to correct the parcellation by adding to the mask of the somata some additional clusters. These allow the definition of separate catchment basins for wrongly assigned branches.

## Testing datasets

The algorithm was tested on datasets acquired with a Nikon A1 confocal microscope (40x objective, excitation length 457 nm, bandwidth 500–550 nm), and a LEICA SP8 STED 3DX (93x objective, pulsed white-light laser 598 nm, pulsed 775 nm depletion laser, bandwidth 605–777 nm). All image stacks were from Purkinje cells within murine cerebella, cleared as in Magliaro et al.³⁰. We evaluated SENPAI's performance in distinguishing both cellular (i.e., neurons) and subcellular (i.e., spines) structures.

The first 40x confocal image is a 512-by-512-by-143 image containing 114 somas (Fig. 2A), while the second one is a 512-by-512-by-139 image containing 103 somas. SENPAI was used on these datasets with a single clustering instance, without Gaussian smoothing. Then, post-processing routines including parcellation and pruning were exploited for isolating single cells.

The 93x STED dataset is a 1024-by-1024-by-35 image in which several sections of neurons can be observed (Fig. 2A). The segmentation with SENPAI was obtained merging two clustering instances with different levels of smoothness (i.e., setting the standard deviations of the 3D Gaussian filter to 0 and 3). Finally, we assigned the dendritic spines to their parent branch.

## Performance assessment

In the following, we report the methodology used to compare the performance of SENPAI with that of HK-Icy, NeuTube, NeuroGPS, Ilastik and manual segmentation. This section of the methodology is not part of the SENPAI pipeline as it was only intended to be used for its validation. First, we describe how the competing toolboxes were employed, then we provide details on how we extracted morphometrics and statistics to be used for benchmarking.

**40x confocal.** The comparisons on the single neuron segmentations obtained with SENPAI, HK-Icy and Ilastik, as well as the tracings obtained with NeuroGPS and NeuTube, were performed on 27 cells.

We provide here the key parameters that had to be set for segmenting those neurons on HK-Icy, and NeuroGPS. For the HK-Means
**Segmentation step.** The first step to obtain faithful three-dimensional neuron reconstructions is to isolate neurons from the background. SENPAI tackles this step through its core segmentation algorithm, a topology-informed K-means clustering. Briefly, the K-means portions of n observations ($X_1, ..., X_n$) defined on a d-dimensional space into K clusters, by minimizing the within-cluster variances⁸¹. In SENPAI, the space is made of $d=4$ features of interest, comprising the pixel intensity of the image and second order spatial derivatives computed along the three main cartesian axes, while the n observations are represented by the total number of pixels entering the K-means. Since K-means convergence may be affected by initial conditions, additional hyperparameters, such as the number of replicates and the maximum number of iterations to reach convergence are included (in SENPAI, replicates are set to 10, and for each replicate, a maximum of 1000 iterations is allowed). To reduce the computational load for the K-means, a subset of background pixels is excluded from the clustering. This is tackled by simple thresholding, although more sophisticated methods could be used⁸². Preprocessing steps might include pointwise transformations (e.g., logarithmic), to adjust the image dynamics. Moreover, since the K-means may be computationally expensive, it can also be run on smaller user-defined cropped datasets to limit memory usage. Each 3D structure defined by a high-intensity cluster on a low-intensity background is characterized by intensity gradients at the boundaries, coded in the second derivative by a positive peak at the external boundary and a negative peak at the internal one. A key feature of SENPAI's K-means clustering is the choice of the number of classes K, and the means by which such classes are interpreted and used for segmentation. The algorithm iteratively searches for the smallest K that allows to have (i) a class encoding positive values of the second order derivatives for each direction in the 3D space (representing the outer borders of the neuron structures), (ii) each direction (x, y, z) is encoded in a different class. Then, for a given number of classes K, SENPAI identifies neurons by sorting and selecting the clusters obtained. Sorting is based on average pixel intensity values of each cluster, from the lowest to the highest. Then, the clusters associated with the neuronal structures are given by all the clusters with the highest average pixel intensity values and with all the second order derivates whose values are negative (these clusters represent signal from the neuron body see Fig. 2B, C). The union of the selected classes gives the final segmentation.

An optional parameter is the size of the pre-filtering kernel, which represents one of the salient features of SENPAI and allows focusing on multiple levels of detail of the image. First, the dataset is filtered using a 3D Gaussian filter and derivatives are computed. After the pre-filter step, the K-means clustering is performed on the pixel intensity of the unsmoothed dataset, and second order spatial derivatives computed on the smoothed image. This pre-filtering step can also be performed twice in a row by using two smoothing levels. This option allows capturing structures at different scales, since it eliminates spurious and unwanted boundaries, e.g., those within thick branches or big somata. When multiple levels of smoothing are used, the resulting segmentations are merged to compose the final segmentation (Fig. 2D).

However, since inhomogeneities in pixel intensity within big neuronal structures (e.g., the soma) cannot all be smoothed and may be identified as boundaries—leading to false negatives—, a function for filling such holes is implemented within the segmentation. Similarly, spurious small clusters (<7 voxels, the smallest 3D symmetrical structure) detected from inhomogeneities in the background are eliminated.

**Parcellation step.** The second step of the algorithm aims at isolating single neurons from the foreground identified via the K-means clustering. To this end, SENPAI performs a parcellation procedure based on the watershed transform. This defines a catchment basin for each structure, which allows marking the regions/pixels that belong to a

particular structure and those that do not pertain to it. The parcellation serves two purposes: when dealing with single neuron reconstruction: first it splits neurons that may have been merged in a single structure, while when dealing with spine segmentation, it groups together disconnected structures. Thus, the parcellation is performed through two different functions.

The catchment basins are produced for each marked core. The cores are defined automatically in the super-resolution case, by imposing a threshold on the size of the clusters composing the segmented image. While big clusters are labeled as cores, smaller clusters are labeled as spines to be assigned to such cores. On the other hand, for standard microscopy, cores correspond to somata. These can be marked by the user thanks to a GUI implemented in SENPAI.

Once the cores are defined, the original grayscale dataset is filtered with a 3-by-3-by-3 median filter, and its complement is obtained. A morphological reconstruction is applied on this latter, so that the regional intensity minima outside the cores are eliminated. A watershed transform produces one catchment basin for each remaining regional minimum.

The parcellation can be modified a posteriori, thanks to a routine to visually assess the quality of the segmentation neuron-by-neuron, and to set additional markers on spuriously assigned branches. Incorrect assignments are usually caused by the presence of branches of neurons whose soma lies outside the acquired dataset. Operationally, this is done thanks to a function within the SENPAI toolkit, implemented to correct the parcellation by adding to the mask of the somata some additional clusters. These allow the definition of separate catchment basins for wrongly assigned branches.

## Testing datasets

The algorithm was tested on datasets acquired with a Nikon A1 confocal microscope (40x objective, excitation length 457 nm, bandwidth 500–550 nm), and a LEICA SP8 STED 3DX (93x objective, pulsed white-light laser 598 nm, pulsed 775 nm depletion laser, bandwidth 605–777 nm). All image stacks were from Purkinje cells within murine cerebella, cleared as in Magliaro et al.³⁰. We evaluated SENPAI's performance in distinguishing both cellular (i.e., neurons) and subcellular (i.e., spines) structures.

The first 40x confocal image is a 512-by-512-by-143 image containing 114 somas (Fig. 2A), while the second one is a 512-by-512-by-139 image containing 103 somas. SENPAI was used on these datasets with a single clustering instance, without Gaussian smoothing. Then, post-processing routines including parcellation and pruning were exploited for isolating single cells.

The 93x STED dataset is a 1024-by-1024-by-35 image in which several sections of neurons can be observed (Fig. 2A). The segmentation with SENPAI was obtained merging two clustering instances with different levels of smoothness (i.e., setting the standard deviations of the 3D Gaussian filter to 0 and 3). Finally, we assigned the dendritic spines to their parent branch.

## Performance assessment

In the following, we report the methodology used to compare the performance of SENPAI with that of HK-Icy, NeuTube, NeuroGPS, Ilastik and manual segmentation. This section of the methodology is not part of the SENPAI pipeline as it was only intended to be used for its validation. First, we describe how the competing toolboxes were employed, then we provide details on how we extracted morphometrics and statistics to be used for benchmarking.

**40x confocal.** The comparisons on the single neuron segmentations obtained with SENPAI, HK-Icy and Ilastik, as well as the tracings obtained with NeuroGPS and NeuTube, were performed on 27 cells.

We provide here the key parameters that had to be set for segmenting those neurons on HK-Icy, and NeuroGPS. For the HK-Means
plugin, the optimal segmentation was achieved by setting the intensity classes to 6 for the confocal datasets. The minimum object size was set to 9000 pixels while the maximum object size was set to 7800000 and 4600000 pixels respectively for the two confocal datasets. The minimum object intensity was set to 0. Further details on the methods and rationale are reported in the Supplementary Information (see Supplementary Fig. 7). The segmentation with Ilastik was obtained using two classes, corresponding to the background and the neurons, and employing the maximum number of features for classification. For NeuroGPS, we set the intensity threshold to the minimum to achieve a dense segmentation. Since NeuTube is a semi-automatic tracing tool, there are no parameters to be set.

**40x confocal: morphometric evaluations and statistical analyses.**
The volumes and areas of the segmented neurons were computed with an ad hoc script in Matlab. Sholl Analysis was performed via Neuroanatomy<sup>83</sup>, a Fiji<sup>84</sup> plugin, whereas the corresponding area under the curve (AUC) was obtained in Matlab.

To evaluate any significant differences of area-to-volume ratio among SENPAI, HK-Icy and Ilastik segmentations, we employed the two-tailed Friedman non-parametric test for paired data. Data obtained from NeuroGPS and NeuTube are not included in the analysis, since they produce tracings with insufficient details on neuron morphology. A two-tailed Friedman non-parametric test for paired data followed by a post-hoc analysis (alpha = 0.05) was used to compare AUCs.

**40x confocal: Skeletonization and Strahler analysis.** SENPAI is a segmentation algorithm which provides volumetric reconstructions of neurons in the form of binary 3D volumes. Since the validation metrics for neuron reconstruction, such as Strahler analysis, are usually designed for assessing the goodness of neuron tracings, i.e., reconstructions in the form of tree-like graphs, we provide a routine for the skeletonization of our segmentations.

Starting from the raw 3D image stack, the binary segmentation of one neuron and the markers of the somata are exploited to produce the skeletonization, in the shape of a Matlab tree structure and of a SWC-like matrix, which is the format usually used to describe a graph or tree as a list of nodes, with their coordinates, diameter, and parent node. After the reduction of the neuron volumetric segmentation to 1-pixel wide curved lines, an ad hoc function converts it into a graph object. For each node the function automatically attributes an identification index. Node diameters are defined based on the intensity of the original image at the node coordinates. The graph is converted to a tree object: cycles are identified and then removed by cutting them where the image intensity is lowest. Finally, the SWC matrix is built by storing each node's identification index, coordinates in space, diameter and the identification index of its parent node.

Starting from the binary segmentation of one neuron and the relative SWC matrix, a function was also implemented to produce the Strahler ordering. Specifically, the functions' output is a matrix storing the statistics computed on: numSegSO (number of segments per SO), numSegSONorm (number of segments per SO, normalized by the total number of segments), segLAve (average segment length per SO), PSnum (coefficients of the linear fit for the normalized number of segments per SO), segDAve (average segment diameter per SO), TOTL (total length of segments), TopoSubLAve (topological subtree size per SO), numBrSO (number of branches per SO), numBrSONorm (number of branches per SO, normalized by the total number of branches), brDAve (average branch diameter per SO), brLAve (average branch length per SO), PBnum (coefficients of the linear fit for the normalized number of branches per SO), normTotL (total dendritic length per SO). The definition of the Strahler order of the segments constituting the whole arborized structure is based on the idea of assigning auxiliary weights to the tree edges, in a way that the minimum path length from each node to the root node, rounded to the floor, will correspond to

the node's SO. The SO of a segment is computed as the mode of the SO of its nodes. The code used to compute the Strahler metrics is also available in the same public repository (https://github.com/cauzzo-s5/SENPAI).

**93x STED.** With HK-Icy, the 93x image was not pre-processed and the number of classes parameter was set to 7. The minimum and the maximum object size, in terms of pixels, were set to 50 and 50000 respectively, while the minimum object intensity was set to 0. The segmentation with Ilastik was obtained using two classes, corresponding to background and neuron, and employing the maximum number of features for classification.

Dendritic spines were manually mapped using the AFNI<sup>85</sup> GUI, which allows marking the centers of each spine detected in the original image with a sphere. For each tool (SENPAI, HK-Icy and Ilastik), the map is used to assess (1) the percentage of spines correctly identified; (2) the percentage of spines correctly identified within the catchment basin defined by the SENPAI parcellation step; (3) the percentage of spines correctly identified and univocally assigned by the algorithm to its parent dendritic branch. For HK-Icy and Ilastik, we consider a spine as assigned by the algorithm if (1) it belongs to the same 3D connected cluster of the dendritic branch, or (2) it is marked with the same label of the dendritic branch after the 3D parcellation.

We compared the area-to-volume ratios (normalized with respect to the ratio computed on manual segmentations) of the objects segmented with three different algorithms (i.e., SENPAI, HK-Icy and Ilastik), by means of a two-tailed Friedman non-parametric test for paired data, followed by a post-hoc multiple comparison analysis.

## Statistics and reproducibility

No statistical method was used to predetermine sample size. The number of neurons from clarified samples for which we reported results and statistics is in line with other similar works in literature (e.g., 13 Purkinje neurons in Vormberg et al.<sup>35,47</sup>, a maximum of 36 neurons segmented by any algorithm for mouse/human neurons in the Gold166 dataset). The experiments were not randomized, and the investigators were not blinded to allocation during experiments because only wildtype genotypes were analyzed.

## Reporting summary

Further information on research design is available in the Nature Portfolio Reporting Summary linked to this article.

## Data availability

Raw microscopy images are made available on zenodo website https://zenodo.org/uploads/10805555, the DataSet<sup>86</sup> Digital Object Identifier being 10.5281/zenodo.10805555. The human/mouse subset from BigNeuron GOLD166 dataset<sup>63</sup> can be downloaded at http://web.biistar.edu.sg/bigneuron/gold166.zip. NeuroGPS dataset was downloaded at https://sourceforge.net/projects/neurogps-tree/files/, as reported in the Code Availability Statement in Quan et al.<sup>35</sup>. Source data are provided with this paper. The data generated in this study and shown in Figs. 4–6 are provided in the Source Data file. The data generated in this study and shown in Supplementary Information Figs. 9–16 are provided in the Source Data file. Source data are provided with this paper.

## Code availability

Matlab code for the SENPAI algorithm is freely available at the following repository: https://github.com/cauzzo-s5/SENPAI.

## References

1. Amunts, K. et al. The human brain project: creating a European research infrastructure to decode the human brain. *Neuron* **92**, 574–581 (2016).
plugin, the optimal segmentation was achieved by setting the intensity classes to 6 for the confocal datasets. The minimum object size was set to 9000 pixels while the maximum object size was set to 7800000 and 4600000 pixels respectively for the two confocal datasets. The minimum object intensity was set to 0. Further details on the methods and rationale are reported in the Supplementary Information (see Supplementary Fig. 7). The segmentation with Ilastik was obtained using two classes, corresponding to the background and the neurons, and employing the maximum number of features for classification. For NeuroGPS, we set the intensity threshold to the minimum to achieve a dense segmentation. Since NeuTube is a semi-automatic tracing tool, there are no parameters to be set.

**40x confocal: morphometric evaluations and statistical analyses.**
The volumes and areas of the segmented neurons were computed with an ad hoc script in Matlab. Sholl Analysis was performed via Neuroanatomy<sup>83</sup>, a Fiji<sup>84</sup> plugin, whereas the corresponding area under the curve (AUC) was obtained in Matlab.

To evaluate any significant differences of area-to-volume ratio among SENPAI, HK-Icy and Ilastik segmentations, we employed the two-tailed Friedman non-parametric test for paired data. Data obtained from NeuroGPS and NeuTube are not included in the analysis, since they produce tracings with insufficient details on neuron morphology. A two-tailed Friedman non-parametric test for paired data followed by a post-hoc analysis (alpha = 0.05) was used to compare AUCs.

**40x confocal: Skeletonization and Strahler analysis.** SENPAI is a segmentation algorithm which provides volumetric reconstructions of neurons in the form of binary 3D volumes. Since the validation metrics for neuron reconstruction, such as Strahler analysis, are usually designed for assessing the goodness of neuron tracings, i.e., reconstructions in the form of tree-like graphs, we provide a routine for the skeletonization of our segmentations.

Starting from the raw 3D image stack, the binary segmentation of one neuron and the markers of the somata are exploited to produce the skeletonization, in the shape of a Matlab tree structure and of a SWC-like matrix, which is the format usually used to describe a graph or tree as a list of nodes, with their coordinates, diameter, and parent node. After the reduction of the neuron volumetric segmentation to 1-pixel wide curved lines, an ad hoc function converts it into a graph object. For each node the function automatically attributes an identification index. Node diameters are defined based on the intensity of the original image at the node coordinates. The graph is converted to a tree object: cycles are identified and then removed by cutting them where the image intensity is lowest. Finally, the SWC matrix is built by storing each node's identification index, coordinates in space, diameter and the identification index of its parent node.

Starting from the binary segmentation of one neuron and the relative SWC matrix, a function was also implemented to produce the Strahler ordering. Specifically, the functions' output is a matrix storing the statistics computed on: numSegSO (number of segments per SO), numSegSOnorm (number of segments per SO, normalized by the total number of segments), segLAve (average segment length per SO), PSnum (coefficients of the linear fit for the normalized number of segments per SO), segDAve (average segment diameter per SO), TOTL (total length of segments), TopoSubLAve (topological subtree size per SO), numBrSO (number of branches per SO), numBrSOnorm (number of branches per SO, normalized by the total number of branches), brDAve (average branch diameter per SO), brLAve (average branch length per SO), PBnum (coefficients of the linear fit for the normalized number of branches per SO), normTotL (total dendritic length per SO). The definition of the Strahler order of the segments constituting the whole arborized structure is based on the idea of assigning auxiliary weights to the tree edges, in a way that the minimum path length from each node to the root node, rounded to the floor, will correspond to

the node's SO. The SO of a segment is computed as the mode of the SO of its nodes. The code used to compute the Strahler metrics is also available in the same public repository (https://github.com/cauzzo-s5/SENPAI).

**93x STED.** With HK-Icy, the 93x image was not pre-processed and the number of classes parameter was set to 7. The minimum and the maximum object size, in terms of pixels, were set to 50 and 50000 respectively, while the minimum object intensity was set to 0. The segmentation with Ilastik was obtained using two classes, corresponding to background and neuron, and employing the maximum number of features for classification.

Dendritic spines were manually mapped using the AFNI<sup>85</sup> GUI, which allows marking the centers of each spine detected in the original image with a sphere. For each tool (SENPAI, HK-Icy and Ilastik), the map is used to assess (1) the percentage of spines correctly identified; (2) the percentage of spines correctly identified within the catchment basin defined by the SENPAI parcellation step; (3) the percentage of spines correctly identified and univocally assigned by the algorithm to its parent dendritic branch. For HK-Icy and Ilastik, we consider a spine as assigned by the algorithm if (1) it belongs to the same 3D connected cluster of the dendritic branch, or (2) it is marked with the same label of the dendritic branch after the 3D parcellation.

We compared the area-to-volume ratios (normalized with respect to the ratio computed on manual segmentations) of the objects segmented with three different algorithms (i.e., SENPAI, HK-Icy and Ilastik), by means of a two-tailed Friedman non-parametric test for paired data, followed by a post-hoc multiple comparison analysis.

## Statistics and reproducibility

No statistical method was used to predetermine sample size. The number of neurons from clarified samples for which we reported results and statistics is in line with other similar works in literature (e.g., 13 Purkinje neurons in Vormberg et al.<sup>35,47</sup>, a maximum of 36 neurons segmented by any algorithm for mouse/human neurons in the Gold166 dataset). The experiments were not randomized, and the investigators were not blinded to allocation during experiments because only wildtype genotypes were analyzed.

## Reporting summary

Further information on research design is available in the Nature Portfolio Reporting Summary linked to this article.

## Data availability

Raw microscopy images are made available on zenodo website https://zenodo.org/uploads/10805555, the DataSet<sup>86</sup> Digital Object Identifier being 10.5281/zenodo.10805555. The human/mouse subset from BigNeuron GOLD166 dataset<sup>63</sup> can be downloaded at http://web.bii.a-star.edu.sg/bigneuron/gold166.zip. NeuroGPS dataset was downloaded at https://sourceforge.net/projects/neurogps-tree/files/, as reported in the Code Availability Statement in Quan et al.<sup>35</sup>. Source data are provided with this paper. The data generated in this study and shown in Figs. 4–6 are provided in the Source Data file. The data generated in this study and shown in Supplementary Information Figs. 9–16 are provided in the Source Data file. Source data are provided with this paper.

## Code availability

Matlab code for the SENPAI algorithm is freely available at the following repository: https://github.com/cauzzo-s5/SENPAI.

## References

1. Amunts, K. et al. The human brain project: creating a European research infrastructure to decode the human brain. *Neuron* **92**, 574–581 (2016).
2. Magliaro, C., Callara, A. L., Vanello, N. & Ahluwalia, A. Gotta trace 'em all: a mini-review on tools and procedures for segmenting single neurons toward deciphering the structural connectome. *Front. Bioeng. Biotechnol.* **7**, 202 (2019).

3. Redolfi, A. et al. Italian, European, and international neuroinformatics efforts: an overview. *Eur. J. Neurosci.* **57**, 2017–2039 (2022).

4. Helmstaedter, M. Cellular-resolution connectomics: challenges of dense neural circuit reconstruction. *Nat. Methods* **10**, 501–507 (2013).

5. Lagache, T. et al. Mapping molecular assemblies with fluorescence microscopy and object-based spatial statistics. *Nat. Commun.* **9**, 698 (2018).

6. García-López, P., Garcia-Marín, V. & Freire, M. The discovery of dendritic spines by Cajal in 1888 and its relevance in the present neuroscience. *Prog. Neurobiol.* **83**, 110–130 (2007).

7. Harris, K. M. Synaptic odyssey. *J. Neurosci.* **40**, 61–80 (2020).

8. Rasia-Filho, A. A., Calcagnotto, M. E. & von Bohlen und Halbach, O. Introduction: what are dendritic spines? *Nature* **34**, 1–68 (2023).

9. Harris, K., Jensen, F. & Tsao, B. Three-dimensional structure of dendritic spines and synapses in rat hippocampus (CA1) at post-natal day 15 and adult ages: implications for the maturation of synaptic physiology and long-term potentiation [published erratum appears in J Neurosci 1992 10 Aug;1. *J. Neurosci.* **12**, 2685–2705 (1992).]

10. Ofer, N., Berger, D. R., Kasthuri, N., Lichtman, J. W. & Yuste, R. Ultrastructural analysis of dendritic spine necks reveals a continuum of spine morphologies. *Dev. Neurobiol.* **81**, 746–757 (2021).

11. Noguchi, J., Matsuzaki, M., Ellis-Davies, G. C. R. & Kasai, H. Spine-neck geometry determines NMDA receptor-dependent Ca2+ signaling in dendrites. *Neuron* **46**, 609–622 (2005).

12. Citri, A. & Malenka, R. C. Synaptic plasticity: multiple forms, functions, and mechanisms. *Neuropsychopharmacology* **33**, 18–41 (2008).

13. Sala, C. & Segal, M. Dendritic spines: the locus of structural and functional plasticity. *Physiol. Rev.* **94**, 141–188 (2014).

14. Knott, G. & Holtmaat, A. Dendritic spine plasticity—current understanding from in vivo studies. *Brain Res. Rev.* **58**, 282–289 (2008).

15. Bourne, J. & Harris, K. M. Do thin spines learn to be mushroom spines that remember? *Curr. Opin. Neurosci.* **17**, 381–386 (2007).

16. Kasai, H. et al. Learning rules and persistence of dendritic spines. *Eur. J. Neurosci.* **32**, 241–249 (2010).

17. Spires, T. L. Dendritic spine abnormalities in amyloid precursor protein transgenic mice demonstrated by gene transfer and intravital multiphoton microscopy. *J. Neurosci.* **25**, 7278–7287 (2005).

18. Penzes, P., Cahill, M. E., Jones, K. A., VanLeeuwen, J.-E. & Woolfrey, K. M. Dendritic spine pathology in neuropsychiatric disorders. *Nat. Neurosci.* **14**, 285–293 (2011).

19. Glausier, J. R. & Lewis, D. A. Dendritic spine pathology in schizophrenia. *Neuroscience* **251**, 90–107 (2013).

20. Serrano-Pozo, A., Frosch, M. P., Masliah, E. & Hyman, B. T. Neuro-pathological alterations in Alzheimer disease. *Cold Spring Harb. Perspect. Med.* **1**, a006189 (2011).

21. Scheff, S. W., Price, D. A., Schmitt, F. A. & Mufson, E. J. Hippocampal synaptic loss in early Alzheimer's disease and mild cognitive impairment. *Neurobiol. Aging* **27**, 1372–1384 (2006).

22. Nwaneshiuhu, A. et al. Introduction to confocal microscopy. *J. Invest. Dermatol.* **132**, 1–5 (2012).

23. Helmchen, F. & Denk, W. Deep tissue two-photon microscopy. *Nat. Methods* **2**, 932–940 (2005).

24. Schermelleh, L., Heintzmann, R. & Leonhardt, H. A guide to super-resolution fluorescence microscopy. *J. Cell Biol.* **190**, 165–175 (2010).

25. Collot, M. et al. MemBright: A family of fluorescent membrane probes for advanced cellular imaging and neuroscience. *Cell Chem. Biol.* **26**, 600–614.e7 (2019).

26. Godin, A. G., Lounis, B. & Cognet, L. Super-resolution microscopy approaches for live cell imaging. *Biophys. J.* **107**, 1777–1784 (2014).

27. Hell, S. W. & Wichmann, J. Breaking the diffraction resolution limit by stimulated emission: stimulated-emission-depletion fluorescence microscopy. *Opt. Lett.* **19**, 780 (1994).

28. Wegel, E. et al. Imaging cellular structures in super-resolution with SIM, STED and localisation microscopy: a practical comparison. *Sci. Rep.* **6**, 27290 (2016).

29. Chung, K. & Deisseroth, K. CLARITY for mapping the nervous system. *Nat. Methods* **10**, 508–513 (2013).

30. Magliaro, C. et al. Clarifying CLARITY: quantitative optimization of the diffusion based delipidation protocol for genetically labeled tissue. *Front. Neurosci.* **10**, 179 (2016).

31. Liu, Y., Wang, G., Ascoli, G. A., Zhou, J. & Liu, L. Neuron tracing from light microscopy images: automation, deep learning and bench testing. *Bioinformatics* **38**, 5329–5339 (2022).

32. Li, R. et al. Precise segmentation of densely interweaving neuron clusters using G-cut. *Nat. Commun.* **10**, 1549 (2019).

33. Peng, H. et al. Automatic tracing of ultra-volumes of neuronal images. *Nat. Methods* **14**, 332–333 (2017).

34. Callara, A. L., Magliaro, C., Ahluwalia, A. & Vanello, N. A smart region-growing algorithm for single-neuron segmentation from confocal and 2-photon datasets. *Front. Neuroinform.* **14**, 9 (2020).

35. Quan, T. et al. NeuroGPS-Tree: automatic reconstruction of large-scale neuronal populations with dense neurites. *Nat. Methods* **13**, 51–54 (2016).

36. Milligan, K., Balwani, A. & Dyer, E. Brain mapping at high resolutions: challenges and opportunities. *Curr. Opin. Biomed. Eng.* **12**, 126–131 (2019).

37. Chen, R., Liu, M., Chen, W., Wang, Y. & Meijering, E. Deep learning in mesoscale brain image analysis: a review. *Comput. Biol. Med.* **167**, 107617 (2023).

38. Mazzamuto, G. et al. Automatic segmentation of neurons in 3D samples of human brain cortex. *Applications of Evolutionary Computation: 21st International Conference EvoApplications* **78–85** (2018).

39. Ghahremani, P. et al. NeuroConstruct: 3D reconstruction and visualization of neurites in optical microscopy brain images. *IEEE Trans. Vis. Comput. Graph.* **28**, 4951–4965 (2021).

40. Nourbakhsh, F. et al. Neural cell segmentation in large-scale 3D color fluorescence microscopy images for developmental neuroscience. in *2018 25th IEEE International Conference on Image Processing (ICIP)* 3828–3832 (2018).

41. Stuckner, J., Harder, B. & Smith, T. M. Microstructure segmentation with deep learning encoders pre-trained on a large microscopy dataset. *npj Comput. Mater.* **8**, 200 (2022).

42. von Chamier, L. et al. Democratising deep learning for microscopy with ZeroCostDL4Mic. *Nat. Commun.* **12**, 2276 (2021).

43. Liu, Z. & Xu, F. Interpretable neural networks: principles and applications. *Front. Artif. Intell.* **6**, 974295 (2023).

44. Manubens-Gil, L. et al. BigNeuron: a resource to benchmark and predict performance of algorithms for automated tracing of neurons in light microscopy datasets. *Nat. Methods* **20**, 824–835 (2023).

45. Pesce, L. et al. Exploring the human cerebral cortex using confocal microscopy. *Prog. Biophys. Mol. Biol.* **168**, 3–9 (2022).

46. Ueda, H. R. et al. Tissue clearing and its applications in neuroscience. *Nat. Rev. Neurosci.* **21**, 61–79 (2020).

47. Vormberg, A., Effenberger, F., Muellerleile, J. & Cuntz, H. Universal features of dendrites through centripetal branch ordering. *PLOS Comput. Biol.* **13**, e1005615 (2017).

48. Feher, J. Balance and control of movement. in *Quantitative Human Physiology* 341–353 (Elsevier, 2012) https://doi.org/10.1016/B978-0-12-382163-8.00037-2.

49. Vincent, L. Morphological grayscale reconstruction in image analysis: applications and efficient algorithms. *IEEE Trans. Image Process.* **2**, 176–201 (1993).
2. Magliaro, C., Callara, A. L., Vanello, N. & Ahluwalia, A. Gotta trace 'em all: a mini-review on tools and procedures for segmenting single neurons toward deciphering the structural connectome. *Front. Bioeng. Biotechnol.* **7**, 202 (2019).

3. Redolfi, A. et al. Italian, European, and international neuroinformatics efforts: an overview. *Eur. J. Neurosci.* **57**, 2017–2039 (2022).

4. Helmstaedter, M. Cellular-resolution connectomics: challenges of dense neural circuit reconstruction. *Nat. Methods* **10**, 501–507 (2013).

5. Lagache, T. et al. Mapping molecular assemblies with fluorescence microscopy and object-based spatial statistics. *Nat. Commun.* **9**, 698 (2018).

6. García-López, P., Garcia-Marín, V. & Freire, M. The discovery of dendritic spines by Cajal in 1888 and its relevance in the present neuroscience. *Prog. Neurobiol.* **83**, 110–130 (2007).

7. Harris, K. M. Synaptic odyssey. *J. Neurosci.* **40**, 61–80 (2020).

8. Rasia-Filho, A. A., Calcagnotto, M. E. & von Bohlen und Halbach, O. Introduction: what are dendritic spines? *Nature* **34**, 1–68 (2023).

9. Harris, K., Jensen, F. & Tsao, B. Three-dimensional structure of dendritic spines and synapses in rat hippocampus (CA1) at post-natal day 15 and adult ages: implications for the maturation of synaptic physiology and long-term potentiation [published erratum appears in J Neurosci 1992 10 Aug;1. *J. Neurosci.* **12**, 2685–2705 (1992).]

10. Ofer, N., Berger, D. R., Kasthuri, N., Lichtman, J. W. & Yuste, R. Ultrastructural analysis of dendritic spine necks reveals a continuum of spine morphologies. *Dev. Neurobiol.* **81**, 746–757 (2021).

11. Noguchi, J., Matsuzaki, M., Ellis-Davies, G. C. R. & Kasai, H. Spine-neck geometry determines NMDA receptor-dependent Ca2+ signaling in dendrites. *Neuron* **46**, 609–622 (2005).

12. Citri, A. & Malenka, R. C. Synaptic plasticity: multiple forms, functions, and mechanisms. *Neuropsychopharmacology* **33**, 18–41 (2008).

13. Sala, C. & Segal, M. Dendritic spines: the locus of structural and functional plasticity. *Physiol. Rev.* **94**, 141–188 (2014).

14. Knott, G. & Holtmaat, A. Dendritic spine plasticity—current understanding from in vivo studies. *Brain Res. Rev.* **58**, 282–289 (2008).

15. Bourne, J. & Harris, K. M. Do thin spines learn to be mushroom spines that remember? *Curr. Opin. Neurosci.* **17**, 381–386 (2007).

16. Kasai, H. et al. Learning rules and persistence of dendritic spines. *Eur. J. Neurosci.* **32**, 241–249 (2010).

17. Spires, T. L. Dendritic spine abnormalities in amyloid precursor protein transgenic mice demonstrated by gene transfer and intravital multiphoton microscopy. *J. Neurosci.* **25**, 7278–7287 (2005).

18. Penzes, P., Cahill, M. E., Jones, K. A., VanLeeuwen, J.-E. & Woolfrey, K. M. Dendritic spine pathology in neuropsychiatric disorders. *Nat. Neurosci.* **14**, 285–293 (2011).

19. Glausier, J. R. & Lewis, D. A. Dendritic spine pathology in schizophrenia. *Neuroscience* **251**, 90–107 (2013).

20. Serrano-Pozo, A., Frosch, M. P., Masliah, E. & Hyman, B. T. Neuro-pathological alterations in Alzheimer disease. *Cold Spring Harb. Perspect. Med.* **1**, a006189 (2011).

21. Scheff, S. W., Price, D. A., Schmitt, F. A. & Mufson, E. J. Hippocampal synaptic loss in early Alzheimer's disease and mild cognitive impairment. *Neurobiol. Aging* **27**, 1372–1384 (2006).

22. Nwaneshiu du, A. et al. Introduction to confocal microscopy. *J. Invest. Dermatol.* **132**, 1–5 (2012).

23. Helmchen, F. & Denk, W. Deep tissue two-photon microscopy. *Nat. Methods* **2**, 932–940 (2005).

24. Schermelleh, L., Heintzmann, R. & Leonhardt, H. A guide to super-resolution fluorescence microscopy. *J. Cell Biol.* **190**, 165–175 (2010).

25. Collot, M. et al. MemBright: A family of fluorescent membrane probes for advanced cellular imaging and neuroscience. *Cell Chem. Biol.* **26**, 600–614.e7 (2019).

26. Godin, A. G., Lounis, B. & Cognet, L. Super-resolution microscopy approaches for live cell imaging. *Biophys. J.* **107**, 1777–1784 (2014).

27. Hell, S. W. & Wichmann, J. Breaking the diffraction resolution limit by stimulated emission: stimulated-emission-depletion fluorescence microscopy. *Opt. Lett.* **19**, 780 (1994).

28. Wegel, E. et al. Imaging cellular structures in super-resolution with SIM, STED and localisation microscopy: a practical comparison. *Sci. Rep.* **6**, 27290 (2016).

29. Chung, K. & Deisseroth, K. CLARITY for mapping the nervous system. *Nat. Methods* **10**, 508–513 (2013).

30. Magliaro, C. et al. Clarifying CLARITY: quantitative optimization of the diffusion based delipidation protocol for genetically labeled tissue. *Front. Neurosci.* **10**, 179 (2016).

31. Liu, Y., Wang, G., Ascoli, G. A., Zhou, J. & Liu, L. Neuron tracing from light microscopy images: automation, deep learning and bench testing. *Bioinformatics* **38**, 5329–5339 (2022).

32. Li, R. et al. Precise segmentation of densely interweaving neuron clusters using G-cut. *Nat. Commun.* **10**, 1549 (2019).

33. Peng, H. et al. Automatic tracing of ultra-volumes of neuronal images. *Nat. Methods* **14**, 332–333 (2017).

34. Callara, A. L., Magliaro, C., Ahluwalia, A. & Vanello, N. A smart region-growing algorithm for single-neuron segmentation from confocal and 2-photon datasets. *Front. Neuroinform.* **14**, 9 (2020).

35. Quan, T. et al. NeuroGPS-Tree: automatic reconstruction of large-scale neuronal populations with dense neurites. *Nat. Methods* **13**, 51–54 (2016).

36. Milligan, K., Balwani, A. & Dyer, E. Brain mapping at high resolutions: challenges and opportunities. *Curr. Opin. Biomed. Eng.* **12**, 126–131 (2019).

37. Chen, R., Liu, M., Chen, W., Wang, Y. & Meijering, E. Deep learning in mesoscale brain image analysis: a review. *Comput. Biol. Med.* **167**, 107617 (2023).

38. Mazzamuto, G. et al. Automatic segmentation of neurons in 3D samples of human brain cortex. *Applications of Evolutionary Computation: 21st International Conference EvoApplications* **78–85** (2018).

39. Ghahremani, P. et al. NeuroConstruct: 3D reconstruction and visualization of neurites in optical microscopy brain images. *IEEE Trans. Vis. Comput. Graph.* **28**, 4951–4965 (2021).

40. Nourbakhsh, F. et al. Neural cell segmentation in large-scale 3D color fluorescence microscopy images for developmental neuroscience. in *2018 25th IEEE International Conference on Image Processing (ICIP)* 3828–3832 (2018).

41. Stuckner, J., Harder, B. & Smith, T. M. Microstructure segmentation with deep learning encoders pre-trained on a large microscopy dataset. *npj Comput. Mater.* **8**, 200 (2022).

42. von Chamier, L. et al. Democratising deep learning for microscopy with ZeroCostDL4Mic. *Nat. Commun.* **12**, 2276 (2021).

43. Liu, Z. & Xu, F. Interpretable neural networks: principles and applications. *Front. Artif. Intell.* **6**, 974295 (2023).

44. Manubens-Gil, L. et al. BigNeuron: a resource to benchmark and predict performance of algorithms for automated tracing of neurons in light microscopy datasets. *Nat. Methods* **20**, 824–835 (2023).

45. Pesce, L. et al. Exploring the human cerebral cortex using confocal microscopy. *Prog. Biophys. Mol. Biol.* **168**, 3–9 (2022).

46. Ueda, H. R. et al. Tissue clearing and its applications in neuroscience. *Nat. Rev. Neurosci.* **21**, 61–79 (2020).

47. Vormberg, A., Effenberger, F., Muellerleile, J. & Cuntz, H. Universal features of dendrites through centripetal branch ordering. *PLOS Comput. Biol.* **13**, e1005615 (2017).

48. Feher, J. Balance and control of movement. in *Quantitative Human Physiology* 341–353 (Elsevier, 2012) https://doi.org/10.1016/B978-0-12-382163-8.00037-2.

49. Vincent, L. Morphological grayscale reconstruction in image analysis: applications and efficient algorithms. *IEEE Trans. Image Process.* **2**, 176–201 (1993).
50. Najman, L. & Schmitt, M. Geodesic saliency of watershed contours and hierarchical segmentation. *IEEE Trans. Pattern Anal. Mach. Intell.* **18**, 1163-1173 (1996).

51. Dufour, A., Meas-Yedid, V., Grassart, A. & Olivo-Marin, J.-C. Automated quantification of cell endocytosis using active contours and wavelets. in *2008 19th International Conference on Pattern Recognition* 1-4 (IEEE, 2008).

52. de Chaumont, F. et al. Icy: an open bioimage informatics platform for extended reproducible research. *Nat. Methods* **9**, 690-696 (2012).

53. Berg, S. et al. ilastik: interactive machine learning for (bio)image analysis. *Nat. Methods* **16**, 1226-1232 (2019).

54. Feng, L., Zhao, T. & Kim, J. neuTube 1.0: A new design for efficient neuron reconstruction software based on the SWC format. *eneuro* **2**, ENEURO.0049-14.2014 (2015).

55. Sholl, D. A. The organization of the visual cortex in the cat. *J. Anat.* **89**, 33-46 (1955).

56. Hirano, T. Purkinje neurons: development, morphology, and function. *Cerebellum* **17**, 699-700 (2018).

57. Ascoli, G. A., Donohue, D. E. & Halavi, M. NeuroMorpho.Org: A central resource for neuronal Morphologies. *J. Neurosci.* **27**, 9247-9251 (2007).

58. Ledderose, J., Sención, L., Salgado, H., Arias-Carrión, O. & Treviño, M. A software tool for the analysis of neuronal morphology data. *Int. Arch. Med.* **7**, 6 (2014).

59. Nanda, S., Bhattacharjee, S., Cox, D. N. & Ascoli, G. A. Distinct relations of microtubules and actin filaments with dendritic architecture. *iScience* **23**, 101865 (2020).

60. Magliaro, C., Callara, A. L., Vanello, N. & Ahluwalia, A. A manual segmentation tool for three-dimensional neuron datasets. *Front. Neuroinform.* **11**, 36 (2017).

61. Dice, L. R. Measures of the amount of ecologic association between species. *Ecology* **26**, 297-302 (1945).

62. Peng, H. et al. BigNeuron: Large-scale 3D neuron reconstruction from optical microscopy images. *Neuron* **87**, 252-256 (2015).

63. Peng, H., Ruan, Z., Long, F., Simpson, J. H. & Myers, E. W. V3D enables real-time 3D visualization and quantitative analysis of large-scale biological image data sets. *Nat. Biotechnol.* **28**, 348-353 (2010).

64. Peng, H., Bria, A., Zhou, Z., Iannello, G. & Long, F. Extensible visualization and analysis for multidimensional images using Vaa3D. *Nat. Protoc.* **9**, 193-208 (2014).

65. Peng, H. et al. Virtual finger boosts three-dimensional imaging and microsurgery as well as terabyte volume image visualization and analysis. *Nat. Commun.* **5**, 4342 (2014).

66. DeFelipe, J. From the connectome to the synaptome: an epic love story. *Science* **330**, 1198-1201 (2010).

67. Tønnesen, J., Katona, G., Rózsa, B. & Nägerl, U. V. Spine neck plasticity regulates compartmentalization of synapses. *Nat. Neurosci.* **17**, 678-685 (2014).

68. Nägerl, U. V., Willig, K. I., Hein, B., Hell, S. W. & Bonhoeffer, T. Live-cell imaging of dendritic spines by STED microscopy. *Proc. Natl Acad. Sci.* **105**, 18982-18987 (2008).

69. Pfeiffer, T. et al. Chronic 2P-STED imaging reveals high turnover of dendritic spines in the hippocampus in vivo. *Elife* **7**, e34700 (2018).

70. Tønnesen, J. & Nägerl, U. V. Dendritic spines as tunable regulators of synaptic signals. *Front. Psychiatry* **7**, 101 (2016).

71. Luengo-Sanchez, S. et al. 3D morphology-based clustering and simulation of human pyramidal cell dendritic spines. *PLOS Comput. Biol.* **14**, e1006221 (2018).

72. Benavides-Piccione, R., Fernaud-Espinosa, I., Robles, V., Yuste, R. & DeFelipe, J. Age-based comparison of human dendritic spine structure using complete three-dimensional reconstructions. *Cereb. Cortex* **23**, 1798-1810 (2013).

73. Ganesan, P. & Sajiv, G. A comprehensive study of edge detection for image processing applications. in *2017 International Conference on Innovations in Information, Embedded and Communication Systems (ICIIECS)* 1-6 (IEEE, 2017).

74. Lakshmi, S. & Sankaranarayanan, D. V. A study of edge detection techniques for segmentation computing approaches. *Int. J. Comput. Appl.* **CASCT**, 35-41 (2010).

75. Jain, S., Mukherjee, S., Danglot, L. & Olivo-Marin, J.-C. Morphological reconstruction of detached dendritic spines via geodesic path prediction. in *2021 IEEE 18th International Symposium on Biomedical Imaging (ISBI)* 944-947 (IEEE, 2021).

76. Erdl, E., OzgurArgunsah, A., Tasdizen, T., Unay, D. & Cetin, M. Combining nonparametric spatial context priors with nonparametric shape priors for dendritic spine segmentation in 2-photon microscopy images. in *2019 IEEE 16th International Symposium on Biomedical Imaging (ISBI 2019)* 204-207 (IEEE, 2019).

77. Rodriguez, A., Ehlenberger, D. B., Dickstein, D. L., Hof, P. R. & Wearne, S. L. Automated three-dimensional detection and shape classification of dendritic spines from fluorescence microscopy images. *PLoS One* **3**, e1997 (2008).

78. Su, R., Sun, C., Zhang, C. & Pham, T. D. A novel method for dendritic spines detection based on directional morphological filter and shortest path. *Comput. Med. Imaging Graph.* **38**, 793-802 (2014).

79. Cheng, J. et al. A novel computational approach for automatic dendritic spines detection in two-photon laser scan microscopy. *J. Neurosci.* **Methods** **165**, 122-134 (2007).

80. Hotulainen, P. & Lappalainen, P. Stress fibers are generated by two distinct actin assembly mechanisms in motile cells. *J. Cell Biol.* **173**, 383-394 (2006).

81. Lloyd, S. Least squares quantization in PCM. *IEEE Trans. Inf. Theory* **28**, 129-137 (1982).

82. Sternberg Biomedical image processing. *Computer* **16**, 22-34 (1983).

83. Ferreira, T. A. et al. Neuronal morphometry directly from bitmap images. *Nat. Methods* **11**, 982-984 (2014).

84. Schindelin, J. et al. Fiji: an open-source platform for biological-image analysis. *Nat. Methods* **9**, 676-682 (2012).

85. Cox, R. W. AFNI: software for analysis and visualization of functional magnetic resonance neuroimages. *Comput. Biomed. Res.* **29**, 162-173 (1996).

86. Cauzzo, S. et al. Open data regarding paper: 'A modular framework for multi-scale tissue imaging and neuronal segmentation'. *Nat. Commun.* https://doi.org/10.5281/zenodo.10805555 (2024).

87. Radojević, M. & Meijering, E. Automated neuron reconstruction from 3D fluorescence microscopy images using sequential monte carlo estimation. *Neuroinformatics* **17**, 423-442 (2019).

## Acknowledgements

We would like to thank the Neurlmag Imaging core Facility team (part of IPNP, Inserm U. 1266 and Université Paris Cité) and member of the national infrastructure France-Biolmaging supported by the French National Research Agency (ANR-10-INBS-04) for their technical and scientific support. We thank the Leducq foundation for supporting the acquisition of the Leica SP8 Confocal/STED 3DX microscope. E.B., D.B. and P.N. were supported by the FLAG-ERA (grant Sensei by ANR-19-HBPR-0003 and MUR provvedimento n. 1637, 19/10/2020, CUP: I54119002660006). A.L.C. was supported by the European Union—Next Generation EU, in the context of The National Recovery and Resilience Plan, Investment 1.5 Ecosystems of Innovation, Project Tuscany Health Ecosystem (THE), Spoke 3 “Advanced technologies, methods, materials and heath analytics” CUP: I53C22000780001. This work was funded by the French National Research Agency (ANR) ANR-19-CE16-0012 (to LD), and by FLAG-ERA (grant SENSEI by ANR-19-HBPR-0003 and MUR- CUP: I54119002660006) to L.D. and N.V.
50. Najman, L. & Schmitt, M. Geodesic saliency of watershed contours and hierarchical segmentation. *IEEE Trans. Pattern Anal. Mach. Intell.* **18**, 1163–1173 (1996).

51. Dufour, A., Meas-Yedid, V., Grassart, A. & Olivo-Marin, J.-C. Automated quantification of cell endocytosis using active contours and wavelets. in *2008 19th International Conference on Pattern Recognition* 1–4 (IEEE, 2008).

52. de Chaumont, F. et al. Icy: an open bioimage informatics platform for extended reproducible research. *Nat. Methods* **9**, 690–696 (2012).

53. Berg, S. et al. ilastik: interactive machine learning for (bio)image analysis. *Nat. Methods* **16**, 1226–1232 (2019).

54. Feng, L., Zhao, T. & Kim, J. neuTube 1.0: A new design for efficient neuron reconstruction software based on the SWC format. *eneuro* **2**, ENEURO.0049–14.2014 (2015).

55. Sholl, D. A. The organization of the visual cortex in the cat. *J. Anat.* **89**, 33–46 (1955).

56. Hirano, T. Purkinje neurons: development, morphology, and function. *Cerebellum* **17**, 699–700 (2018).

57. Ascoli, G. A., Donohue, D. E. & Halavi, M. NeuroMorpho.Org: A central resource for neuronal Morphologies. *J. Neurosci.* **27**, 9247–9251 (2007).

58. Ledderose, J., Sención, L., Salgado, H., Arias-Carrión, O. & Treviño, M. A software tool for the analysis of neuronal morphology data. *Int. Arch. Med.* **7**, 6 (2014).

59. Nanda, S., Bhattacharjee, S., Cox, D. N. & Ascoli, G. A. Distinct relations of microtubules and actin filaments with dendritic architecture. *iScience* **23**, 101865 (2020).

60. Magliaro, C., Callara, A. L., Vanello, N. & Ahluwalia, A. A manual segmentation tool for three-dimensional neuron datasets. *Front. Neuroinform.* **11**, 36 (2017).

61. Dice, L. R. Measures of the amount of ecologic association between species. *Ecology* **26**, 297–302 (1945).

62. Peng, H. et al. BigNeuron: Large-scale 3D neuron reconstruction from optical microscopy images. *Neuron* **87**, 252–256 (2015).

63. Peng, H., Ruan, Z., Long, F., Simpson, J. H. & Myers, E. W. V3D enables real-time 3D visualization and quantitative analysis of large-scale biological image data sets. *Nat. Biotechnol.* **28**, 348–353 (2010).

64. Peng, H., Bria, A., Zhou, Z., Iannello, G. & Long, F. Extensible visualization and analysis for multidimensional images using Vaa3D. *Nat. Protoc.* **9**, 193–208 (2014).

65. Peng, H. et al. Virtual finger boosts three-dimensional imaging and microsurgery as well as terabyte volume image visualization and analysis. *Nat. Commun.* **5**, 4342 (2014).

66. DeFelipe, J. From the connectome to the synaptome: an epic love story. *Science* **330**, 1198–1201 (2010).

67. Tønnesen, J., Katona, G., Rózsa, B. & Nägerl, U. V. Spine neck plasticity regulates compartmentalization of synapses. *Nat. Neurosci.* **17**, 678–685 (2014).

68. Nägerl, U. V., Willig, K. I., Hein, B., Hell, S. W. & Bonhoeffer, T. Live-cell imaging of dendritic spines by STED microscopy. *Proc. Natl Acad. Sci.* **105**, 18982–18987 (2008).

69. Pfeiffer, T. et al. Chronic 2P-STED imaging reveals high turnover of dendritic spines in the hippocampus in vivo. *Elife* **7**, e34700 (2018).

70. Tønnesen, J. & Nägerl, U. V. Dendritic spines as tunable regulators of synaptic signals. *Front. Psychiatry* **7**, 101 (2016).

71. Luengo-Sanchez, S. et al. 3D morphology-based clustering and simulation of human pyramidal cell dendritic spines. *PLOS Comput. Biol.* **14**, e1006221 (2018).

72. Benavides-Piccione, R., Fernaud-Espinosa, I., Robles, V., Yuste, R. & DeFelipe, J. Age-based comparison of human dendritic spine structure using complete three-dimensional reconstructions. *Cereb. Cortex* **23**, 1798–1810 (2013).

73. Ganesan, P. & Sajiv, G. A comprehensive study of edge detection for image processing applications. in *2017 International Conference on Innovations in Information, Embedded and Communication Systems (ICIIECS)* 1–6 (IEEE, 2017).

74. Lakshmi, S. & Sankaranarayanan, D. V. A study of edge detection techniques for segmentation computing approaches. *Int. J. Comput. Appl.* **CASCT**, 35–41 (2010).

75. Jain, S., Mukherjee, S., Danglot, L. & Olivo-Marin, J.-C. Morphological reconstruction of detached dendritic spines via geodesic path prediction. in *2021 IEEE 18th International Symposium on Biomedical Imaging (ISBI)* 944–947 (IEEE, 2021).

76. Erdl, E., OzgurArgunsah, A., Tasdizen, T., Unay, D. & Cetin, M. Combining nonparametric spatial context priors with nonparametric shape priors for dendritic spine segmentation in 2-photon microscopy images. in *2019 IEEE 16th International Symposium on Biomedical Imaging (ISBI 2019)* 204–207 (IEEE, 2019).

77. Rodriguez, A., Ehlenberger, D. B., Dickstein, D. L., Hof, P. R. & Wearne, S. L. Automated three-dimensional detection and shape classification of dendritic spines from fluorescence microscopy images. *PLoS One* **3**, e1997 (2008).

78. Su, R., Sun, C., Zhang, C. & Pham, T. D. A novel method for dendritic spines detection based on directional morphological filter and shortest path. *Comput. Med. Imaging Graph.* **38**, 793–802 (2014).

79. Cheng, J. et al. A novel computational approach for automatic dendritic spines detection in two-photon laser scan microscopy. *J. Neurosci.* **Methods** **165**, 122–134 (2007).

80. Hotulainen, P. & Lappalainen, P. Stress fibers are generated by two distinct actin assembly mechanisms in motile cells. *J. Cell Biol.* **173**, 383–394 (2006).

81. Lloyd, S. Least squares quantization in PCM. *IEEE Trans. Inf. Theory* **28**, 129–137 (1982).

82. Sternberg Biomedical image processing. *Computer* **16**, 22–34 (1983).

83. Ferreira, T. A. et al. Neuronal morphometry directly from bitmap images. *Nat. Methods* **11**, 982–984 (2014).

84. Schindelin, J. et al. Fiji: an open-source platform for biological-image analysis. *Nat. Methods* **9**, 676–682 (2012).

85. Cox, R. W. AFNI: software for analysis and visualization of functional magnetic resonance neuroimages. *Comput. Biomed. Res.* **29**, 162–173 (1996).

86. Cauzzo, S. et al. Open data regarding paper: 'A modular framework for multi-scale tissue imaging and neuronal segmentation'. *Nat. Commun.* https://doi.org/10.5281/zenodo.10805555 (2024).

87. Radojević, M. & Meijering, E. Automated neuron reconstruction from 3D fluorescence microscopy images using sequential monte carlo estimation. *Neuroinformatics* **17**, 423–442 (2019).

## Acknowledgements

We would like to thank the NeurImag Imaging core Facility team (part of IPNP, Inserm U. 1266 and Université Paris Cité) and member of the national infrastructure France-Biolmaging supported by the French National Research Agency (ANR-10-INBS-04) for their technical and scientific support. We thank the Leducq foundation for supporting the acquisition of the Leica SP8 Confocal/STED 3DX microscope. E.B., D.B. and P.N. were supported by the FLAG-ERA (grant Sensei by ANR-19-HBPR-0003 and MUR provvedimento n. 1637, 19/10/2020, CUP: I54119002660006). A.L.C. was supported by the European Union—Next Generation EU, in the context of The National Recovery and Resilience Plan, Investment 1.5 Ecosystems of Innovation, Project Tuscany Health Ecosystem (THE), Spoke 3 "Advanced technologies, methods, materials and heath analytics" CUP: I53C22000780001. This work was funded by the French National Research Agency (ANR) ANR-19-CE16-0012 (to LD), and by FLAG-ERA (grant SENSEI by ANR-19-HBPR-0003 and MUR- CUP: I54119002660006) to L.D. and N.V.
## Author contributions

S.C., C.M., L.D. and N.V. conceived and designed the study. S.C., E.B., D.B., P.N. A.L.C., A.A., C.M. and L.D. handled data curation. S.C., E.B., P.N., M.B., A.L.C., F.T. and L.D. carried out formal analysis. S.C., E.B., A.L.C. and N.V. designed the methodology for segmentation algorithm and statistical tools development. D.B., P.N., C.M. and L.D. designed the methodology for sample processing. S.C., E.B., D.B., P.N., M.B., A.L.C., C.M. and L.D. carried out the investigation. S.C., E.B. and A.L.C designed the software. S.C., E.B., P.N, M.B., A.L.C., F.T., L.D. and N.V. worked on validation. S.C., E.B., D.B., P.N. and M.B. worked on data and results visualization. S.C. and E.B. prepared the original draft. S.C., E.B., A.L.C., A.A., C.M., L.D. and N.V. edited and revised the manuscript. A.A., C.M., L.D. and N.V. managed resources and funding acquisition. C.M., L.D. and N.V. curated project administration. L.D. and N.V. supervised the study.

## Competing interests

The authors declare no competing interests.

## Ethics

This research complies with all relevant national and international ethical regulations. L7GFP were obtained for a UNIPI project (PRA_2016_56) from the Department of Translational Research, New Technologies in Medicine and Surgery of the University of Pisa (Italy). The study protocol was approved by the Animal Welfare Committee from University of Pisa, specifically Organismo Preposto al Benessere Animale, Unità Etica e tutela animale nella Ricerca, Lungarno Pacinotti 43/44, 56126, Pisa.

## Additional information

**Supplementary information** The online version contains supplementary material available at https://doi.org/10.1038/s41467-024-48146-y.

**Correspondence** and requests for materials should be addressed to Simone Cauzzo, Lydia Danglot or Nicola Vanello.

**Peer review information** *Nature Communications* thanks Martin Fuhrmann, and the other, anonymous, reviewer(s) for their contribution to the peer review of this work. A peer review file is available.

**Reprints and permissions information** is available at http://www.nature.com/reprints

**Publisher's note** Springer Nature remains neutral with regard to jurisdictional claims in published maps and institutional affiliations.

**Open Access** This article is licensed under a Creative Commons Attribution 4.0 International License, which permits use, sharing, adaptation, distribution and reproduction in any medium or format, as long as you give appropriate credit to the original author(s) and the source, provide a link to the Creative Commons licence, and indicate if changes were made. The images or other third party material in this article are included in the article's Creative Commons licence, unless indicated otherwise in a credit line to the material. If material is not included in the article's Creative Commons licence and your intended use is not permitted by statutory regulation or exceeds the permitted use, you will need to obtain permission directly from the copyright holder. To view a copy of this licence, visit http://creativecommons.org/licenses/by/4.0/.

© The Author(s) 2024
## Author contributions

S.C., C.M., L.D. and N.V. conceived and designed the study. S.C., E.B., D.B., P.N. A.L.C., A.A., C.M. and L.D. handled data curation. S.C., E.B., P.N., M.B., A.L.C., F.T. and L.D. carried out formal analysis. S.C., E.B., A.L.C. and N.V. designed the methodology for segmentation algorithm and statistical tools development. D.B., P.N., C.M. and L.D. designed the methodology for sample processing. S.C., E.B., D.B., P.N., M.B., A.L.C., C.M. and L.D. carried out the investigation. S.C., E.B. and A.L.C designed the software. S.C., E.B., P.N, M.B., A.L.C., F.T., L.D. and N.V. worked on validation. S.C., E.B., D.B., P.N. and M.B. worked on data and results visualization. S.C. and E.B. prepared the original draft. S.C., E.B., A.L.C., A.A., C.M., L.D. and N.V. edited and revised the manuscript. A.A., C.M., L.D. and N.V. managed resources and funding acquisition. C.M., L.D. and N.V. curated project administration. L.D. and N.V. supervised the study.

## Competing interests

The authors declare no competing interests.

## Ethics

This research complies with all relevant national and international ethical regulations. L7GFP were obtained for a UNIPI project (PRA_2016_56) from the Department of Translational Research, New Technologies in Medicine and Surgery of the University of Pisa (Italy). The study protocol was approved by the Animal Welfare Committee from University of Pisa, specifically Organismo Preposto al Benessere Animale, Unità Etica e tutela animale nella Ricerca, Lungarno Pacinotti 43/44, 56126, Pisa.

## Additional information

**Supplementary information** The online version contains supplementary material available at https://doi.org/10.1038/s41467-024-48146-y.

**Correspondence** and requests for materials should be addressed to Simone Cauzzo, Lydia Danglot or Nicola Vanello.

**Peer review information** *Nature Communications* thanks Martin Fuhrmann, and the other, anonymous, reviewer(s) for their contribution to the peer review of this work. A peer review file is available.

**Reprints and permissions information** is available at http://www.nature.com/reprints

**Publisher's note** Springer Nature remains neutral with regard to jurisdictional claims in published maps and institutional affiliations.

**Open Access** This article is licensed under a Creative Commons Attribution 4.0 International License, which permits use, sharing, adaptation, distribution and reproduction in any medium or format, as long as you give appropriate credit to the original author(s) and the source, provide a link to the Creative Commons licence, and indicate if changes were made. The images or other third party material in this article are included in the article's Creative Commons licence, unless indicated otherwise in a credit line to the material. If material is not included in the article's Creative Commons licence and your intended use is not permitted by statutory regulation or exceeds the permitted use, you will need to obtain permission directly from the copyright holder. To view a copy of this licence, visit http://creativecommons.org/licenses/by/4.0/.

© The Author(s) 2024