How to measure fiber length and diameter automatically?

Hey everyone. I’m new here and to SEM image processing and using ImageJ/Fiji. Thanks for looking at my post.

I am characterizing the fibers shown below and would like to automatically measure their length and average diameter. I was looking at DiameterJ, but I think it doesn’t have what I want for measuring the fiber length. I’m looking for something that will plot a line along my curvy fibers using thresholding and report that line’s measurement. Does anyone have a recommendation for the best plug-in to use for this?

Hi,

One way to do this is enhance the image to highlight the strands. I did this with the Difference of Gaussians plugin which is the script menu, but there is not doubt a plugin for this. The parameters I used were 10 and 5

After this I ran the ridge detection plugin with the following parameters

This puts the strands into the Roi manager and there is a results table with the length and width of each.

Cheers,

Chris

1 Like

Hi Chris,

Thanks for your advice! I was able to get this analysis going, but my mean line widths are reporting with about half the values that you calculated. Your values are much closer to what I was expecting.

I think this is because I was unable to use the Difference of Gaussians script like you did. I was able to run the Apply_DOG_Filtering.py script which I picked up from GitHub here:

This gave me the script window seen in your first screenshot and I entered your same sigma values, however, this just produces a completely black image for me. Do I need to change the script somehow?

After this challenge I tried using the GDSC Difference of Gaussians plugin from The Univeristy of Sussex toolpak. I get the same results there unless I check the “Enhance Contrast” box. But when I do ridge analysis with the resulting image the widths are too small. I think the contrast enhancement is a problem.

Is there something different about your Python script for the Difference of Gaussians analysis? I am trying to reproduce your results exactly.

Thanks,

Dan

Hi Dan,

The ridge detection plugins only works on 8-bit images(although @gselzer has been working on an IJ2 update). I was playing with the png image attached to your post which is 8-bit so I didn’t have to change in bit depth.

Your raw images are probably 16-bit, or maybe even 32-bit, which means you need to need to convert to 8-bit. ImageJ uses the current brightness and contrast settings to truncate 16-bit images to 8-bit, which is why you see a difference when “Enhance Contrast” is run. If you’re comparing multiple images it will probably be best to set a fixed range in the Brightness and Contrast tool.

I ran the DoG on the 8-bit version which will be slightly different too.

Cheers,

Chris

Thanks for your quick reply, Chris. I really appreciate your help.

So my raw images really are 8-bit, but I even redownloaded my image off of here and got the same results. I’m also trying this on a second computer with fresh installs now. Maybe there is some other setting referenced by the script I am missing? Also, I’m not sure what you mean by setting a range in the Brightness and Contrast tool. This is the window that opens with Shift+C, yes? But seems like that is just an issue for 8-bit conversion.

Below are images processed using the file downloaded from my original post. Here is what I get running the Apply_DOG_Filtering.py script with sigma values of 10 and 5. Something seems to be wrong with the upper threshold:

Here is what I get using the GDSC DoG plug-in with and without the contrast enhanced:

When I submit the second one to ridge analysis using your parameters it seems to be working, but I end up with different diameters:

Maybe this is because I have a scale set on my images? However, to my eye, it looks like I’m losing some of the fiber ridge definition at the DoG step.

What do you think?

Thanks,

Dan

Hi Dan,

the DoG image is dark compared to the original. Here is profile plot of the fibre on the raw and DoG processed:

As the change in intensity in the raw image is subtle change in intensity on DoG is only 20. Changing the Brightness and Contrast just changes how the image is displayed on the screen (it only make a difference in your are converting to 8-bit from a higher bit depth). You can the Ridge Detection plugin on the dark image and it is still going to find the strands.

Cheers,

Chris

Thanks, Chris.

I tried running Ridge Detector on my dark image but I’m still getting sorter line widths than I’m expecting:

Here I’m looking at the same cross-section as you but with a shorter line. The DoG processed plot shows about 7 nm between the edges of the peak, but none of my mean line widths are greater than 5.

Any idea why these values aren’t closer to yours? I think our ridge detection images look pretty much the same though.

Thanks,

Dan

Hi Dan,

I think other than the pixel scale, the our results are the same.

Chris

OK I was suspecting it was just the scale then. I guess my fibers are a litter thinner then I was measuring by hand. Thanks for all of your help!

Hey Chris,

Just wanted to say thanks again for your help. The paper I was working on with this was accepted today and I got you in the acknowledgements.

Dan

Hello Chris,

I’m having a hard time locating this DoG plug in. Could you lend me a hand please.

Hi Dan,

I just saw your message - thanks so much for acknowledgement!

Cheers,

Chris

Hi @gprince,

there’s a couple of ways:

Manually

Create the larger blur

  1. Duplicate the image Image > Duplicate
  2. Do the larger blur Process > Filters > Gaussian Blur... and put in the larger sigma
  3. Rename this blur_big Image Rename...

Create the smaller blur

  1. Duplicate the image Image > Duplicate
  2. Do the larger blur Process > Filters > Gaussian Blur... and put in the smaller sigma
  3. Rename this blur_small Image Rename...

Take the difference

  1. Subtract blur_small from blur_big Process > Image Calculator and
    • image1: blur_big
    • operation: subtract
    • image2: blur_small
    • create new window: tick
    • 32-bit result: tick
  2. Use Brightness and contrast to scale the range and convert the image to the bit depth you need.

Without installing anything

There is a DoG in the script examples:

  1. Go to menu item File > New > Script ... to bring up the script editor
  2. On Windows there are menus on script window, on MacOs the menu at eh top of the screen changes. In this select Templates > ImageJ2 > Apply DoG Filtering (Python)
  3. Press Run on the script window to run the filter on the active image.

Screen Shot 2020-03-20 at 9.02.23 am

Install the GDSC plugins

From Dan’s posts above:

  1. Run the update in imageJ Help > Updates
  2. After the check have run click Manage update sites
  3. Tick the GDSC box
  4. Press Close
  5. Press Apply changes
  6. Restart ImageJ

The plugin can now be run from the menu by going to:
Plugins > GDSC > Utils > Difference of Gaussians

Cheers,

Chris

1 Like