How can I make a shifted duplicate of a ROI?

Hi there. I have created a ROI with setTool("freeline");. For other purposes, I want to duplicate this ROI and move the duplicate. The goal is to have i ROIs, where i-1 ROIs are shifted duplicates of the first ROI. How can I achieve this? Many thanks for any hints!

1 Like

Perhaps ?

newImage("Untitled", "8-bit white", 512, 512, 1);
//setTool("line");
makeLine(39, 128, 319, 59);
roiManager("Add");
roiManager("Select", 0);
roiManager("translate", 0, 100);
run("Create Selection");
run("Restore Selection");
roiManager("Add");
roiManager("Show All");
1 Like

Thank you! But when I try to sequentially duplicate+shift ROIs 10 times by 1 pixel in a for loop, I’m doing something wrong, because it creates 9 replicates with the same shift:

      for (i=0; i<10; i++) {
roiManager("Select", i);
roiManager("translate", 1, 0);
run("Create Selection");
run("Restore Selection");
roiManager("Add");
roiManager("Show All");
      }

I also tried to shift and duplicate the same ROI by different values, but that also doesn’t work:

      for (i=0; i<10; i++) {
roiManager("Select", 0);
roiManager("translate", i, 0);
run("Create Selection");
run("Restore Selection");
roiManager("Add");
roiManager("Show All");
      }

EDIT: Finally! This creates new shifted ROIs in 1 pixel distances.

      for (i=0; i<10; i++) {
roiManager("Select", i);
roiManager("translate", i, 0);
run("Create Selection");
run("Restore Selection");
roiManager("Add");
roiManager("Show All");
      }
newImage("Untitled", "8-bit white", 512, 512, 1);
makeLine(39, 128, 319, 59);
roiManager("Add");
// Choose the offset x.
x=4;
// Choose the number n of lines.
n=8;
for(i=0;i<n;i++)
{
roiManager("Select",0);
roiManager("translate", 0, x);
run("Create Selection");
run("Restore Selection");
roiManager("Add");
}
roiManager("Select", 0);
roiManager("Delete");
roiManager("Show All with labels");
1 Like