Login  Register

Re: Autocorrelation using Fourier

Posted by Michael Schmid on Dec 14, 2010; 9:39am
URL: http://imagej.273.s1.nabble.com/Autocorrelation-using-Fourier-tp3686185p3686186.html

Hi Norbert,

here is a rough equivalent to the core of your correlation macro  
using FFT:

k100 = 100; //how far out we need the autocorrelation
run("FD Math...", "image1=AutoCorr.tif operation=Correlate  
image2=AutoCorr.tif result=Result do");
width = getWidth();
run("Divide...", "value="+(width*width)); //FD Math gives sum over  
all pixels; convert to mean
half = width/2;  //origin is at the center
makeLine(half, half, half+k100, half);
run("Plot Profile");

It won't be 100% exact because the FFT version extends the image  
assuming periodic boundary conditions, not using a value of zero as  
the 'translate' command in your macro.
This won't matter for your test image which has a rather large border  
with zero value.
If periodic boundary conditions are a problem, simply enlarge the  
image to the next power of 2 with zero background.

Hope this helps.

Michael
________________________________________________________________


On 13 Dec 2010, at 23:19, Norbert Vischer wrote:

> Hello all,
>
> I created a test macro that performs 1D autocorrelation.
> It runs well in a few seconds, but I wonder if the speed can be  
> improved by Fourier techniques for larger data sets.
>
> The macro first creates a test image that is randomly covered with  
> white horizontal lines with a mean length of 20 pixels. The image  
> is then periodically multiplied with a horizontally shifted copy,  
> so I get the autocorrelation plot from which I can derive the mean  
> line length. The output looks like this:
>
>   Simulated Length = 20.17
>   Measured Length = 20.06
>
> Later in reality, the white lines will represent the fluorescent  
> duration of molecules, and the data set will be much larger.
> I doubt that a native plugin will do the same thing much faster,  
> but has anyone a suggestion how to use Fourier techniques?
>
> My demo macro can be downloaded from:
> http://simon.bio.uva.nl/objectj/GenericMacros/AutoCorrelation/ 
> AutoCorrelation-2.txt
>
>
> Norbert Vischer