correcting a constant drift in a image stack

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

correcting a constant drift in a image stack

Wes Armour
Hi all,

I have a series of images (600) that have a constant drift of 1/30 of a
pixel between frames. I have tried various align plugins but none seem to work.
This doesn't surprise me because the main object in the images changes.

Is there a way I can do an incremental translation to the images?
For example...
Translate image1 by 1x0.0333 in x
Translate image2 by 2x0.0333 in x
Translate image3 by 3x0.0333 in x
Translate image4 by 4x0.0333 in x

Thanks for any help,

Wes.
Reply | Threaded
Open this post in threaded view
|

Re: correcting a constant drift in a image stack

jiho
On 2009-March-17  , at 11:34 , Wes wrote:

> Translate image1 by 1x0.0333 in x
> Translate image2 by 2x0.0333 in x
> Translate image3 by 3x0.0333 in x
> Translate image4 by 4x0.0333 in x

I am not sure this would apply to subpixel movement but you could  
batch shift the source images by the amount of drift using  
ImageMagick. Here is a small shell script template:

#!/bin/sh
# Assuming images are named like IMG001.JPG, IMG002.JPG, etc. and the  
shift is from left to right
# To adapt to your own scenario

# Get width and height of the first image
width=`identify -format "%[fx:w]" IMG001.JPG`
height=`identify -format "%[fx:h]" IMG001.JPG`
echo $width
echo $height

# Create temporary dir to work in
mkdir tmp

nbImages=3
for (( i = 1; i <= $nbImages; i++ )); do
     # Compute the amount of pixels to translate the image by
     moveBy=`echo $i*0.0333` | bc

     # Construct the name of the current image
     curImg="IMG"$(printf "%03i" $i)".JPG"

     # Recrop image, translating the frame to the right by $moveBy  
pixels
     # At the right of the image, the image is "wrapped" around the  
"missing" pixels are filled with the pixels from the left
     convert -crop "$width"x"$height"+"$moveBy"+0! $curImg tmp/"$curImg"
done

# At this point the images in tmp/ have all the same size and are  
shifted to a common reference.

exit 0


I hope that helps.

Jean-Olivier Irisson
---
Division of Applied Marine Physics
Rosenstiel School of Marine and Atmospheric Sciences
4600 Rickenbacker Causeway, Miami, Florida 33149-1098
+1 786 342 3410
http://jo.irisson.free.fr/work/
Reply | Threaded
Open this post in threaded view
|

Re: correcting a constant drift in a image stack

Wayne Rasband
In reply to this post by Wes Armour
On Mar 17, 2009, at 11:34 AM, Wes wrote:

> Hi all,
>
> I have a series of images (600) that have a constant drift of 1/30 of a
> pixel between frames. I have tried various align plugins but none seem
> to work.
> This doesn't surprise me because the main object in the images changes.
>
> Is there a way I can do an incremental translation to the images?
> For example...
> Translate image1 by 1x0.0333 in x
> Translate image2 by 2x0.0333 in x
> Translate image3 by 3x0.0333 in x
> Translate image4 by 4x0.0333 in x

Here is a macro that will correct for the drift:

   requires("1.42l");
   setBatchMode(true);
   drift = 0.0333;
   offset = 0;
   for (i=1; i<=nSlices; i++) {
      setSlice(i);
      offset += drift;
      run("Translate...", "interpolation=Bicubic slice y=0 x="+offset);
   }

It requires the v1.42l daily build, which updates the Image>Translate
command to work with sub-pixel offsets. V1.42l also adds a Bicubic
interpolation option to the Translate, Scale, Rotate and Adjust>Size
commands. The bicubic interpolation method used is from Chapter 16 of
"Digital Image Processing: An Algorithmic Introduction Using Java" by
Wilhelm Burger and Mark Burge. The 'a' control parameter is set to 0.5
(Catmull-Rom interpolation). You can update to the daily build by using
the Help>Update ImageJ command and selecting "daily build" from the
drop down menu.

-wayne
Reply | Threaded
Open this post in threaded view
|

Re: correcting a constant drift in a image stack

Wes Armour
Many thanks for your replies Wayne and Jean-Olivier,

I did try the convert script but it only gives pixel level alignment.
The macro worked far better giving sub-pixel alignment which is what I
needed.

Cheers,

Wes.

On Tue, 2009-03-17 at 16:14 -0400, Wayne Rasband wrote:

> On Mar 17, 2009, at 11:34 AM, Wes wrote:
>
> > Hi all,
> >
> > I have a series of images (600) that have a constant drift of 1/30 of a
> > pixel between frames. I have tried various align plugins but none seem
> > to work.
> > This doesn't surprise me because the main object in the images changes.
> >
> > Is there a way I can do an incremental translation to the images?
> > For example...
> > Translate image1 by 1x0.0333 in x
> > Translate image2 by 2x0.0333 in x
> > Translate image3 by 3x0.0333 in x
> > Translate image4 by 4x0.0333 in x
>
> Here is a macro that will correct for the drift:
>
>    requires("1.42l");
>    setBatchMode(true);
>    drift = 0.0333;
>    offset = 0;
>    for (i=1; i<=nSlices; i++) {
>       setSlice(i);
>       offset += drift;
>       run("Translate...", "interpolation=Bicubic slice y=0 x="+offset);
>    }
>
> It requires the v1.42l daily build, which updates the Image>Translate
> command to work with sub-pixel offsets. V1.42l also adds a Bicubic
> interpolation option to the Translate, Scale, Rotate and Adjust>Size
> commands. The bicubic interpolation method used is from Chapter 16 of
> "Digital Image Processing: An Algorithmic Introduction Using Java" by
> Wilhelm Burger and Mark Burge. The 'a' control parameter is set to 0.5
> (Catmull-Rom interpolation). You can update to the daily build by using
> the Help>Update ImageJ command and selecting "daily build" from the
> drop down menu.
>
> -wayne
This e-mail and any attachments may contain confidential, copyright and or privileged material, and are for the use of the intended addressee only. If you are not the intended addressee or an authorised recipient of the addressee please notify us of receipt by returning the e-mail and do not use, copy, retain, distribute or disclose the information in or attached to the e-mail.
Any opinions expressed within this e-mail are those of the individual and not necessarily of Diamond Light Source Ltd.
Diamond Light Source Ltd. cannot guarantee that this e-mail or any attachments are free from viruses and we cannot accept liability for any damage which you may sustain as a result of software viruses which may be transmitted in or with the message.
Diamond Light Source Limited (company no. 4375679). Registered in England and Wales with its registered office at Diamond House, Harwell Science and Innovation Campus, Didcot, Oxfordshire, OX11 0DE, United Kingdom