Code covered by the BSD License  

Highlights from
3D convolution in the FFT domain

4.66667

4.7 | 3 ratings Rate this file 35 Downloads (last 30 days) File Size: 1.87 KB File ID: #35613
image thumbnail

3D convolution in the FFT domain

by

 

13 Mar 2012 (Updated )

Achieve a 3D convolution in the fourrier domain.

| Watch this File

File Information
Description

%% 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 http://www.mathworks.com/matlabcentral/fileexchange/24504 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).

MATLAB release MATLAB 7.13 (R2011b)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (7)
02 May 2014 Ran

How can I do a 'valid' convolution?

28 Aug 2012 D D

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

27 Aug 2012 D D

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

21 Apr 2012 Edwin

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
extr(1:3)={};

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?

21 Apr 2012 Edwin  
14 Mar 2012 Christopher Coello

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.

13 Mar 2012 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 http://www.mathworks.com/matlabcentral/fileexchange/24504 ?
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.

Updates
13 Mar 2012

Screenshot uploaded

16 Mar 2012

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

19 Mar 2012

- Fix initialization bug

Contact us