Coral growth analysis- How to count the number of branches or nodes?

This is brilliant thank you so much! This is a crucial step! I’ve managed to skeltonize the image now :slightly_smiling:

However when I run the analyse skeleton, it counts too many junctions, probably because of the loops, as you can see from your image above. The Strahler plugin I mentioned previously takes into account these loops and discounts them.

I’m sorry to keep asking questions!.. but I think it would be ideal if I could use this Strahler plugin. I can’t figure out how to manually download this plugin. I am using Fiji now but still can’t find this plugin.

This is the link below to the plugin description.

https://raw.githubusercontent.com/tferr/Scripts/master/Morphometry/Strahler_Analysis.bsh

You can find the installation instruction here:

Users: You can enable an update site using the Help :arrow_forward: Update… command and clicking the “Manage update sites” button

Then add the update site “Add Update Site”:
http://sites.imagej.net/Tiago/

Then activate the checkbox next to the line containing BAR (http://sites.imagej.net/Tiago/).

2 Likes

Have you tried setting the cycle pruning option in AnalyzeSkeleton?

3 Likes

For update sites from the official list of update sites, the recommended way of installation is just to activate them in the list, not to add them manually:

(I edited your post above to avoid confusion about the best way to add update sites. I hope you don’t mind. :slightly_smiling:)

2 Likes

Hello Jan,

absolutely not. Thanks for the correction. I didn’t see it.

Thanks guys!

I’m very nearly there after all your help!

I managed to run the script for the strahler analysis after first processing the image by following the instructions from @Bio7

setOption("BlackBackground", false);
run("Make Binary");
run("Erode");
run("Median...", "radius=4");

I then got this output

It’s quite dark but the image on the right shows all the counted end points which is what I want :slightly_smiling:

However to save time, I would like to be able to do this to multiple images at a time but I can’t make this work by running the script- i tried to stack the images first but it processed it as one and gave me this picture of craziness! -

I’ve followed the instructions by @imagejan (thanks!) but I still can’t find the strahler plugin :frowning: It is there but it’s not ‘active’ and has a strahler analysis.bsh see below

I can’t find this function either!

under analyze skeleton the only option I have is skeletonize. Am I missing another update somewhere? I am using Fiji.

Also if I were to use the the skeletonise and pruning function (instead of the Strahler analysis which has both built in) would I be able to analyse multiple photos at once?

You can batch process the images very easily from a folder and put all your commands in a macro which will be executed:

http://imagej.net/docs/guide/146-29.html#sub:batch>Macro

Of course you can also all do this in a macro, too.


For the Strahler plugin open the Update menu (Help->Update…) then press “Manage update sites” (1) and then add the BAR site (2) to the default sites:

Then press “Apply changes” and restart ImageJ.

1 Like

Hmm, the option should be visible in the dialog that pops up when you run the plugin. If you run the plugin via scripts you can set the pruning option in the first parameter to the run call:

var skel = new AnalyzeSkeleton_();
skel.setup("", imagePlus);

var skelResult = skel.run(AnalyzeSkeleton_.NONE, false, true, null, true, false);

The options are: AnalyzeSkeleton_.NONE, AnalyzeSkeleton_.SHORTEST_BRANCH, AnalyzeSkeleton_.LOWEST_INTENSITY_VOXEL and AnalyzeSkeleton_.LOWEST_INTENSITY_BRANCH. The two latter also require an grayscale image of the imagePlus (this is the 4th parameter that’s null in the above code).

To answer your second question, I don’t know how AnalyzeSkeleton would handle multiple images. I know it can process multiple skeletons (objects) in the same image, and will report their statistics separately in the results table.

Hi @Seafan1,
Sorry for not jumping in earlier. I’ve developed the Strahler plugin and should be able to help. If I got it right, you need help concerning 1) Installation, 2) Batch processing and 3) Resolving closed loops the ramified structure.

@Bio7, @imagejan and @rimadoma already helped you with most of it, but just for thoroughness and future reference I will try to comment on those:

Installation
Strahler is distributed with the BAR suite of scripts. That’s why the easiest is to subscribe to the BAR update site. If I recall correctly this should be mentioned in the Installation sections of both the Strahler and BAR documentation pages. AnalyzeSkeleton (Analyze▷ Skeleton▷ Analyze Skeleton (2D/3D)…) and Skeletonize3D (Plugins▷ Skeleton▷ Skeletonize (2D/3D)…) are part of core Fiji.

