I was wondering whether anybody has a suggestion how to fill small discontinuities in linear structures in a binary image. The image below shows a binary mask of a neuron with some processes. The magenta circles in the second image show breaks in the linear structures that I would like to fill automatically without fusing linear structures that run in parallel to each other (e.g. a binary close with iteration set to 5 and count set to 3 closes the gaps, but also creates additionally bridges between some of the parallel structures).
I did consider skeletonising the structure, find endpoints and then dilate endpoints to join them. This works for situations where the break is between two endpoints (lower circle). However, it doesn't work for the type of break shown inside the upper circle.
For that I was looking for a method that does a sort of 'directional dilation', i.e. extends/dilates the linear structure in the direction of its 'main direction'. I know that I could use a structural filter element for that, but I would have to define the shape of this, which doesn't really work as the linear structures could run in any direction.
Does anybody have an idea how this could be done?