Add Results of Plugin as New Row in Results Table


I am trying to analyse each slice in a stack with the same MorphoLibJ command (Region Morphometry). I then want to have each slice’s result to be saved in a new row in the results table.

So far, I have managed to ‘write’ (read: cobble together) this little macro:

  macro "Measure Stack" {
       setOption("Stack position", true);
       for (n=1; n<=nSlices; n++) {
          run("Region Morphometry");
          setResult("Slice", nResults, n);

But it doesn’t do what I want. The Region Morphometry results end up in a different window and each new slice’s result overwrites the one before, whereas the results table proper just contains the slice numbers.

How do I get the Region Morphometry results into the actual results table, with each result being stored in a new row? (Sorry if the answer is really obvious to you, but I am new to this.) Please give me a shout if you need any other information!



Okay, let me rephrase the question. Is there a way of calculating the circumference of all objects of a specific colour in each slice throughout a stack?

If nobody wants to help me, I would at least appreciate a hint as to why nobody wants to help me. Do you people need more specific information? I am really new to this and might not be aware of ‘how it is done’. So, any input would be much appreciated.


Hello @dansch,

Does the AnalyzeParticles tool meet your needs (Analyze -> Analyze Particles…)? You can set it to measure the perimeter and elliptical fit parameters to each region if you want (Analyze -> Set Measurements…). It also runs on each slice in a stack and can put all the results in a ResultsTable for you.

If you do need to concatenate tables generated by the MorphoLibJ plugin being run on each slice you could do it with a script and a bunch of loops (perhaps there is a better way?). Then display that big table at the end. Below is an idea of how you may achieve that (I only quickly tested it…).

#@ ImagePlus(label="Image to Process: ") imp

# We will need the plugin and ResultsTable
from inra.ijpb.plugins import RegionMorphometryPlugin
from ij.measure import ResultsTable

# Call the plugin's process function directly and grab the results table
# it generates, we will store each results table in a list
RMP = RegionMorphometryPlugin()
results = []

for slice in range(imp.getNSlices()):
	results.append(RMP.process(imp, 4))
# Loop through every table, column and row and add the values to a new table
finalTable = ResultsTable()

for table in range(len(results)):
	for row in range(results[table].size()):
		for column in range(len(results[table].getHeadings())-1):
			finalTable.addValue(column, results[table].getValue(column, row))

# Add the headings...
for column in range(len(results[0].getHeadings())-1):
	finalTable.setHeading(column, results[0].getColumnHeading(column))

# Show the table..."All Results")

Regarding your post, it is often easier to provide advice if you have an example image to aid in your description of the goals. Having a second image with some doodles on it showing what you are trying to do is even better! :slight_smile:

Let me know if this helps! :rocket:


Dear Andy,

Thanks a lot for the detailed reply regarding both my problem and how to post a problem. :slight_smile:

I tried the ‘Analyse Particles’ tool, but I didn’t like that it yielded results individually for different objects of the same colour. What I ended up doing is using a binarised image stack that captures all objects of one colour and excludes all other colours, then use the ‘Create Selection’ tool to select all the objects, and finally used the normal ‘Measure’ command. This whole process I packed into my above macro that loops through the stack. So… thanks for setting me on the right tracks!

Nevertheless, I also appreciate a lot your ideas on how to get the results from the MorphoLibJ plugin. I will study it and use it or parts of it as needed in the future. Thanks!