Batch processing
Typically (and for highest flexibility) ImageJ plugins operate in single images with processing of multiple images being handled separately by ImageJ. As the vast majority of ImageJ plugins, Strahler is macro recordable. So the easiest way to process multiple images would be to:

  1. Start the Macro Recorder (Plugins▷ Macros▷ Record…)
  2. Run BAR▷ Morphometry▷ Strahler Analysis on the first image
  3. Copy the resulting line into the Batch Processing dialog (Process▷ Batch▷ Macro…). The recorded line would look something like it:
run("Strahler Analysis", "max.=10 infer ignore method=[shortest branch] display_iteration show");

If needed, you could also use some of BAR’s Batch_Processors. But in either case I’d explore first the procedure in a couple of images after reading the pages mentioned above. Any of us will be able to help you with this automation, but we will sure be more effective if you first give it a try.

Skeleton loops
In short: The plugin cannot process skeletons containing closed loops. You have several options to resolve such loops, including some sophisticated ones that will use the original (pre-thinned) image to determine the best way to open up loops in the structure. Rationale and details are explained in both the Strahler and AnalyzeSkeleton documentation (the core functionality of Strahler is provided by AnalyzeSkeleton, so all the information you need will always be in either documentation page). NB: Strahler will automatically disable loop-resolving options that cannot be applied to your image. E.g.: If the original grayscale image of the structure is not available, Intensity-based options will not be available.

Suggestions
Since your coral is a somewhat polarized structure, I wanted to mention that you will probably be interested in determining the root of the coral, as described in Root Detection (NB: There have been some recent improvements in root detection that are not yet documented). For this to work you will have to mark the root of your corals with a rectangular ROI, as mentioned in the documentation. This option is also compatible with batch processing as long as you save your images as .tiff, since the ROI will be saved in the image header and retrieved at startup by ImageJ.
On a slightly different note, I wanted to mention that you could also complement your analysis using Sholl.

5 Likes

Amazing! Thanks for answering! :smiley:

I’ve got strahler plugin to install and run on a single image now. I’m just struggling with the batch analysis. I’ve got to the stage where I have binary images in tiff format ready to use the Strahler analysis. But I get this error message and don’t know how to resolve this.

okay, so to break down my method for this analysis, for each image I will:

  1. Format it as binary and use the erode function so that each individual polyp is not visible. I think this will have to be done individually.
  2. Root the Fan by making a ROI (very good suggestion thank you!)
  3. save the image as a tiff file
  4. create a batch for the images of the same Sea Fan over the time series

These steps above are fine.
What I now need to figure out is:

  1. For the loops, do I need to get rid of them before running the Strahler analysis? Or does it take it into account? In the first image I used with Strahler analysis there were loops but the analysis ran anyway so I wonder if it’s necessary?
  2. The batch Strahler analysis that wouldn’t run as shown above. I would just like to mention that (typically!) I am very time limited and so being able to run the analysis in batch is crucial!

I also have another question. From my database I have selected the Sea Fans with the most simple, ‘2D’ structure. There are many Fans that are far more complicated. I was wondering if you think that the Strahler could cope with more complicated structures such as the fan seen below?

The problem is that, when making the image binary the branches tend to blur into each other.

Again, thanks to everyones help so far! I couldn’t have done it without your input!! :blush:

It seems that you copied Java code instead of ImageJ Macro code in the Batch dialog.

From which source is the code?

The error message starts at the beginning of the imports (import ij.IJ;).

However, please paste the macro code in the dialog as @tferr suggested, something like:

run("Erode");
run("Strahler Analysis", "max.=10 infer ignore method=[shortest branch] display_iteration show");

Press “Test” to controll if everything is working as it should before you apply the macro on the selected folder of images.

1 Like

The code is from the link on the strahler plugin website.

The code I got from this link circled on the image above and then integrated the code from @tferr. Then when I ran the test I got the error I mentioned above.

A BeanShell script (*.bsh) is not ImageJ macro code! No need to paste the *.bsh code in the Batch dialog.
You already installed it.

Just use the ImageJ macro commands as already explained:

2 Likes

Hi,
I can see what I was doing wrong now! Thank you @Bio7

