Skeletonize Remove or Prune short end segments

skeleton-analysis
Tags: #<Tag:0x00007fd541fb9208>

#1

Hi everyone,

I’m trying to use a macro to count the number of intersections or junction points in a starting image. I get the image below after thresholding and dilating to remove noise before running “Skeletonize (2D/3D)”. Afterwards I can analyze with “Analyze Skeleton (2D/3D)” and get the number of junctions in the image.

However, I need to remove the small endpoint noise branches before I run the analyze plugin. Image below shows where I’m at just before analyze plugin, and the small endpoint branches to be removed circled in red. Any help on how to do this would be much appreciated! Thanks!


#2

Hello @Ficus and welcome to the ImageJ forum!

In this post we explained how to remove branches by length using a script. I hope it helps!

ignacio


#3

Thanks ignacio!

Took a bit as I’m new to scripts, but works perfectly now when I call the script manually.

Now trying to call the script from my preexisting ijm macro. I’ve been trying runMacro() and eval functions but keep coming up with errors. Is that the right direction to keep trying or is there a different way?

Thanks!


#4

The easiest way is to put the script into a subfolder of the ./scripts/ directory of your ImageJ installation, so that it will show up in the menu after restarting ImageJ (e.g. ./scripts/MyMenu/My_Pruning_Script.bsh).

You will then be able to record the command with the macro recorder as usual, yielding something like run("My Pruning Script", "image=Skeleton threshold=3.0")


#5

Thanks Jan

I can install like you recommend into ImageJ, but it doesn’t seem to install in Fiji. Unfortunately, I have only gotten the script to work in Fiji (it errors out in ImageJ). No matter what folder I put it in in Fiji directory or if I install it inside Fiji I can’t get it to ever appear as an option in the plugins menu.

I’m guessing I’m doing something stupid wrong?


#6

I forgot to mention that the file name has to contain an underscore _ for ImageJ/Fiji in order to be shown in the menu. (I thought this old requirement for scripts in ./plugins/Scripts had disappeared for the ./scripts/ folder, but I was mistaken.

Also note that the command will appear in any menu corresponding to the sub-folder hierarchy of the script location - i.e. not necessarily in the Plugins menu.


#7

Thanks Jan!!! Underscore fixed it!


#8

@iarganda

While running this script in FIJI, I am continuously getting an error that ImagePlus is required but none exist. How should I solve this issue?

Can this script also help to remove the branches in 3D skeletonised stack or it just works in 2D skeletonised image?

With regards,
Neel


#9

The script expects the binary skeleton image to be open and selected. Is that your case?

It works on both 2D and 3D images.


#10

Hi @iarganda

Thanks a lot for this intelligent script. It has actually refined the results by pruning unwanted branches. I ran that script by opening the binary skeleton image and it worked fine.

I just need to ask one more thing. Is it possible through some script that in pruned skeleton, the cluster of nodes which are creating small branches can be treated as one and the final skeleton will have branches higher than minimum pixel length? It’s the same idea @alessandrofelder tried to implement in Intertrabecular Angle (ITA) Algorithm. The only issue with existing ITA algorithm is it only considers one skeleton at a time. So, I was thinking to use the previous BoneJ>Skeletonize 3D and Analyze Skeleton plugin to perform skeletonization with the additional help of thresholding minimum pixel length.

I hope you understand my query.

With regards,
Neel


#11

What I suggest is you repeat the script until not changes are made on your skeletons. How does it sound?


#12

Well, I am trying that part. I hope it works. It’s just in my images, small cracks are so much, they are shadowing the effect of big length cracks that are small in number. That’s why I thought to make cluster at closely spaced nodes.

What do you say about it, @iarganda?

With regards,
Neel


#13

Maybe if you post an example image here we might try to find the best solution together. What do you think?


#14

@iarganda

I am sharing a 3D stack of skeleton of 10 images. Have a look and suggest. This is the google drive link for the image.

https://drive.google.com/open?id=0B1_zQFtGD7o4NVlQcWJGMDY1R2s

In this stack of images, after pruning threshold branches, results are improving. But, still, a number of smaller length branches are really high and obscuring the result for longer branches.

Neel


#15

OK, and what is the minimum length that you want for a branch?


#16

Minimum branch length I want is 6 pixels.


#17

Then, running a couple of times the script does the trick, doesn’t it?


#18

I tried to run the pruning script three times on the skeleton. But it didn’t make further changes. The only changes were brought in the results, when the skeleton was pruned for the first time. After first time pruning, results of analyze skeleton was same.

I think the small branches (<6pixels) inside a skeleton, with no end point voxels, can’t be pruned with this script. And that’s why in pruned skeleton, all branches with one or two end points and less than threshold length were removed. But those with branch length lesser than the threshold value are still in the skeleton because they have no end point voxels.

What do you say about it?


#19

Yes, of course, only branches starting on end points are pruned. Otherwise you could completely distort the skeleton.


#20

@iarganda

You are right about distorting the skeleton. That’s why in the previous post, I asked is it possible in pruned skeleton, to eliminate those branches with length lesser than the threshold by changing their nodes such that one node out of the cluster of closely spaced nodes, similar to ITA algorithm.

I hope I am not complicating the problem.

Neel