In a few scans I’m working with, after thresholding and segmenting with brushes/scissors/etc, I wind up with many thousands of small islands in the integument of some insects. Basically, lots of tiny little buts that are the same intensity of the vessels I’m segmenting out, but separate from these features. The islands are typically less than 20 voxels, so removing them using remove small islands is pretty straightforward. The issue is that it is exceedingly slow - it can take hours, depending on how many (upwards of 100000) small specs show up.
I’ve dug into the python for the islands effect a bit, and by scattering print statements to do a very coarse profiling, it appears the slowest part is the modifySegmentByLabelmap() function (implemented in C++), so “refactoring” this is probably non-trivial.
What I’ve wound up doing is making a new segment and picking the larger islands one by one to add to it using Add selected island, but it’s still pretty tedious. I’ve also tried a few filtering and smoothing approaches, but they wind up removing detail on the things I want to keep.
Any ideas anybody has on this for either speeding up removing small islands, or a totally different approach would be most appreciated - Thanks!
It’s definitely remove small islands, not split islands. (Not sure I’ve ever used split islands…)
The same function in SegmentEditorIslandsEffect.py is used for splitting or removing, there’s just a bool to tell the function whether or not to split, so the logic is similar for both. As far as workflow, I basically use a combination of thresholding, thresholded brush, and scissors to pick out lots of air spaces, and in some specimens I get a lot of “noise” - very small islands scattered in the integument (20 voxels or less). Remove small islands does an awesome job removing these, but in some specimens with a LOT of noise, it can take hours.
I’m a little fuzzy on exactly what’s going on as I don’t speak VTK, but it looks like it uses vtkITKIslandMath to identify the islands larger than a particular size (this is the fast part), then makes a new segment and adds the large enough islands in one by one (this is the slow part).
The one call that appears to be taking the longest is towards the end of the function in the loop that adds each island back in. This one here:
There is one other spot that’s a little slow but I’m forgetting what it is right now, and I took out my debug prints for “profiling”. Anyway, please let me know if there’s anything I can do to assist with fixes or testing. I know C++ (and python) but not VTK/ITK.
Hundreds of thousands of speckles are most likely caused by random noise. Islands effect is not optimal for removing it, not just because of the long computation time but also because valid object boundaries will be still corrupted by noise.
Instead, you can suppress noise in the master image using image filtering - see modules: Filtering / Denoising; and Filtering / Simple filters.
You can also remove small speckles without significant loss of details by using Smoothing effect / Median method with a small kernel size.