I still can’t get the batch to work. I have preprocessed all the files, saved them as 8 bit tiff files but when I run a test it only works for the first image in a folder. It also comes up with the message no 8-bit image found. But I’ve triple checked and all images (I’m just trying with 4 images to start with) in the file are 8 bit.

this next question is probably for @tferr.

I’ve tried using the plugin on one of my smaller sea fans to get a better understanding of what the output is telling me.
Below is a screen shot of the original image and the stages of analysis. Binary format, and the two phases of the strahler analysis.

I’m a little confused by the output tables I get after running the analysis. To me, in each picture I see 5 outer branches. And in the final image, strahler plugin as also picked up these 5 outer branches and coloured them all blue. But in the table output it doesn’t give me that number.
This photo is from 1995 and so the quality is not as good as the others. It’s also zoomed in from this image below. So could it be that it is the quality of the image that is making the plugin make this mistake?

In short: you have other objects in your image. Please remember that the analysis assumes that you have only a single skeleton in your image (Albeit briefly, this is mentioned in the documentation): If you have multiple trees in your image, their properties will be summed.

When you segmented your coral, you also thresholded some clusters of pixels elsewhere in the image. These “segmentation debris” are probably too small that you haven’t noticed them in the image canvas, but they do contribute to the analysis, as they are de facto objects. The Iteration Log table (visible in your screenshot) is reporting this in the # Trees column, informing that 4 distinct skeletonized trees were present in the image when the analysis started. (See also this post on why so many “unfiltered” parameters are reported).

The best way to avoid this is to ensure that all of the foreground pixels of your binary image include only the coral (in other words: clear all of the pixels outside the coral). Below is a macro that does this to your image, by selecting the segmented coral with the wand tool, and clearing all pixels outside the selection:

// Open 95WAY11n.JPG sample image
open("http://forum.image.sc/uploads/imagej/original/1X/94954b0dcfd7fe280dcab86b7cc82036fc484bf3.JPG");
rename("95WAY11n");

// Pre-processing
run("8-bit");
run("Gaussian Blur...", "sigma=2");

// Segmentation
setAutoThreshold("Intermodes dark");
setOption("BlackBackground", true);
run("Convert to Mask");

// Ensure there is only one object in the image by clearing all pixels outside the sea fan
doWand(525, 580);
setBackgroundColor(0, 0, 0);
run("Clear Outside");

// Mark the root of the sea fan and run Strahler
makeRectangle(500, 580, 50, 50);
run("Strahler Analysis", "max.=10 infer ignore method=[shortest branch] show");

To run it in Fiji: Copy the above macro, and paste in a new IJ macro editor, opened by running File▷ New▷ Script… ([ shortcut) followed by Language▷IJ1 macro. When I run it, I get the expected results of 5 order I branches and 4 order II branches.

I now realize that the user-feedback on multiple-trees being detected is somewhat cryptic. I will try to improve it as soon as I find the time. Meanwhile I opened an issue, so I it is not forgotten.

3 Likes

I am able to reproduce this. It seems to be indeed a bug. I will investigate. As a work around, macros recorded with the “Tabular data only (no image output)” option should still work (although I have not yet tested).

1 Like

Great thanks for all your advice. At the moment I’m using the Strahler individually and it’s working really well :slightly_smiling:

If I wanted to just run Strahler to get the tablular data only, how would I code for this in the macro editor?

You don’t :slightly_smiling: . The best way is to use the Macro Recorder to generate the code for you. Open an image, run Strahler and check the “Tabular data only (no image output)” checkbox. When I do it, a new keyword tabular appears in the recorded string.

If you run the Recorder and run Strahler multiple times while toggling different options in the dialog prompt you will notice the following:
In a macro, ImageJ commands are controlled by a single lowercase sentence in which arguments are separated by a space and active checkboxes by a single keyword: hence the appearance of the tabular keyword (BTW, Input fields and drop-down menu lists appear as keyword=value pairs).

Notice also that while the recorder records all the parameters in the dialog, you can omit options that are not needed. E.g.:

run("Strahler Analysis", "max.=10 infer ignore method=[shortest branch] show tabular");
3 Likes

Sorry for the late reply!

Thanks again for all your help. I am currently writing up my dissertation. Unfortunately I was only able to use the strahler analysis for part of the data analysis. But I"m hopeful for it’s application in the future :slight_smile:

I want to refer to the Strahler plugin and was wondering if there was a paper that I could cite in my write up?

1 Like