<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/242130</link>
    <title>MATLAB Central Newsreader - Out of memory when I am doing 3D FFT</title>
    <description>Feed for thread: Out of memory when I am doing 3D FFT</description>
    <language>en-us</language>
    <copyright>&amp;copy;1994-2012 by MathWorks, Inc.</copyright>
    <webmaster>webmaster@mathworks.com</webmaster>
    <generator>MATLAB Central Newsreader</generator>
    <docs>http://blogs.law.harvard.edu/tech/rss</docs>
    <ttl>60</ttl>
    <image>
      <title>MathWorks</title>
      <url>http://www.mathworks.com/images/membrane_icon.gif</url>
    </image>
    <item>
      <pubDate>Fri, 09 Jan 2009 16:57:02 -0500</pubDate>
      <title>Out of memory when I am doing 3D FFT</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/242130#620707</link>
      <author>David </author>
      <description>Hi, there&lt;br&gt;
&lt;br&gt;
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.&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
function FilterOut=perform_convolution_3d(Vol,vker)&lt;br&gt;
&lt;br&gt;
%% Vol is the input volumetric image data whose size is 341 by 341 by 341, uint16, &lt;br&gt;
%% vker is an isotropic Gaussian vker whose size is 30 by 30 by 30&lt;br&gt;
&lt;br&gt;
SizeV=size(Vol);&lt;br&gt;
&lt;br&gt;
smoothcell=zeros(SizeV);&lt;br&gt;
centerpix=floor(SizeV/2);&lt;br&gt;
centerker=floor(size(vker)/2);&lt;br&gt;
&lt;br&gt;
embed1i=centerpix(1)-centerker(1)+[1:size(vker,1)];&lt;br&gt;
embed2i=centerpix(2)-centerker(2)+[1:size(vker,2)];&lt;br&gt;
embed3i=centerpix(3)-centerker(3)+[1:size(vker,3)];&lt;br&gt;
&lt;br&gt;
smoothcell(embed1i,embed2i,embed3i)=vker;&lt;br&gt;
&lt;br&gt;
FFT1=fftn(double(Vol));&lt;br&gt;
FFT2=fftn(double(smoothcell));&lt;br&gt;
CPXARR2=FFT1.*conj(FFT2);&lt;br&gt;
MFout=fftshift(ifftn(CPXARR2));&lt;br&gt;
&lt;br&gt;
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.&lt;br&gt;
&lt;br&gt;
I use window xp 32 OP system with 2GB RAM.&lt;br&gt;
&lt;br&gt;
Thanks for the help, &lt;br&gt;
David</description>
    </item>
    <item>
      <pubDate>Fri, 09 Jan 2009 19:00:20 -0500</pubDate>
      <title>Re: Out of memory when I am doing 3D FFT</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/242130#620732</link>
      <author>Matt </author>
      <description>&quot;David &quot; &amp;lt;david2008.w@gmail.com&amp;gt; wrote in message &amp;lt;gk7vku$naj$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; Hi, there&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; 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.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; function FilterOut=perform_convolution_3d(Vol,vker)&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; %% Vol is the input volumetric image data whose size is 341 by 341 by 341, uint16, &lt;br&gt;
&amp;gt; %% vker is an isotropic Gaussian vker whose size is 30 by 30 by 30&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; SizeV=size(Vol);&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; smoothcell=zeros(SizeV);&lt;br&gt;
&amp;gt; centerpix=floor(SizeV/2);&lt;br&gt;
&amp;gt; centerker=floor(size(vker)/2);&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; embed1i=centerpix(1)-centerker(1)+[1:size(vker,1)];&lt;br&gt;
&amp;gt; embed2i=centerpix(2)-centerker(2)+[1:size(vker,2)];&lt;br&gt;
&amp;gt; embed3i=centerpix(3)-centerker(3)+[1:size(vker,3)];&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; smoothcell(embed1i,embed2i,embed3i)=vker;&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; FFT1=fftn(double(Vol));&lt;br&gt;
&amp;gt; FFT2=fftn(double(smoothcell));&lt;br&gt;
&amp;gt; CPXARR2=FFT1.*conj(FFT2);&lt;br&gt;
&amp;gt; MFout=fftshift(ifftn(CPXARR2));&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; 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.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; I use window xp 32 OP system with 2GB RAM.&lt;br&gt;
&lt;br&gt;
How big are your arrays? Since they seem to be pretty big, maybe you'd settle for representing this as singles rather than doubles.&lt;br&gt;
&lt;br&gt;
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. &lt;br&gt;
&lt;br&gt;
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.</description>
    </item>
    <item>
      <pubDate>Sat, 10 Jan 2009 06:02:10 -0500</pubDate>
      <title>Re: Out of memory when I am doing 3D FFT</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/242130#620794</link>
      <author>vedenev</author>
      <description>Follow how memory is used on your computer in windows task manager&lt;br&gt;
