Page 1 of 1

Imagemagick FFT routines

Posted: 2008-05-07T18:03:11-07:00
by seanburke1979
Friends,
Fred and I have been hard at work on a set of FFT routines for Imagemagick wrapped around FFTW (http://www.fftw.org). We are still ironing out one major incompatibility, but everything else looks to be going well.

Here is what works:
- Magnitude and phase pairs, or optionally real and imaginary pairs can be produced and reassembled correctly.
- Round-trip (IFT(FT(image))) images now have zero difference between the originals when the transform is performed with HDRI.

Here is what does not work:
- We cannot swap an IMFFT mag/phase pair (or real/imag) with one from Photoshop or image/j. Right now, it looks like this is being caused by the transforms employed in converting the FFTW output and what we consider to be an "ideal image." I am going to try to figure this out sometime in the remaining week.

Here is what still needs to be done:
- We need to be able to demonstrate a successful (non trivial) deblurring operation. Fred is working on this right now and I hope to hear from him as soon as I have figured out the transform issue.
- The documentation is woefully out of date. Once the smoke clears on the development, I hope to give some real time to documenting the usage of the functions.

As a reminder, this is still beta code. It is fairly hardy, but has not yet been polished by the core developers. If you would like to get a feel for the routines, I have written a companion program called demo - it is a bit messy, but demonstrates the correct calling sequences for FourierImage(), FourierImages(), InvFourierImage() and InvFourierImages().

To get a magnitude/phase pair of images, use:
./demo f my_input.jpg fft.miff
(Be sure to use miff or one of the other HDRI file types)
This will produce a pair of images fft-0.miff and fft-1.miff corresponding to the magnitude and phase of each image.
The inverse is given with:
./demo i fft-0.miff fft-1.miff my_outfile.tiff

For real and imaginary pairs, substitute "f" and "i" with "g" and "j" respectively.

ftp://depot.aecom.yu.edu/pub/vzXLSQerK7 ... 0/Makefile
ftp://depot.aecom.yu.edu/pub/vzXLSQerK7wd2FMmv230/fft.c
ftp://depot.aecom.yu.edu/pub/vzXLSQerK7wd2FMmv230/fft.h
ftp://depot.aecom.yu.edu/pub/vzXLSQerK7 ... 230/demo.c

You can build everything with the attached Makefile.

Best,

Sean

Re: Imagemagick FFT routines

Posted: 2008-05-07T20:22:36-07:00
by fmw42
Just to add a bit from my perspective on Sean's comments.

We have successfully demonstrated that we can do FFT/IFT in a Q8, Q16, Q32 environment using magnitude and phase images from the FFT without HDRI, although a round trip FFT then IFT with no other processing has some small rmse error when comparing using compare -metric rmse originalimage roundtripimage null:. The errors go to zero if one employs HDRI.

I have an example page at http://www.fmwconcepts.com/misc_tests/F ... index.html that shows many of the abilities of processing in the frequency domain for filtering noise, dither patterns, high and low pass filtering. These all work fine in a non-HDRI environment using magnitude and phase images from the FFT. The syntax has changed however as Sean's IMFFT routines now output magnitude/phase or real/imaginary components in separate 3-channel images (for color image input) rather than the tiff stack of 6 frames. I have not yet fixed the examples. Also the format of the FFT images from their "half-format" to a full square image has changed some. Thus the spectrum and masks will have a different symmetry.

Today, I successfully demonstrated that I could do normalized cross correlation (on grayscale imagery) to do pattern matching. That is to find where a smaller (subsection) image best matches within a larger image. This however, requires the use of real/imaginary components and HDRI.

Where I am still not getting successful results is in two places:

First, in an HDRI environment, I should be able to do an FFT on an image to real/imaginary, then use IM and -fx to convert from real/imaginary to magnitude/phase and then do an IFT using the magnitude/phase to get a round trip FFT/IFT back to the original image. So far the result is not even close to the original. The issue here has been traced to a problem with MIFF format image in HDRI. This is being worked on by the IM staff.

Second, I should be able to motion-blur a special test image by creating a motion-blur filter image (a straight white line in a black background), FFT the test image and the filter image, multiply them using -fx and then IFT the result. So far my results, even using HDRI, are not matching a properly motion-blurred image either using similar FFT techniques in other applications or doing the motion-blur in the spatial domain via a simple convolution. This has been solved, now.