timholy/Images.jl — pull request #231 by romainFr (2014-12-04 23:20:57+00:00)
Title: Discrete Fourier transform registration (subpixel translation correction)

Something I needed at some point that might be useful to more people. It's taken from [Guizar & al](http://www.opticsinfobase.org/ol/fulltext.cfm?uri=ol-33-2-156&id=148843) (Manuel Guizar-Sicairos, Samuel T. Thurman, and James R. Fienup, "Efficient subpixel image registration algorithms," Opt. Lett. 33, 156-158 (2008)) and (very) inspired by the [matlab code] (http://www.mathworks.com/matlabcentral/fileexchange/18401-efficient-subpixel-image-registration-by-cross-correlation) provided by the authors.

Function ```subpixelshift(img,rowShift,colShift)``` translates an image by the given amount. ```dftReg(imgser,[ref,ufac,align])``` performs the registration of ```imgser``` to a reference ```ref``` (by default the first frame of ```imgser```). Either returns an array of registration parameters (by default), or the registered image (if ```align==true```). ```usfac``` is the upsampling factor (10 by default). Finally ```alignFromDft``` performs the registration given an array of registration parameters.

This doesn't work with color images for now.

As a side-note, this would also work for rotations by transforming the image to polar coordinates beforehand.

```julia
> using Images, TestImages
> img = testimage("mandril_gray");
> img2 = subpixelshift(img,40.3,30.7);
> dftReg(img2,ref=img,ufac=10)
1x3 Array{Float64,2}:
0.332617 -40.3 -30.7
```