Help with computing correlations along z in stacks.

Posted by Thomas Julou on
URL: http://imagej.273.s1.nabble.com/Help-with-computing-correlations-along-z-in-stacks-tp5011785.html

Hello,

I hope this list is the right place to ask my question.
In order to achieve robust segmentation of bacteria from white light pictures, we use a "correlation" image. The principle is to acquire a z-stack of bright field pictures, and to correlate the intensity along z with an « expected" intensity profile. So far, we wrote the code in Matlab only.

However for several purpose, I’d be interested in having the code written for imageJ (among other, doing the acquisition with micro-manager and processing images on the fly; though I know I could call MM from Matlab). Since I'm new to plug-in programming (but anticipate that speed will matter in this case), I'd really appreciate getting pointers to appropriate libraries / examples.

Here are a few specific questions:
- is it better to run a FFT per (x, y) intensity profile or is there any kind of "vectorized syntax"?
- which fft library do you recommend? fftw? imglib2?
- is it realistic to write this for cuda / opencl already? (to me it looks like a good task for a gpu)?

Below is the code I wrote for matlab since it might help to answer.
Thank you in advance for your help. Best,

Thomas

--
Thomas Julou  |  Computational & Systems Biology  |  Biozentrum – University of Basel  |  Klingelbergstrasse 50/70 CH-4056 Basel  |  +41 (0)61 267 16 21


> function IM_CORREL = correlImg(IM, sigma)
> [ny, nx, nz] = size(IM);
> z = (1:nz)';
> center = round(nz/2);
>
> zProfile = - (z-center) .* exp(- (z-center).^2 / (2*sigma^2));
> zProfileFFT = fft(zProfile);
> zProfileFFT(1) = 0;
>
> zProfileFFTc = conj(zProfileFFT);
> Z_PROFILE_FFT_C(1,1,:) = zProfileFFTc;
> Z_PROFILE_FFT_C = repmat(Z_PROFILE_FFT_C, [ny nx]);
>
> IM_Z_FFT = fft(IM, [], 3);
> IM_Z_FFT(:,:,1) = 0;
> CORREL = real(ifft(IM_Z_FFT.*Z_PROFILE_FFT_C, [], 3));
>
> idx = [center+1:nz 1:center];
> IM_CORREL = CORREL(:,:,idx);

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html