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 |
Hi Thomas,
unfortunately I don't know matlab, but it seems to my that you can it in ImageJ without very much programming, i.e., in a macro: - Image>Stacks>Reslice to have the z direction run in x or y. - Convert to float and subtract the background value, so that the background gets a value of 0 - Pad the canvas size to a square that is a power of 2. - Create a 32-bit image of the same size with you function centered in the middle, running in the same x or y direction as the original z direction, only in the middle line. - For all stack slices, run Process>Math>FD Math and correlate (with inverse transform) the images of the resliced stack with the image having the function. - Combine the output images to a stack, and reslice to the original orientation if desired. If you want to do programming in Java, you could also use the built-in 1D FHT (fast Hartley transform) of ImageJ. https://github.com/imagej/imagej1/blob/master/ij/process/FHT.java Correlation is simply multiplying the FHT arrays index by index, then transform back (inverseTransform1D). Michael ________________________________________________________________ On Feb 26, 2015, at 12:14, Thomas Julou wrote: > 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 -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Free forum by Nabble | Edit this page |