Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Out of memory when I am doing 3D FFT
Date: Fri, 9 Jan 2009 19:00:20 +0000 (UTC)
Organization: Xoran Technologies
Lines: 40
Message-ID: <gk86s4$mvo$1@fred.mathworks.com>
References: <gk7vku$naj$1@fred.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: webapp-05-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1231527620 23544 172.30.248.35 (9 Jan 2009 19:00:20 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Fri, 9 Jan 2009 19:00:20 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1440443
Xref: news.mathworks.com comp.soft-sys.matlab:510685


"David " <david2008.w@gmail.com> wrote in message <gk7vku$naj$1@fred.mathworks.com>...
> Hi, there
> 
> I am working on CT image processing. I need to calculate the Hessian matrix of the volumetric dataset. It can be accomplished by convolution the image with the 2nd order partial derivatives of the Gaussian kernel.  Here is the way I am doing the convolution.
> 
> 
> function FilterOut=perform_convolution_3d(Vol,vker)
> 
> %% Vol is the input volumetric image data whose size is 341 by 341 by 341, uint16, 
> %% vker is an isotropic Gaussian vker whose size is 30 by 30 by 30
> 
> SizeV=size(Vol);
> 
> smoothcell=zeros(SizeV);
> centerpix=floor(SizeV/2);
> centerker=floor(size(vker)/2);
> 
> embed1i=centerpix(1)-centerker(1)+[1:size(vker,1)];
> embed2i=centerpix(2)-centerker(2)+[1:size(vker,2)];
> embed3i=centerpix(3)-centerker(3)+[1:size(vker,3)];
> 
> smoothcell(embed1i,embed2i,embed3i)=vker;
> 
> FFT1=fftn(double(Vol));
> FFT2=fftn(double(smoothcell));
> CPXARR2=FFT1.*conj(FFT2);
> MFout=fftshift(ifftn(CPXARR2));
> 
> But the 'out of memory' problem always occurs when I implement the code.  I tried to save some of the un-used variables to the disk, only leaving the essential ones in the workspace, but the 'out of memory' problem still happens.
> 
> I use window xp 32 OP system with 2GB RAM.

How big are your arrays? Since they seem to be pretty big, maybe you'd settle for representing this as singles rather than doubles.

Other than that, you probably don't need to compute FFT2, or at least not as a 3D array whose size is the same as Vol. 

Since your kernel is Gaussian, it is separable, and so are its derivatives. So, instead, you should be computing 1D kernels and using 1D fft's to do the convolution on each row, column, etc... of Vol.