Steve on Image Processing

April 17th, 2009

Multithreaded FFT functions in MATLAB R2009a

For the past several releases, we have been incrementally making more of the computational routines in MATLAB multithreaded. (More recently, we've also started doing this in the Image Processing Toolbox.)

For the R2009a release, readers of this blog might be particularly interested in the improvements made to the FFT functions (fft, ifft, fft2, ifft2, fftn, and ifftn).

Multithreading for the FFT functions works for two- and higher-dimensional cases, and it works for one-dimensional FFTs when multiple columns are being transformed at the same time.

In this example I time a 2048-by-2048 two-dimensional FFT using a two-core 32-bit Windows laptop. (You can get the timeit function from the MATLAB Central File Exchange.)

x = rand(2048, 2048);
timeit(@() fft2(x))
ans =

    0.5443

The computation runs almost twice as fast (on my two-core machine) as it does when using the R2008b release.


Get the MATLAB code

Published with MATLAB® 7.8

6 Responses to “Multithreaded FFT functions in MATLAB R2009a”

  1. Jason Merrill replied on :

    This is great news. Thanks for your work.

    Is the parallelism limited to only two cores at this point? I was excited by the 2x speedup for a 1024×1024 fft2 on my dual core laptop, but a little surprised that the speedup was still only 2x on our 8 core machine.

  2. Steve replied on :

    Jason—No, the FFT implementation is not limited to two cores. However, other factors in the computation can limit the speedup achieved. For example, cache misses when computing the one-dimensional FFT along the non-unit-stride dimension can dominate overall execution time.

  3. erik replied on :

    hi steve-
    are you considering using CUDA? i believe the speedup would be substantial. i would like to make a pixel shader to do n-d filtering on the GPU. i need 3-dimensional (inseparable, circular) filtering in real time for psychophysical/neurophysiology experiments, using psychtoolbox, which provides an interface btw matlab and the GPU, including shaders. there is a 2-d filtering example provided, and i’m trying generalize it by translating the implementation in imfilter_mex.h/ndim_filter() (or \toolbox\matlab\datafun\convnc.cpp\convolve()) for use as a shader.

    the rough size of my problem is to show ~ 50×50 movie at 100hz, filtered by a ~ 35×35x12 kernel (tho even bigger would be even better). using imfilter this takes ~8x real time on a 2.6GHz core2 duo, and i didn’t see any speedup from upgrading to 2009a, i think because fft is not used by either imfilter or convn.

    i’m finding all the index bookkeeping to be a headache. i was wondering if this would be an easy problem for you to demo, and a great excuse for exploring if using the GPU in matlab (esp. image/signal processing) could be an important market opportunity for mathworks (as has been demonstrated by folding@home, which saw a speed up of several orders of magnitude, for example). a less preferable alternative would be to use the FPU — neither example seems to make use of vectorized SIMD calls that have long been available — why is that?

  4. Steve replied on :

    Erik—We are always looking at technology options, but I can’t be specific about our plans.

    You are correct that imfilter and convn do not use frequency-domain-based implementations.

    imfilter does use the Intel IPP library for some inputs, and IPP exploits the extended instruction sets you mentioned. IPP does not support 3-D filtering, however.

  5. khairiah replied on :

    Hi Steve,

    Based on documentation,fft supports inputs of data types double and single .Is fft also support data type sign and unsigned integer for 8bit and 16bit image?
    I have problems,where i need to input 16bit unsigned data into fft function,so that I can get the same unsigned 16 bit output.

  6. Steve replied on :

    Khairiah—The MATLAB FFT functions work in floating point. You can convert your 16-bit unsigned integer data to floating point (single or double), compute the FFT, and then convert back.

Leave a Reply

Wrap code fragments inside <pre> tags, like this:

<pre class="code">
a = magic(3);
sum(a)
</pre>

If you have a "<" character in your code, either follow it with a space or replace it with "&lt;" (including the semicolon).


Steve Eddins manages the Image & Geospatial development team at The MathWorks and coauthored Digital Image Processing Using MATLAB. He writes here about image processing concepts, algorithm implementations, and MATLAB.

  • Frida: I totally agree. I want to find a global average threshold from a large number of images so my initial...
  • Steve: Dansheng—The following code will give you the binary image corresponding to a single object. L =...
  • Dansheng Song: Hi Steve, Your posts are very helpful for Matlab users. Do you know how can I get the binary image by...
  • DP: Thanks Steve. it did work. now can easily calculate DSC.
  • Steve: DP— A & B
  • DP: Hi Steve, Dice similarity coefficient is defined to find the overlapped regions between two objects in an image....
  • Steve: Searching— axis on
  • Steve: DP—Sorry, but I’ve never heard of dice similarity coefficients.
  • searching: Hey, I found this place extremely useful. I have a question though. Although I manage to plot my points on...
  • DP: Hi Steve, thanks for your email. i could not seperate those connected objects. Instead i am trying to compare...

These postings are the author's and don't necessarily represent the opinions of The MathWorks.