File Exchange

image thumbnail

3D convolution in the FFT domain

version 1.4 (1.87 KB) by

Achieve a 3D convolution in the fourrier domain.



View License

%% convolution3D_FFTdomain - Performs a fast 3D convolution between a volume and a kernel using mutliplication in the Fourrier space.
%Syntax: [outVol] = convolutionInFFTdomain(inVol,inKer)
% Inputs:
% inVol - input volume (real / complex)
% inKer - input kernel (real / complex)
% Outputs:
% outVol - output convolved volume (real / complex) - precision of the output format is the same as the input
% volume. The output volume is the central part of the convolution with same size as inVol.
% size(outVol)=size(inVol) ('same' option of convn).

It is a specialized version of to 3D convolution between volume and kernel (small).
Gives faster results for small volumes (<128x128x128, kernel 20x20x20), and of coure much faster than convn (x300).

Comments and Ratings (8)


Ran (view profile)

How can I do a 'valid' convolution?


D D (view profile)

Replacing "extr(1:3)={};" by "extr(1:3)={0};" solved the problem...


D D (view profile)

I have the same problem with Matlabs 2010a.
Please, help :(


Edwin (view profile)

hi, thanks to your code.
but when I run this code,

errors comes out like this:
??? Subscripted assignment dimension mismatch.

Error in ==> convolution3D_FFTdomain at 42

have I done something wrong? I just unzipped the .m file and runs it at that path. I am using R2011a, is it necessary to run on R2011b?


Edwin (view profile)

Hi, Thanks Michael for the comment.
I indeed make the assumption of only real positive output. This is related to my own problematic (PET imaging).
For the max check, it is an obvious error that will be corrected in the next version.

Michael Völker

Hi, I didn't try the code, just checked it.

You do this after the convolution:

> % Check if all the values are superior to zero
> if (max(convinVol(:))>=0),

You do not check if all values are positive, but only if the *max* value is positive. To check all values, try
> if all( convinVol(:) >=0 )

Then you do
> convinVol(convinVol<0)=0;
which I find more complicated and probably slower than just
> convinVol = max( convinVol, [], 0 );

I like your code in principle, as I just looked for n-dimensional convolution stuff myself, but I don't like the assumptions made in your code.

You assume that the output *must* be positive. Why should it? I'd find it more intuitive to force only positive output if the input was all positive, too.
And beyond that, there are complex numbers, too. Many people (like me) work with complex matrices and don't care for 'negative' values, which does not make sense there. So it would further make sense to distinguish between complex and real numbers.

Have you checked ?
It is slower than it could be, just because it does not use fftn but for-loops instead. Just yesterday I fftn'ed it and was very happy with the results.



- Fix initialization bug


- Bug fixed (positivity of output, size)
- Works with complex


Screenshot uploaded

MATLAB Release
MATLAB 7.13 (R2011b)

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video