Fig.2: Main steps of the segmentation procedure.
Mamba-Image is the most comprehensive open-source Mathematical Morphology library written in C and Python. The library is exceptionally well-documented; it also includes numerous code examples for beginners as well as many publication references for advanced users.
Below is Pyhon source code in Jupyter Notebook format. You can download it using this link: Source Code
In the demo code above I show processing results using small images (512 x 512). However, you can process the whole section of the mouse brain in “one shot”, as it is shown in the slide above. Processing of one image 15,000 x 9,000 pixels takes ~ 4 minutes(4-core i7-3770S CPU@3.1GHz).
As it seems (Fig.4, below), this algorithm produces quite acceptable result in different cortical areas of the brain with quite different neuronal density, as well as in the hippocampus, where the neuronal density is much higher.