ROI Manager count=0 although ROI Manager has ROIs
Posted by Martin Höhne on Sep 23, 2015; 6:25pm
URL: http://imagej.273.s1.nabble.com/ROI-Manager-count-0-although-ROI-Manager-has-ROIs-tp5014427.html
Dear all,
the macro below illustrates a problem with the ROI Manager. Although it is open and populated with ROIs the roi-count is zero.
I´m sure it has something to do with batch mode, but I´m not sure if the behaviour is expected or a bug.
Best,
Martin
//macro start----------------------------------------------------
/*
* Part 1: identify small particles and add their outline to overlay of the original image
* this part works fine
* Part 2: identify large particles and allow the user to view the results with Show/Hide the ROIs
* this part does not work as expected
*
* Problems are in line 61 (minor) and 66 (severe)
*/
run("Close All");
if (isOpen("ROI Manager")) {
selectWindow("ROI Manager");
run("Close");
}
setBatchMode(true);
//open Cell Colony image and make a binarized copy
run("Cell Colony (31K)");
original=getImageID;
run("Duplicate...", "title=bin");
run("Make Binary");
binary=getImageID;
setOption("BlackBackground", false);
// Part 1: identify small particles and add their outline to overlay of the original image
// this part works fine
run("Analyze Particles...", "size=1-44 exclude add");
//add outlines to overlay
roiManager("Show None");
//rois=roiManager("Count");
//combine all identified ROIs into one ROI
a1=newArray(roiManager("Count"));
for (i=0; i<a1.length; i++){
a1[i]=i;
}
roiManager("Select", a1);
roiManager("Combine");
roiManager("Add");
//add combined ROI to overlay of original
selectImage(original);
roiManager("Select", (a1.length));//this is the combined ROI
roiManager("Set Color", "blue");
run("Add Selection...");// to overlay
// Part 2: identify large particles and allow the user to view the results with Show/Hide the ROIs
// this part does not work as expected
selectImage(binary);
run("Select None");
roiManager("Reset");
run("ROI Manager...");
run("Analyze Particles...", "size=45-Infinity exclude add");
selectImage(original);
//the complete macro should run in batch mode, however at this point I´d like the user
//to have a look at the selected particles
setBatchMode("Show");
roiManager("Show All");// Problem #1: this line seems to have no effect.
//The ROIs are only shown after deselecting/reselecting "Show All" in the ROI Manager
waitForUser("Display/hide large particles by selecting/deselecting \n -Show All- in the ROI Manager\n \nContinue with OK");
setBatchMode("Hide");
print("There are "+ roiManager("Count")+" ROIs in the ROI Manager");
// Problem #2: although the ROI Manager is visible and populated with ROIs the count is zero?
exit;
//macro end----------------------------------------------------------