http://imagej.273.s1.nabble.com/FFT-and-Inverse-FFT-problem-for-an-Electron-Microscope-Image-tp5013915p5013967.html
Thank you very much for that. I will try this code later when I am near my computer.
Just one query please ? How does it work where I would like my final image to be 16 bits please ? Thank you for taking the time to do this.
> On 10 Aug 2015, at 13:30, Brian Northan <
[hidden email]> wrote:
>
> If anyone is interested in an example of ops fft, below is a jython script
> example that shows how to use the ops fft interface (it also uses
> parameterized scripting and calls pieces of imglib2 using jython). It is
> based on this imglib tutorial
>
>
https://github.com/imglib/imglib2-tutorials/blob/master/src/main/java/Example6c.java>
> If one copies and pastes the code at the bottom of this message into the
> script editor of the latest Fiji release it should run and produce the same
> result as the java tutorial. The images (DrosophillaWing.tif and
> WingTemplate.tif) are available in the imglib2-tutorials repository.
>
>
https://github.com/imglib/imglib2-tutorials>
> Keep in mind the ops fft interfaces are fairly new and still in beta.
> Feedback (and contributions) are very welcome - Brian
>
> # @DisplayService display
> # @OpService ops
> # @net.imagej.Dataset image
> # @net.imagej.Dataset template
>
> '''
> This example is an 'ops' version of:
>
>
http://fiji.sc/ImgLib2_Examples#Example_6c_-_Complex_numbers_and_Fourier_transforms>
> for which the code and images can be found
>
>
https://github.com/imglib/imglib2-tutorials>
> '''
> from net.imglib2.img.display.imagej import ImageJFunctions;
> from net.imglib2.type.numeric.complex import ComplexFloatType;
> from net.imglib2.outofbounds import OutOfBoundsMirrorExpWindowingFactory;
>
> from net.imglib2.converter import ComplexImaginaryFloatConverter;
> from net.imglib2.converter import ComplexPhaseFloatConverter;
> from net.imglib2.converter import ComplexRealFloatConverter;
>
> from jarray import array
>
> # perform fft of the template
>
> # basic fft call with no parameters
> #templateFFT=ops.fft(template.getImgPlus())
>
> # alternatively to pass an outofbounds factory we have to pass every
> parameter. We want:
> # output='None', input=template, borderSize=10 by 10, fast='True',
> outOfBoundsFactor=OutOfBoundsMirrorExpWindowingFactory
> templateFFT=ops.fft(None, template.getImgPlus(), array([10, 10], 'l'),
> True, OutOfBoundsMirrorExpWindowingFactory(0.25));
>
> # display fft (by default in generalized log power spectrum)
> ImageJFunctions.show(templateFFT).setTitle("fft power spectrum");
>
> # display fft phase spectrum
> ImageJFunctions.show( templateFFT,ComplexPhaseFloatConverter() ).setTitle(
> "fft phase spectrum" );
>
> # display fft real values
> ImageJFunctions.show( templateFFT,ComplexRealFloatConverter() ).setTitle(
> "fft real values" );
>
> # display fft imaginary values
> ImageJFunctions.show( templateFFT, ComplexImaginaryFloatConverter()
> ).setTitle( "fft imaginary values" );
>
> # complex invert the fft of the template
> c = ComplexFloatType();
> for t in templateFFT:
> c.set(t);
> t.complexConjugate();
> c.mul(t);
> t.div(c);
>
> # create Img memory for inverse FFT and compute inverse
> templateInverse=ops.createImg(array([template.dimension(0),
> template.dimension(1)], 'l'))
>
> ops.ifft(templateInverse, templateFFT)
> display.createDisplay("template inverse", templateInverse)
>
> # convolve templateInverse with image
> final=ops.convolve(image, templateInverse);
> display.createDisplay("final", final)
>
>> On Fri, Aug 7, 2015 at 4:40 PM, Curtis Rueden <
[hidden email]> wrote:
>>
>> Hi everyone,
>>
>> Regarding FFT and IFFT operations, I just wanted to mention that ImageJ Ops
>> (distributed as part of ImageJ2!) does have these operations [1, 2, 3, 4,
>> 5], driven by the powerful ImgLib2 library [6]. And very soon to be using
>> JTransforms [7] as mentioned by Dimiter (currently it uses Mines JTK [8,
>> 9]).
>>
>> So for anyone considering reinventing this wheel: please consider
>> contributing to Ops rather that starting a new and instantly obsolete
>> plugin. ;-)
>>
>> Regards,
>> Curtis
>>
>> [1]
>>
>>
https://github.com/imagej/imagej-ops/tree/imagej-ops-0.16.0/src/main/java/net/imagej/ops/filter/fft>> [2]
>>
>>
https://github.com/imagej/imagej-ops/tree/imagej-ops-0.16.0/src/main/java/net/imagej/ops/filter/fftSize>> [3]
>>
>>
https://github.com/imagej/imagej-ops/tree/imagej-ops-0.16.0/src/main/java/net/imagej/ops/filter/ifft>> [4]
>>
>>
https://github.com/imagej/imagej-ops/blob/imagej-ops-0.16.0/src/main/java/net/imagej/ops/filter/FilterNamespace.java#L569-L702>> [5]
>>
>>
https://github.com/imagej/imagej-ops/blob/imagej-ops-0.16.0/src/main/java/net/imagej/ops/filter/FilterNamespace.java#L879-L910>> [6]
https://github.com/imglib/imglib2-algorithm-fft>> [7]
https://github.com/imglib/imglib2-algorithm-fft/pull/3>> [8]
https://github.com/imglib/imglib2/issues/61>> [9]
https://github.com/imglib/imglib2/issues/38>>
>>
>> On Fri, Aug 7, 2015 at 9:05 AM, Rosenberg, Mark F <
>>
[hidden email]> wrote:
>>
>>> Dear Dimiter
>>> Thank you for your feedback and suggestions too.
>>> Best Regards,
>>> Mark
>>>> On 7 Aug 2015, at 11:12, Dimiter Prodanov <
[hidden email]> wrote:
>>>>
>>>> Dear all,
>>>>
>>>> Handing of FFTs (and complex numbers) is a definite weakness of ImageJ.
>>>> Actually ImageJ implements only the Discrete Hartley transform in order
>>> to
>>>> avoid as much as possible use of complex numbers.
>>>> May be this was a reasonable design choice 15 years ago when ImageJ was
>>>> hardly more than an applet displaying an image but now I think it will
>>> make
>>>> much sense to reconsider this.
>>>>
>>>> To put it simply without canonical state of the art FFT/IFFT routine
>>>> ImageJ is not suitable for serious work in linear filtering/signal
>>>> processing.
>>>>
>>>> It will be nice to expose FFTs using for example JTransforms library
>>>>
https://sites.google.com/site/piotrwendykier/software/jtransforms>>>>
>>>> I think that the licenses are compatible.
>>>>
>>>> best regards,
>>>>
>>>> Dimiter Prodanov
>>>>
>>>> --
>>>> ImageJ mailing list:
http://imagej.nih.gov/ij/list.html>>>
>>> --
>>> ImageJ mailing list:
http://imagej.nih.gov/ij/list.html>>>
>>
>> --
>> ImageJ mailing list:
http://imagej.nih.gov/ij/list.html>>
>
> --
> ImageJ mailing list:
http://imagej.nih.gov/ij/list.html