1

I'm trying to crop sections in an image and then averaging all of them. I'm recycling my previous macros on imageJ. Previous macros work well by doing loops in a list of ROIs. But, for this one, I can't understand why the loop does not move to the next ROI in the list. Instead, I got the job N-times as the number of ROIs I have in the list but the macro uses the first ROI information. This is my macro:

runMacro("OpenROI");
rename("AA");
selectWindow("AA");
n=roiManager("count");

for(i=0;i<n;i++){
    roiManager("select",i);
    run("Copy");
    run("Internal Clipboard");
    rename(i);
}

selectWindow("AA");
run("Close");
run("Images to Stack", "name=Stack title=[] use");
run("Z Project...", "projection=[Average Intensity]");

Someone can catch what am I losing it? Thanks

Jonathan Pacheco
  • 531
  • 1
  • 6
  • 16

1 Answers1

1

I found a solution, the line:

selectWindow("AA");

must be inside the loop in order to set the ROI on the image. Full code is as follows:

runMacro("OpenROI");
rename("AA");

n=roiManager("count");

for(i=0;i <n; i++){
    selectWindow("AA");
    roiManager("select",i);
    run("Copy");
    run("Internal Clipboard");
    rename(i);
}

selectWindow("AA");
run("Close");
run("Images to Stack", "name=Stack title=[] use");
run("Z Project...", "projection=[Average Intensity]");
Jonathan Pacheco
  • 531
  • 1
  • 6
  • 16