Login  Register

Re: Cyclic translation transform

Posted by jerry novakk on Jul 30, 2015; 8:47am
URL: http://imagej.273.s1.nabble.com/Cyclic-translation-transform-tp5013479p5013808.html

Below I've added a Macro that periodically Translates all images in a stack for the same input amount in x & y direction.

__________________________________________________________________________________________

//Stack needs to be open!!

Dialog.create("Translate horizontal");
Dialog.addNumber("X", 0);
Dialog.show();
X= Dialog.getNumber();

Dialog.create("Translate vertical");
Dialog.addNumber("Y", 0);
Dialog.show();
Y= Dialog.getNumber();

for(i=1;i<=nSlices;i++){
  setSlice(i);

    getDimensions(W, H, dummy, dummy, dummy);

  //translate horizontal

    if (X<0) {
      Xa=W+X;
      run("Select All");
      run("Specify...", "Width=abs(X) Height=H x=0 y=0");
      run("Copy");
      run("Select None");
      run("Translate...", "x=X y=0 interpolation=None");
      run("Specify...", "Width=abs(X) Height=H x=Xa y=0");
      run("Paste");
    }
    else {
      Xb=W-X;
      run("Select All");
      run("Specify...", "Width=abs(X) Height=H x=Xb y=0");
      run("Copy");
      run("Select None");
      run("Translate...", "x=X y=0 interpolation=None");
      makeRectangle(0, 0, abs(X), H);
      run("Paste");
    }

  //translate vertical
 
    if (Y<0) {
      Ya=H+Y;
      run("Select All");
      run("Specify...", "Width=W Height=abs(Y) x=0 y=0");
      run("Copy");
      run("Select None");
      run("Translate...", "x=0 y=Y interpolation=None");
      run("Specify...", "Width=W Height=abs(Y) x=0 y=Ya");
      run("Paste");
    }
    else {
      Yb=H-Y;
      run("Select All");
      run("Specify...", "Width=W Height=abs(Y) x=0 y=Yb");
      run("Copy");
      run("Select None");
      run("Translate...", "x=0 y=Y interpolation=None");
      makeRectangle(0, 0, W, abs(Y));
      run("Paste");
    }
 
    run("Select None");
}

__________________________________________________________________________________________