Posted by
Michael Schmid on
May 14, 2009; 9:35pm
URL: http://imagej.273.s1.nabble.com/1D-autocorrelation-function-tp3692494p3692504.html
Hi Larry,
maybe there is a misunderstanding:
My RDF plugin calculates the radial distribution function of particle
CENTERS. I have updated the documentation to make this more clear.
If you are interested in the radially averaged autocorrelation of the
binary image (thus including information on particle sizes and
shapes), here is a macro for this task.
Note that the mailer may add line breaks in long lines such as the
ones starting with 'run("FD Math'; in that case you have to join
these lines.
// ImageJ macro to calculate the Radially Averaged Autocorrelation
Function,
// Corrected for finite size effects
// The output is normalized to a value of 1 at zero radius
// and corrected for effects of the finite image size.
// (No need to extend the image size for avoiding edge effects)
//
// Use with a binary input image.
// Needs the "Radial Profile" plugin,
http://rsb.info.nih.gov/ij/
plugins/radial-profile.html
//
// Version: 2008-May-14 Michael Schmid
//
doStack=false;
if (nSlices()>1) doStack = getBoolean("Get RDF from full stack?");
setBatchMode(true);
firstSlice=getSliceNumber();
lastSlice=getSliceNumber();
if (doStack) {
firstSlice=1;
lastSlice=nSlices();
}
width=getWidth;
height=getHeight;
getPixelSize(unit, pixelWidth, pixelHeight);
run("Select None");
//maxRadius may be modified, should not be larger than 0.3*minOf
(width, height);
maxRadius=0.3*minOf(width, height);
minFFTsize=1.3*maxOf(width, height);
title=getTitle();
size=4;
while(size<minFFTsize) size*=2;
for (slice=firstSlice; slice<=lastSlice; slice++) {
//make autocorrelation of particle image
tempTitle="temp-"+random();
run("Duplicate...", "title="+tempTitle);
tempID=getImageID();
getRawStatistics(nPixels, mean);
run("Canvas Size...", "width="+ size+" height="+ size+"
position=Center zero");
makeRectangle(floor((size-width)/2), floor((size-height)/2),
width, height);
run("Make Inverse");
run("Set...", "value="+mean);
run("Select None");
getRawStatistics(nPixels, mean);
run("FD Math...", "image1=["+tempTitle+"] operation=Correlate
image2=["+tempTitle+"] result=AutoCorrelation do");
psID=getImageID();
run("Subtract...", "value="+(nPixels*mean*mean));
selectImage(tempID);
close();
//make autocorrelation reference to correct finite image size effects
newImage("frame", "8-bit White", width, height, 1);
run("Set...", "value=255");
tempID=getImageID();
rename(tempTitle);
run("Canvas Size...", "width="+ size+" height="+ size+"
position=Center zero");
run("FD Math...", "image1=["+tempTitle+"] operation=Correlate
image2=["+tempTitle+"] result=AutoCorrReference do");
refID=getImageID();
imageCalculator("Divide", psID,refID);
selectImage(refID);
close();
selectImage(tempID);
close();
//prepare normalized power spectrum for radial averaging
selectImage(psID);
circleSize=2*floor(maxRadius)+1;
norm = getPixel(size/2, size/2);
run("Divide...", "value="+norm);
run("Specify...", "width="+circleSize+" height="+circleSize+" x="+
(size/2+0.5)+" y="+(size/2+0.5)+" oval centered");
run("Radial Profile", "x="+(size/2+0.5)+" y="+(size/2+0.5)+"
radius="+floor(maxRadius)-1);
plotID=getImageID();
selectImage(psID);
close();
Plot.getValues(x, y);
if (slice==firstSlice) ySum = newArray(y.length);
for (i=0; i<y.length; i++)
ySum[i]+=y[i]/nSlices;
selectImage(plotID);
close();
}
if (pixelWidth==pixelHeight) {
for (i=0; i<x.length; i++)
x[i] *= pixelWidth;
} else
unit = "pixels";
if (doStack) title = title + " (stack)";
Plot.create("Autocorrelation of "+title, "Distance ("+unit+")",
"Normalized Autocorrelation", x, ySum);
setBatchMode(false);
Best wishes,
Michael
________________________________________________________________
On 14 May 2009, at 19:38, Larry Anovitz wrote:
> Michael
> I gave it a try, and you are right, this is much faster. The
> results do
> not, however seem to be identical.
> Since you were curious about the comparison of the two techniques,
> here are
> the results. Unfortunately, the server won’t let me sent
> Figures, but if you want to see them send me a direct e-mail, mine
> is listed
> below.
>
> The RDF macro/plug-in was done on the full 2048 x 2048 image (the
> original
> image is actually a 1024 x 1024 image
> Copied 4 times in order to try to reduce the edge effects. This
> may not be
> necessary for the RDF approach).
> The 2-point correlation plug-in. It was done on the same 4x Image,
> downsampled to 1024 x 1024 using the Averaging Reducer plugin
>
> There are several differences between
> 1. the 2PC curve is smoother, and composed of about 10x more points
> 2. the Y scale is different, with a maximum on the RDF af about 4.5
> and the
> 2PC or about 4000. This is probably immaterial, however, as this
> wil be
> normalized
> 3. there is a long tail in the 2PC curve that is probably an
> artifact of the
> image multiplication and edges. It can be fitted as a stretched
> exponential
> and subtracted
> 4. importantly, the sharp drop-off in the curve appears to be at
> about 5-10x
> larger r in the RDF plot (between about 8 and 25 microns) than the
> 2PC plot
> (between 1.5 and 3 microns)
>
> I can also compare these two results (normalized, and with the tail
> subtracted from the 2PC curve)
> to a plot of the correlation function calculated from a measured
> neutron
> scattering curve and a pore Volume obtained from the image.
> This has a half-fall distance of about 4 microns. Thus the measured
> values
> lie between the other 2.
>
> The direct neutron measurements are for scales up to approx 24
> microns, so
> most of this curve is directly constrained. However, while it may
> not seem
> very important in the correlation plot, a lot of the calculated
> volume comes
> from that high-r part of the curve
>
>
> What do you think ?
>
> --larry
>
>
> On 5/14/09 4:19 AM, "Michael Schmid" <
[hidden email]> wrote:
>
>> Hi Larry,
>>
>> if it is simply the radial distribution function that you are
>> interested in you can try my macro
>>
http://imagejdocu.tudor.lu/doku.php?
>> id=macro:radial_distribution_function
>>
>> It needs about half a minute (2.4 GHz Core2Duo) and 500 MB RAM for a
>> 2048*2048 binary image.
>> It uses the FFT, but does not assume periodic boundary conditions.
>> Instead, it rather expands the image (in this case to 4096*4096) and
>> corrects for the finite size (edge effects) of the image. So you need
>> not (and should not) expand your image when using it.
>> ---
>> Concerning the r resulution: For radii well above 1, there should be
>> enough pixels in each zone between r and r+0.3 pixels. My macro
>> simply uses the Radial Profile Plugin, which uses increments of 1 for
>> the radius.
>>
http://rsb.info.nih.gov/ij/plugins/radial-profile.html>>
>> It would be interesting to see how the results of my macro compare
>> with the plugin by Dscho; if you find any significant differences or
>> a bug in my macro, let me know, please.
>>
>> Michael
>> ________________________________________________________________
>>
>> On 13 May 2009, at 22:47, Larry Anovitz wrote:
>>
>>> Hi,
>>> A few weeks back, Gabriel was kind enough to send me the
>>> suggestion
>>> below in response to my question about a plug-in to calculate 2-
>>> point
>>> correlation functions.
>>> Having been working with this plug-in for a few weeks now, I
>>> have run
>>> into a couple of problems, and one query, which I hope someone can
>>> help me
>>> solve.
>>> The biggest problem is memory. Running this plug-in takes a
>>> lot. If I
>>> have a 1024 x 1024 pixel image I can get it to solve if I set the
>>> memory to
>>> 2 GB, If I have a 2048 x 2048 image I have not yet gotten the
>>> program to
>>> work. Instead, it comes back with a window saying that it has used
>>> up the
>>> available memory (I've used values as high as 4 GB, and
>>> downloaded the
>>> newest version of ImageJ for the Mac this afternoon). While I have
>>> tried
>>> down-sampling the image, and this works, it does not give me the
>>> resolution
>>> I would like, and I need to keep the overall image size large to
>>> avoid edge
>>> effects (I'd like to go to a 4096 x 4096 image at least).
>>> The second problem is that the "naïve" computation version of
>>> the plug
>>> in does not seem to work at all. The pop-up window does say that
>>> this is
>>> slow, but I've left if for hours without any results.
>>> Finally, a question. The plug-in has a default radius step
>>> (changeable)
>>> of 0.3 pixels. Since this is (obviously) less than 1 pixel, and the
>>> correlation has to do with the relationship between pixels, this
>>> seems a bit
>>> odd. I suspect it may be due to the FFT method of obtaining the
>>> calculation, but am not sure, and was wondering if Dsho (who
>>> wrote the
>>> plug-in) could enlighten me.
>>>
>>> Many thanks in advance for help with this.
>>>
>>> --Larry
>>>
>>> I am running a Mac, with system version 10.5.6, a 2 x 3.2 GHz Quad-
>>> Core
>>> Intel Xeon processor, and 6 GB of 800 MHz DDR2 FB-DIMM memory.
>>>
>>> --Larry Anovitz
>>>
>>>
>>> --
>>> Dr. Lawrence M. Anovitz
>>> MS 6110 PO Box 2008
>>> Aqueous and Geochemistry Group
>>> Oak Ridge National Laboratory
>>> Oak Ridge, Tennessee 37831-6110
>>>
>>> 865-574-5034 : phone
>>> 865-574-4961 : fax
>>>
>>>
[hidden email]
>>>
>>>
>>>
>>>
>>>
>>> On 4/6/09 10:46 AM, "Gabriel Landini" <
[hidden email]> wrote:
>>>
>>>> Larry,
>>>> Are you sure you do not mean the "two-point correlation function"?
>>>> That is a
>>>> commonly used technique in condensed matter physics (I have seen
>>>> it several
>>>> times used to characterise fractal agglormerates and porous
>>>> materials).
>>>>
>>>> Dsho wrote a plugin some time ago. I have not used it, though:
>>>>
>>>>
http://wbgn013.biozentrum.uni-wuerzburg.de/ImageJ/two-point->>>> correlation.html
>>>>
>>>> Cheers,
>>>>
>>>> G.