Re: Problem with ROI Manager in BatchMode

Posted by Rasband, Wayne (NIH/NIMH) [E] on
URL: http://imagej.273.s1.nabble.com/Problem-with-ROI-Manager-in-BatchMode-tp3682680p3682683.html

On Nov 1, 2011, at 3:28 PM, Peter Haub wrote:

> Hi Winfried,
> Hi Wayne,
>
> sorry, my description was not precise enough.
>
> The problem has - as far as I can see in the IJ code - to do with the IJ
> internal management of the RoiManager.
> In the BatchMode there is a special handling of the RoiManager.
> So the behaviour of your macro depends on the sequence of activation the
> BatchMode and first time calling the RoiManager.
> You solved the problem by changing that sequence.
>
> The idea of my code was to attract someones attention who can solve this.

The open() macro function is unable to open ROI sets if the macro is running in batch mode and the ROI Manager is not open. I did not see an easy fix for this problem so the ImageJ 1.46a4 daily build displays an error message in this situation. You can easily work around this problem by using

   roiManager("Open", path_to_ROI_set);

to open ROI sets.

-wayne

> The problem can be visualized more clearly by changing my code and to
> open the RoiManager before activating the BatchMode.
> This code works fine:
>
> **************** Here is my 'changed' code **********************
> open("C:\\RoiSet.zip");
>
> setBatchMode(true);
>
> open("C:\\test.tif");
>
> // It's working if this call is previous to the batch mode activation
> !!!!!!!!
> //open("C:\\RoiSet.zip");
>
> selectWindow("test.tif");
> run("Select None");
> m=(roiManager("count")-1);
> for(r=0;r<=m;r++)
> {
>    roiManager("deselect");
>    roiManager("select",r);
>    arg="enlarge="+2;
>    run("Fill", "slice");
> }
> setBatchMode("exit and display");
> *****************************************************
>
> Peter
>
> On 01.11.2011 17:44, Winfried Wurm wrote:
>> Thank you Peter for trying to solve my Problem.
>> But my Problems seems to have another reason. Actually I solved my Problem today, but I have to admit that I don´t know why the Macro is working now....
>>
>> It seems to me now that the Problem was another Function that I run before the Foci counting part that I posted yesterday. That function is measuring the Area of Chromocenters. When I turned it off or behind the Foci measuring today everything worked fine. But I don’t know why! The function measures in a completely different Image and shares no variable with the Foci measuring function.  And when I call that function AFTER the Foci Funtion there is no Problem.
>>
>> So why is that working?
>> CountMeasureFoci("cell.tif","foci.tif",px[con],mpx[con],msl[con]);
>> cellarea=Cellar("cellar.tif");
>> chromarea=Cellar("chrom.tif");
>>
>> And this not?
>> cellarea=Cellar("cellar.tif");
>> chromarea=Cellar("chrom.tif");
>> CountMeasureFoci("cell.tif","foci.tif",px[con],mpx[con],msl[con]);
>>
>> And why did the Problem only occur in BatchMode? I have no Idea what has happend. Maybe someone can tell what went wrong? Because even if it works now. I would like to understand why.
>>
>> Here is the function that seems to make the Problem:
>>
>> function Cellar(window)
>> {
>>     selectWindow(window);
>>     area=0;
>>     for(z=1;z<=nSlices;z++)
>>     {
>>         setSlice(z);
>>         run("Select None");
>>         run("Measure");
>>         if (getResult("Max")==255)
>>         {
>>             for(x=1;x<getWidth;x++)
>>             {
>>                 makeRectangle(x, 0, 1, getHeight);
>>                 run("Measure");
>>                 if (getResult("Max")==255)
>>                 {
>>                     for(y=1;y<getHeight;y++)
>>                     {
>>                         if(getPixel(x,y)==255)
>>                         {
>>                             doWand(x-1,y);
>>                             run("Measure");
>>                             m=getResult("Area");
>>                             area+=m;
>>                             run("Fill", "slice");
>>                             makeRectangle(x, 0, (getWidth-x), getHeight);
>>                             run("Measure");
>>                             if (getResult("Max")==255)
>>                             {
>>                                 makeRectangle(x, 0, 1, getHeight);
>>                                 run("Measure");
>>                                 if (getResult("Max")<255)
>>                                     y=getHeight;
>>                             }
>>                             else
>>                             {
>>                                 x=getWidth;
>>                                 y=getHeight;
>>                             }
>>                         }
>>                     }
>>
>>
>>                 }
>>             }
>>         }
>>     }
>>    return area;
>> }
>>