Strange behaviour of RoI manager in batch mode

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Strange behaviour of RoI manager in batch mode

Stoyan Pavlov
Hi, dear friends,

I recently noticed a strange behaviour, when running roimanager commands in
a macro in batch mode. I don't know whether it did this before (since I
only recently started adjusting rois through macros) or probably its
expected due to the peculiarities of the batch mode?
Hear is whats happening: I wrote a macro to open an image, threshold it,
create selection and open a set of rois, which afterwards are manipulated
in the following way: second roi (number 1) is combined (OR) with the
thresholded selection and than multiplied (AND) with the first roi (number
0)and updated, than rois 2,4, 6 are multiplied by the new 2nd region and
the new selections are used to update rois 3,5 and 7. When I run this macro
in standard mode everyrhing happens as described. When however I try to run
it with batchmode set to true, everything goes haywire: roi number 1 is
replaced by number 0 and rois 3,5 and 7 are replaced by the combined  roi
1with the new thresholded selection. Here follows the code I am using for
reference. (I know I could have written it without adding the intermittent
rois , using only 'run(Restore Selection)' and 'roiManager("update")', but
somehow this made results even more unpredictable):
---
 //Macro start

dir1 = getDirectory("Choose an Image Directory ");
dir2 = getDirectory("Choose a ROI file Directory");
dir3 = getDirectory("Choose a Modified RoIs Directory");

//setBatchMode(true);

 list = getFileList(dir1);
 list2 = getFileList(dir2);

 for (i=0; i<list.length; i++) {
                path = dir1+list[i];
                showProgress(i, list.length);
                if (!endsWith(path,"/")) open(path);
                if (nImages>=1) {

                roiManager("reset");
                setThreshold(0.15,2.41);
                run("Create Selection");
                resetThreshold();

                                //loading ROIs here
                                 path2 = dir2+list2[i];
                                if (!endsWith(path2,"/")) {
                                roiManager("Open", path2);

  // ROI manipulation - replacing second roi with combination of
thresholded selection and second roi and multiply by first roi

                                roiManager("sort");
                                roiManager("add");
                                roiManager("select", 1);
                                roiManager("add");
                                nm=roiManager("count");
                                roi1=nm-2;
                                roi2=nm-1;
                                roiManager("select", newArray(roi1,roi2));
                                   roiManager("combine");
                                   roiManager("add");
                                   roiManager("delete");
                                   roiManager("select", 0);
                                   roiManager("add");
                                   roiManager("select",
newArray(roi1,roi2));
                                   roiManager("and");
                                   roiManager("add");
                                   roiManager("delete");
                                   roiManager("select", roi1);
                                   roiManager("select", 1);
                                   run("Restore Selection");
                                   roiManager("update");
                                   roiManager("select", roi1);
                                   roiManager("delete");

// ROI manipulation - replacing rois 3,5,7 with multiplication (AND) of
rois 2,4,6 and roi 1(second roi)
                                nn=roiManager("count");
                                    for (z=2;z<nn;z+=2) {
                                    t=z+1;
                                    roiManager("select", newArray(1,z));
                                    roiManager("and");
                                    roiManager("select", t);
                                    run("Restore Selection");
                                    roiManager("update");
                                    }
              path3 = dir3+list2[i];
              roiManager("deselect");
              roiManager("save", path3);
                   close();     //closes main image window
                   }

}};

if (isOpen("Exception")) {
      selectWindow("Exception");
      run("Close");           //close error windows to avoid saving to
results.
      }

 //Macro end
----

   Best regards
Stoyan

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

Re: Strange behaviour of RoI manager in batch mode

Stoyan Pavlov
Hi, dear friends,

I recently noticed a strange behaviour, when running roimanager commands in
a macro in batch mode. I don't know whether it did this before (since I
only recently started adjusting rois through macros) or probably its
expected due to the peculiarities of the batch mode?
Hear is whats happening: I wrote a macro to open an image, threshold it,
create selection and open a set of rois, which afterwards are manipulated
in the following way: second roi (number 1) is combined (OR) with the
thresholded selection and than multiplied (AND) with the first roi (number
0)and updated, than rois 2,4, 6 are multiplied by the new 2nd region and
the new selections are used to update rois 3,5 and 7. When I run this macro
in standard mode everyrhing happens as described. When however I try to run
it with batchmode set to true, everything goes haywire: roi number 1 is
replaced by number 0 and rois 3,5 and 7 are replaced by the combined  roi
1with the new thresholded selection. Here follows the code I am using for
reference. (I know I could have written it without adding the intermittent
rois , using only 'run(Restore Selection)' and 'roiManager("update")', but
somehow this made results even more unpredictable):
---
 //Macro start

dir1 = getDirectory("Choose an Image Directory ");
dir2 = getDirectory("Choose a ROI file Directory");
dir3 = getDirectory("Choose a Modified RoIs Directory");