(ctrl+alt+del). See MATLAB.exe. Add virtual memory colomn. Find info&lt;br&gt;
about 3GB mode in Windows. In 64 bit computer there are much more&lt;br&gt;
virtual memory is avaliable.&lt;br&gt;
&lt;br&gt;
-----------------------------------------&lt;br&gt;
Maxim Vedenev, MATLAB Custom Programming&lt;br&gt;
&lt;a href=&quot;http://simulations.narod.ru/&quot;&gt;http://simulations.narod.ru/&lt;/a&gt;</description>
    </item>
    <item>
      <pubDate>Sat, 10 Jan 2009 08:06:03 -0500</pubDate>
      <title>Re: Out of memory when I am doing 3D FFT</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/242130#620797</link>
      <author>Bruno Luong</author>
      <description>&quot;David &quot; &amp;lt;david2008.w@gmail.com&amp;gt; wrote in message &amp;lt;gk7vku$naj$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; FFT1=fftn(double(Vol));&lt;br&gt;
&amp;gt; FFT2=fftn(double(smoothcell));&lt;br&gt;
&amp;gt; CPXARR2=FFT1.*conj(FFT2);&lt;br&gt;
&amp;gt; MFout=fftshift(ifftn(CPXARR2));&lt;br&gt;
&amp;gt; &lt;br&gt;
&lt;br&gt;
Few tips:&lt;br&gt;
- use SINGLE instead of DOUBLE&lt;br&gt;
- Inplace fft by slice:&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;FFT1=zeros(size(Vol),class(Vol));&lt;br&gt;
&amp;nbsp;&amp;nbsp;for k=1:size(Vol,3)&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;FFT1(:,:,k)=fftn(Vol(:,:,k));&lt;br&gt;
&amp;nbsp;&amp;nbsp;end&lt;br&gt;
&amp;nbsp;&amp;nbsp;for i=1:size(Vol,1)&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;for j=1:size(Vol,2)&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;FFT1(i,j,:)=fft(squeeze(Vol(i,j,:)));&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;end&lt;br&gt;
&amp;nbsp;&amp;nbsp;end&lt;br&gt;
&amp;nbsp;&amp;nbsp;&lt;br&gt;
&amp;nbsp;&amp;nbsp;% Same for FFT2&lt;br&gt;
&lt;br&gt;
- Clear intermediate variables or reuse the same variables at different steps&lt;br&gt;
- As someone has pointed out: because the kernel is tensorial of 1d kernels, Do the convolution in 1D separately.&lt;br&gt;
&lt;br&gt;
Bruno</description>
    </item>
    <item>
      <pubDate>Sat, 10 Jan 2009 10:04:01 -0500</pubDate>
      <title>Re: Out of memory when I am doing 3D FFT</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/242130#620800</link>
      <author>Bruno Luong</author>
      <description>:,:,k)=fftn(Vol(:,:,k));&lt;br&gt;
&amp;gt;   end&lt;br&gt;
&amp;gt;   for i=1:size(Vol,1)&lt;br&gt;
&amp;gt;      for j=1:size(Vol,2)&lt;br&gt;
&amp;gt;         FFT1(i,j,:)=fft(squeeze(Vol(i,j,:)));&lt;br&gt;
&amp;gt;      end&lt;br&gt;
&amp;gt;   end&lt;br&gt;
&lt;br&gt;
The computation statement should be read as&lt;br&gt;
FFT1(i,j,:)=fft(squeeze(FFT1(i,j,:)));&lt;br&gt;
&lt;br&gt;
Bruno</description>
    </item>
    <item>
      <pubDate>Sun, 11 Jan 2009 19:51:01 -0500</pubDate>
      <title>Re: Out of memory when I am doing 3D FFT</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/242130#620899</link>
      <author>David </author>
      <description>Hi, &lt;br&gt;
thanks for help, I belive that perform the 3D convolution by using three separate one dimensional kernel is good choice. As Bruno and Matt suggested, the use of 1D kernel avoid to calculating the FFT of the 3D smooth kernel which reduces the memory cost. </description>
    </item>
  </channel>
</rss>

