Re: Problem with ROI Manager in BatchMode

Posted by BenTupper on
URL: http://imagej.273.s1.nabble.com/Problem-with-ROI-Manager-in-BatchMode-tp3682680p3682686.html

Hi,

On Nov 1, 2011, at 12:44 PM, 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]);


In my experience, selecting windows/images by name can be problematic under batchMode.  It must be that looking up the object by name creates race conditions or something.  To avoid this issue I would use the image ID instead of the image name.  Like this...

id = getImageID("cellar.tif");
selectImage(id);

I suggest that you change the argument to your Cellar function from a string to an image ID.  Really, you need only change ...

> selectWindow(window);

to

selectImage(window);

... in the function.  I can't know this will correct the problem for sure, but I would be interested to know if the following works for you after you modify the function.

//start

cellarID = getImageID("cellar.tif");
chromID = getImageID("chrom.tif");

cellarea=Cellar(cellarID);
chromarea=Cellar(chromID);

CountMeasureFoci("cell.tif","foci.tif",px[con],mpx[con],msl[con]);

// end

Cheers,
Ben


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