//setBatchMode(true);

 list = getFileList(dir1);
 list2 = getFileList(dir2);

 for (i=0; i<list.length; i++) {
                path = dir1+list[i];
                showProgress(i, list.length);
                if (!endsWith(path,"/")) open(path);
                if (nImages>=1) {

                roiManager("reset");
                setThreshold(0.15,2.41);
                run("Create Selection");
                resetThreshold();

                                //loading ROIs here
                                 path2 = dir2+list2[i];
                                if (!endsWith(path2,"/")) {
                                roiManager("Open", path2);

  // ROI manipulation - replacing second roi with combination of
thresholded selection and second roi and multiply by first roi

                                roiManager("sort");
                                roiManager("add");
                                roiManager("select", 1);
                                roiManager("add");
                                nm=roiManager("count");
                                roi1=nm-2;
                                roi2=nm-1;
                                roiManager("select", newArray(roi1,roi2));
                                   roiManager("combine");
                                   roiManager("add");
                                   roiManager("delete");
                                   roiManager("select", 0);
                                   roiManager("add");
                                   roiManager("select",
newArray(roi1,roi2));
                                   roiManager("and");
                                   roiManager("add");
                                   roiManager("delete");
                                   roiManager("select", roi1);
                                   roiManager("select", 1);
                                   run("Restore Selection");
                                   roiManager("update");
                                   roiManager("select", roi1);
                                   roiManager("delete");

// ROI manipulation - replacing rois 3,5,7 with multiplication (AND) of
rois 2,4,6 and roi 1(second roi)
                                nn=roiManager("count");
                                    for (z=2;z<nn;z+=2) {
                                    t=z+1;
                                    roiManager("select", newArray(1,z));
                                    roiManager("and");
                                    roiManager("select", t);
                                    run("Restore Selection");
                                    roiManager("update");
                                    }
              path3 = dir3+list2[i];
              roiManager("deselect");
              roiManager("save", path3);
                   close();     //closes main image window
                   }

}};

if (isOpen("Exception")) {
      selectWindow("Exception");
      run("Close");           //close error windows to avoid saving to
results.
      }

 //Macro end
----

   Best regards
Stoyan





На 24.07.2017 г. 8:02 "Stoyan Pavlov" <[hidden email]> написа:

Hi, dear friends,

I recently noticed a strange behaviour, when running roimanager commands in
a macro in batch mode. I don't know whether it did this before (since I
only recently started adjusting rois through macros) or probably its
expected due to the peculiarities of the batch mode?
Hear is whats happening: I wrote a macro to open an image, threshold it,
create selection and open a set of rois, which afterwards are manipulated
in the following way: second roi (number 1) is combined (OR) with the
thresholded selection and than multiplied (AND) with the first roi (number
0)and updated, than rois 2,4, 6 are multiplied by the new 2nd region and
the new selections are used to update rois 3,5 and 7. When I run this macro
in standard mode everyrhing happens as described. When however I try to run
it with batchmode set to true, everything goes haywire: roi number 1 is
replaced by number 0 and rois 3,5 and 7 are replaced by the combined  roi
1with the new thresholded selection. Here follows the code I am using for
reference. (I know I could have written it without adding the intermittent
rois , using only 'run(Restore Selection)' and 'roiManager("update")', but
somehow this made results even more unpredictable):
---
 //Macro start

dir1 = getDirectory("Choose an Image Directory ");
dir2 = getDirectory("Choose a ROI file Directory");
dir3 = getDirectory("Choose a Modified RoIs Directory");

//setBatchMode(true);

 list = getFileList(dir1);
 list2 = getFileList(dir2);

 for (i=0; i<list.length; i++) {
                path = dir1+list[i];
                showProgress(i, list.length);
                if (!endsWith(path,"/")) open(path);
                if (nImages>=1) {

                roiManager("reset");
                setThreshold(0.15,2.41);
                run("Create Selection");
                resetThreshold();

                                //loading ROIs here
                                 path2 = dir2+list2[i];
                                if (!endsWith(path2,"/")) {
                                roiManager("Open", path2);

  // ROI manipulation - replacing second roi with combination of
thresholded selection and second roi and multiply by first roi

                                roiManager("sort");
                                roiManager("add");
                                roiManager("select", 1);
                                roiManager("add");
                                nm=roiManager("count");
                                roi1=nm-2;
                                roi2=nm-1;
                                roiManager("select", newArray(roi1,roi2));
                                   roiManager("combine");
                                   roiManager("add");
                                   roiManager("delete");
                                   roiManager("select", 0);
                                   roiManager("add");
                                   roiManager("select",
newArray(roi1,roi2));
                                   roiManager("and");
                                   roiManager("add");
                                   roiManager("delete");
                                   roiManager("select", roi1);
                                   roiManager("select", 1);
                                   run("Restore Selection");
                                   roiManager("update");
                                   roiManager("select", roi1);
                                   roiManager("delete");

// ROI manipulation - replacing rois 3,5,7 with multiplication (AND) of
rois 2,4,6 and roi 1(second roi)
                                nn=roiManager("count");
                                    for (z=2;z<nn;z+=2) {
                                    t=z+1;
                                    roiManager("select", newArray(1,z));
                                    roiManager("and");
                                    roiManager("select", t);
                                    run("Restore Selection");
                                    roiManager("update");
                                    }
              path3 = dir3+list2[i];
              roiManager("deselect");
              roiManager("save", path3);
                   close();     //closes main image window
                   }

}};

if (isOpen("Exception")) {
      selectWindow("Exception");
      run("Close");           //close error windows to avoid saving to
results.
      }

 //Macro end
----

   Best regards
Stoyan

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