ROI Manager Multi-Measure, Append: doesn't clear results properly

Ultimately, I’d like to use a macro to measure a group of ROIs on a few different images, appending the results each time. Then I want to clear the manager and the results, load another set of images and ROIset, and repeat.

However, I noticed the results table started getting really long when I did this for several images in succession.

The following macro shows the effect (although it doesn’t seem very minimal, sorry…).
The log window shows the number of results in the table after measuring a single ROI in different ways.

Note that even when I clear the results, each time multi-measure append is called, it somehow finds the previous results and adds them to the table. The only way I’ve found to get rid of the extra results is to close the ROI Manager window.

Can anyone reproduce this, or explain if I’m doing something wrong?

Many thanks!

// measure_test.ijm
// goal: test whether multi-measure causes expansion of results table
// Note that the number of results increases incorrectly each time Multi-Measure is called with the "append" option,
// and this is "fixed" by closing the ROI manager window.

run("Dot Blot (7K)");
run("Set Measurements...", "area redirect=None decimal=2");
print("Clearing results and resetting ROI Manager");
run("Clear Results");
roiManager("reset");
print("Results at start:",nResults);

function addROI() {
	// makes 1 ROI and adds to manager
	run("Specify...", "width=50 height=50 x=200 y=200");
	roiManager("Add");
	}

// add 1 ROI to Manager
addROI();

// measure ROIs individually

for (i = 1; i < 3; i++) {
	roiManager("select",0);
	run("Measure");
	print("Results after measuring individually, iteration "+i+":",nResults);
	print("Clearing results");
	run("Clear Results");
	}

// measure ROIs using Multi-Measure

for (i = 1; i < 3; i++) {
	print("Results before multi-measure, iteration "+i+":",nResults);
	roiManager("Deselect");
	roiManager("multi-measure measure_all append");
	print("Results after multi-measure, iteration "+i+":",nResults);
	print("Clearing results");
	run("Clear Results");
	}


// measure ROIs using Multi-Measure, but reset the ROI manager window

for (i = 1; i < 3; i++) {
	print("Results before multi-measure with reset, iteration "+i+":",nResults);
	roiManager("Deselect");
	roiManager("multi-measure measure_all append");
	print("Results after multi-measure with reset, iteration "+i+":",nResults);
	print("Clearing results and resetting ROI Manager");
	run("Clear Results");
	roiManager("reset");
	addROI(); // re-make ROI for the next iteration
	}

// measure ROIs using Multi-Measure, but close the ROI manager window

for (i = 1; i < 3; i++) {
	print("Results before multi-measure with close, iteration "+i+":",nResults);
	roiManager("Deselect");
	roiManager("multi-measure measure_all append");
	print("Results after multi-measure with close, iteration "+i+":",nResults);
	print("Clearing results and closing ROI Manager");
	run("Clear Results");
	selectWindow("ROI Manager");
	run("Close");
	addROI(); // re-make ROI for the next iteration
	}
	
print("number of results at end:",nResults);
print("==================================");
selectWindow("Dot_Blot.jpg");
close();
roiManager("reset");
selectWindow("ROI Manager");
run("Close");

Sample log file:

Clearing results and resetting ROI Manager
Results at start: 0
Results after measuring individually, iteration 1: 1
Clearing results
Results after measuring individually, iteration 2: 1
Clearing results
Results before multi-measure, iteration 1: 0
Results after multi-measure, iteration 1: 1
Clearing results
Results before multi-measure, iteration 2: 0
Results after multi-measure, iteration 2: 2
Clearing results
Results before multi-measure with reset, iteration 1: 0
Results after multi-measure with reset, iteration 1: 3
Clearing results and resetting ROI Manager
Results before multi-measure with reset, iteration 2: 0
Results after multi-measure with reset, iteration 2: 4
Clearing results and resetting ROI Manager
Results before multi-measure with close, iteration 1: 0
Results after multi-measure with close, iteration 1: 5
Clearing results and closing ROI Manager
Results before multi-measure with close, iteration 2: 0
Results after multi-measure with close, iteration 2: 1
Clearing results and closing ROI Manager
number of results at end: 0
==================================

Without to execute your macro example I found similar reports for this issue.

In the first report the ROI Manager is closed, too!

http://imagej.1557.x6.nabble.com/append-in-macro-ROI-multi-measure-function-td5015932.html

Recently the following bug was fixed related to the multi measure issue:

Here the API of the ROIManager:

https://imagej.nih.gov/ij/developer/api/ij/plugin/frame/RoiManager.html#reset--

1 Like

Thanks, @Bio7, I forgot to search the mailing list. It looks like a similar bug has cropped up again.

I saw the report by @oburri but that is the opposite issue to what I’m seeing.

However it seems that the ROIManager has a reference to a results table instance which values then get appended if the ROIManager is not closed.

Yes, I’m not that good at reading the source code or API but it looks like the multi-measure method clones the existing results table so even if the main table is cleared, the copy lives on.

When I repeatedly run this code from the mailing list thread of 3/2016, I get the correct behavior (1 line of Results), but if I remove the last 2 lines the results table gets longer each time:

run("Blobs (25K)"); 
run("Clear Results"); 
doWand(136, 54, 30.0, "Legacy"); 
roiManager("Add"); 
doWand(129, 127, 30.0, "Legacy"); 
roiManager("Add"); 
roiManager("multi-measure one append"); 
close(); 
selectWindow("ROI Manager");  // remove this and the next line to see that the results table is not cleared
run("Close"); 

This bug is fixed in the latest ImageJ daily build (1.51o24).

3 Likes

Wonderful! Thank you, @Wayne!