Login  Register

Re: correction for constant drift

Posted by Michael Schmid on Jul 05, 2010; 8:45am
URL: http://imagej.273.s1.nabble.com/correction-for-constant-drift-tp3687724p3687727.html

Hi Henny,

below is a macro for doing it manually. Start it, then click on the  
same feature in the first and last slice; if you wish, also in other  
slices. It will interpolate for those slices where you did not mark  
the feature (the interpolated position is not shown while the macro  
is running - that might be useful to add in a later version).
Press the space bar when done with marking, ESC to abort.

The macro enlarges the image to make it include all frames. It adds  
some extra space if the 'extraspace' variable is set to a value  
larger than 0.

Michael
________________________________________________________________

macro 'Manual Stack Register' {
   extraspace = 5; //padding the image at all sides by this value  
(pixels)

   requires("1.42j");
   n=nSlices();
   if (n<2) exit ("stack required");
   xs=newArray(nSlices);
   ys=newArray(nSlices);
   for (i=0; i<n; i++)
     xs[i] = -1; //initialize positions as unset

   nClicked = 0;
   i=getSliceNumber()-1;
   flags=0;
   lasti = -1;
   posS = "";
   while (!isKeyDown("space")) {
     getCursorLoc(x, y, z, flags);
     if (flags&leftClick !=0) {
       makePoint(x,y);
       xs[i] = x;
       ys[i] = y;
       nClicked++;
       lasti = i;
       do {
         wait(50);
         getCursorLoc(x, y, z, flags);
       } while (flags&leftClick !=0);
     }
     if (i != z) {     //slice changed
       i = z;
       if (xs[i]>=0) {
         makePoint(xs[i],ys[i]);
         lasti = i;
       }
       while (isKeyDown("alt")) wait(50);
     }
     wait(20);
     if (lasti>=0) posS = "pos. from "+(lasti+1);
     showStatus("','=prev, '.'=next, space=done, esc=abort. "+posS);
   }
   if (nClicked<2) exit("Abort - at least two positions required");
   lasti = -1;
   for (i=0; i<n; i++) {
     if (xs[i]>=0) {
       if (lasti<0) {
         lastx=xs[i];
         lasty=ys[i];
       }
       for (j=lasti+1; j<i; j++) {  //interpolate
         xs[j] = lastx + (xs[i]-lastx)*(j-lasti)/(i-lasti);
         ys[j] = lasty + (ys[i]-lasty)*(j-lasti)/(i-lasti);
       }
       lastx=xs[i];
       lasty=ys[i];
       lasti=i;
     }
   }
   if (lasti<n-1) {
     for (j=lasti+1; j<n; j++) {
       xs[j] = lastx;
       ys[j] = lasty;
     }
   }
   Array.getStatistics(xs, xmin, xmax, mean, stdDev);
   Array.getStatistics(ys, ymin, ymax, mean, stdDev);
   newwidth = getWidth()+(xmax-xmin)+2*extraspace;
   newheight = getHeight() +(ymax-ymin)+2*extraspace;
   run("Canvas Size...", "width="+ newwidth +" height="+ newheight +"  
position=Top-Left zero");
   for (i=0; i<n; i++) {
     setSlice(i+1);
     run("Translate...", "x="+(xmax-xs[i]+extraspace)+" y="+(ymax-ys
[i]+extraspace)+" slice");
   }
   showStatus("stack registered");

}

________________________________________________________________

On 3 Jul 2010, at 16:15, JOEL B. SHEFFIELD wrote:

> You might put the set of images into a stack, and then run the  
> TurboReg
> plugin to alilgn the images.
>
> Joel
>
>
> On Sat, Jul 3, 2010 at 9:16 AM, Henny Zandbergen <
> [hidden email]> wrote:
>
>> I have a series of electron microscopy images which have  
>> (approximately) a
>> constant drift.
>>
>> Is there plugin or other something else than can apply  
>> displacements on
>> this series of images in which I for instance put in the total  
>> shift +
>> number of images or the shift between two images?
>>
>> henny
>> --
>> --------------------------------
>> Henny Zandbergen, tel 31-15-2782266, fax 31-15-2786600
>>
>
>
>
> --
>
>
> Joel B. Sheffield, Ph.D
> Department of Biology
> Temple University
> Philadelphia, PA 19122
> Voice: 215 204 8839
> e-mail: [hidden email]
> URL:  http://astro.temple.edu/~jbs