ROI Manager count=0 although ROI Manager has ROIs

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

ROI Manager count=0 although ROI Manager has ROIs

Martin Höhne
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----------------------------------------------------------





Reply | Threaded
Open this post in threaded view
|

Re: ROI Manager count=0 although ROI Manager has ROIs

Romain Guiet
Hi Martin ,
I noticed a weird behavior like this a while ago (when i tried to rename the ROIs). I identified that it was due to the absence of an existing ROImanager window before entering the "batch mode" using setBatchMode(true).

Instead of closing the ROImanager window if it's open, I would recommend to reset it using the function roiManager("Reset").  Actually if there no roiManager window opened, the problem will still be there, so you should open one before entering the batch mode.

So you can replace :

if (isOpen("ROI Manager")) {
     selectWindow("ROI Manager");
     run("Close");
}

by :  

roiManager("Reset"); // it will reset ,or create, the roiManager window

so the begining of your code willl be  :

run("Close All");
roiManager("Reset");
setBatchMode(true);

Cheers,

Romain



---------------------------------------------------------------
Dr. Romain Guiet
Bioimaging and Optics Platform (PT-BIOP)
Ecole Polytechnique Fédérale de Lausanne (EPFL)
Faculty of Life Sciences
Station 19, AI 0140
CH-1015 Lausanne

Phone: [+4121 69] 39629
http://biop.epfl.ch/
---------------------------------------------------------------

________________________________________
De : ImageJ Interest Group [[hidden email]] de la part de Martin Höhne [[hidden email]]
Envoyé : mercredi 23 septembre 2015 20:25
À : [hidden email]
Objet : ROI Manager count=0 although ROI Manager has ROIs

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----------------------------------------------------------









--
View this message in context: http://imagej.1557.x6.nabble.com/ROI-Manager-count-0-although-ROI-Manager-has-ROIs-tp5014427.html
Sent from the ImageJ mailing list archive at Nabble.com.

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: ROI Manager count=0 although ROI Manager has ROIs

Emanuele Martini
Hi to all,
yes I had some similar problems and that's right opening firstly roimanager resolve most of them.
Image Analyst @Ifom-IEO research campus -MI-
Reply | Threaded
Open this post in threaded view
|

Re: ROI Manager count=0 although ROI Manager has ROIs

Martin Höhne
Thanks Romain and Emanuele for the solution.
 
Wayne Rasband suggeted the same solution via Email. Moreover it turned out that there was a bug that is fixed in the latest ImageJ daily build (1.5015)

Here is what I learned from Wayne - might be interesting for others as well:
If the ROI Manager is not open, batch mode macros use an invisible ROI Manager that is deleted when batch mode is exited.
In my macro this invisible ROI Manager was still running when I opened a second (visible) ROI Manager. And this should not have been possible (and is changed with the daily build: ROI Manager cannot be opened when the invisible batch mode ROI Manager is already active). What happened in my macro was obviously, that the second Analyze Particles command populated the visible ROI Manager, while the roiManager("Count") command counted ROIs in the invisible ROI Manager. And that caused quite some confusion.

Martin