Calculation of average chain length

fiji
imagej
plugin
#1

Hi,

I’m a beginner of ImageJ.

I have some images where particles are formed into chains, as follow.

Could someone help and tell me how to detect and calculate the number and the length of the chains? Preferably, I would aslo like to have a histogram that shows the lenght distribution.

Thank you in advance.

Question on plugin 'Directionality'
#2

@yeah

This older forum post seems relevant to your work:

I think the main issue you will have is how to handle the clumping particles found on either side of the image… Do you have an idea how you will handle those? Or only select chains of a certain width?

If you are just getting started with ImageJ - here are a few helpful links for background info, etc:

eta

#3

Thank you so much Etarena! I still have to take some time to read through and try.:face_with_monocle:

1 Like
#4

Check out the ridge detection plugin.

1 Like
#5

Just noticed this functionality

1 Like
#6

Hi rondespain,

This is so cool! Thank you so much!

Could you tell me the parameters you set? And how did you define the pixel length and the line width? I tried the plugin several times, but didn’t get good results as yours. :frowning:

Thank you again!

#7

Lowering the setting of sigma in the Ridge Detector improves it’s sensitivity (more less contrasty ridges found)

Also, the Ridge Detector processes the whole image so you have to do some processing to remove the edges of the selection. Here’s some code that is working for me. Run it after you select your ROI.

//MACRO BEGIN************
run("Duplicate...", "use");
run("8-bit");
setBackgroundColor(255, 255, 255);
run("Clear Outside");
run("Ridge Detection", "line_width=3.5 high_contrast=255 low_contrast=0 displayresults make_binary method_for_overlap_resolution=NONE sigma=0.50 lower_threshold=0 upper_threshold=8.84 minimum_line_length=0 maximum=0");
run("Restore Selection");
run("Clear Outside");
run("Ridge Detection");
selectWindow("Results");
//MACRO END**********

It results in:

Here’s the setup:

1 Like
#8

Thank you so much! Finally I manage to detect the lines as I want.

However, some lines are detected as two or more lines with junctions, which is I don’t want. Maybe this appears because of the lines in my image is formed from particles. Do you happen to know is there a way to combine them or what parameter should I tune?


Really thank you so much, you have helped me a lot!

#9

There is another spread sheet that appears that has the junctions listed. I’m not sure how to interpret it, so you might go to the home users page to read, or maybe contact the originator or the Ridge Detection macro to get some insight.

I’ll continue to explore this and let you know what I find. You can stay in touch at ron_despain@hotmail.com when this.

Please let me know what you discover.

By the way…you can pull in the variables using getResult(“Column”, row); and you can then do math within your macro should you need to.

Ron

#10

Not such a good result on a validation test. Let me know if you figure out how to filter out the many many short partial line segments discovered by Ridge Detection.

May have to use Analyze Particles instead.

Ron

#11

Perhaps you could use the Dilate function to increase the line thickness

#12

I generated the histogram from the Summary window instead which detects each line only once (good), but it still gets a lot of smaller line segments. This might be acceptable as long as you know to ignore the lower values.

Here’s the validation run:

Here’s the code

//Selection Ridge Detection Macro 180626
//ron_despain@hotmail.com
run("Duplicate...", "use");
run("8-bit");
setBackgroundColor(255, 255, 255);
run("Clear Outside");
run("Ridge Detection", "line_width=3.5 high_contrast=255 low_contrast=0 displayresults make_binary method_for_overlap_resolution=NONE sigma=1 lower_threshold=0 upper_threshold=8.84 minimum_line_length=0 maximum=0");
run("Restore Selection");
run("Clear Outside");
run("Invert LUT");
run("Clear Results");
run("Ridge Detection", "line_width=3.5 high_contrast=255 low_contrast=0 displayresults make_binary method_for_overlap_resolution=NONE sigma=1 lower_threshold=0 upper_threshold=8.84 minimum_line_length=0 maximum=0");
//close("Summary");
IJ.renameResults("Summary","Results");
selectWindow("Results");
run("Distribution...", "parameter=Length or=100 and=0-100");
run("Tile");
close("Junctions");
//Macro End *********

You can clip off the lower values by changing the Distribution call:
e.g. run(“Distribution…”, “parameter=Length or=100 and=10-100”);

#13

Here it is on a section of the chains data…you can’t use a rectangular selection with the macro.

#14

Thank you! This helps.

#15

Hi Ron,

I tried your code, but the result doesn’t show the exact length of the lines formed from particles.

And I did not figure out how to avoid the short segments, so maybe I will do some math afterwards.

Thank you so much for your help. It’s very nice of you. I will let you know if I find something.

Best,
yeah

#16

In my last example I didn’t invert the image prior to running…the code is set up for a black background.
So it found the ridges associated with the background.

The prior code I shared was for users who want to select a shaped region.

Here is code more suited to your case as you don’t have to make a selection.

//No Selection Ridge Detection Macro
//ron_despain@hotmail.com
run("Invert");
run("8-bit");
run("Ridge Detection", "line_width=3.5 high_contrast=255 low_contrast=0 displayresults make_binary method_for_overlap_resolution=NONE sigma=1 lower_threshold=0 upper_threshold=8.84 minimum_line_length=0 maximum=0");
run("Select None");
IJ.renameResults("Summary","Results");
selectWindow("Results");
run("Distribution...", "parameter=Length or=100 and=20-100");
run("Tile");
close("Junctions");

I limited the distribution to only show entries of length > 20 to enhance the shorter line peaks…PLEASE SHARE HOW YOU CHOOSE TO DEAL WITH THE SHORTER LINE SEGMENTS.

#17

there is a good discussion of handling the shorter line lengths in this discussion here at ImageJ Forum. A good read with lots of info.

Ridge Detection Feedback