I had similar memory allocation problems when running several CT slices in 32 bit. If you can, using 64-bit should solve your memory problems.<div><br></div><div>Otherwise, I think you&#39;d have to apply your algorithm on individual chunks at a time and combine them at the end.<br>

<br><div class="gmail_quote">On Wed, Apr 13, 2011 at 9:22 AM, Melanie Uks <span dir="ltr">&lt;<a href="mailto:meluks2010@googlemail.com">meluks2010@googlemail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">

I am running 32 bit.<div><div></div><div class="h5"><br><br><div class="gmail_quote">2011/4/13 Neil Panjwani <span dir="ltr">&lt;<a href="mailto:paniwani@gmail.com" target="_blank">paniwani@gmail.com</a>&gt;</span><br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">


Are you running in 32 or 64 bit?<br><br><div class="gmail_quote"><div><div></div><div>On Wed, Apr 13, 2011 at 4:47 AM, Melanie Uks <span dir="ltr">&lt;<a href="mailto:meluks2010@googlemail.com" target="_blank">meluks2010@googlemail.com</a>&gt;</span> wrote:<br>




</div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div></div><div>Hi all,<br><br>I tried to filter a 3D image (300x300x512) with the CannyEdgeFilter. I had the problem that I could not allocate the memory for the filtering. Anyway I don&#39;t like the CannyEdgeFilter Implementation as one has to guess which values to take for the thresholding before the gradientmagnitude image exists... Therefore I wanted to write my own edge detection routine.<br>





<br>The steps:<br>I generate a image (size: 300x300x512)<br>I generate a vector image (size: 300x300x512, vector dimension:3)<br>a) I split the image, process the imagepart with GradientRecursiveGaussianImageFilter<br>b) I paste the processed imagepart in the vector image with the PasteImageFilter<br>





I repeat a) and b) until the whole image is processed<br><br>Now the first question: Why can&#39;t I process the complete image. I have to split the image and get a result... This is the error I get:<br><font size="1"><i>itk::ExceptionObject (0151C728)<br>





Location: &quot;class itk::CovariantVector&lt;float,3&gt; *__thiscall itk::ImportImageConta<br>iner&lt;unsigned long,class itk::CovariantVector&lt;float,3&gt; &gt;::AllocateElements(unsig<br>ned long) const&quot;<br>File: h:\itk\insighttoolkit-3.16.0\code\common\itkImportImageContainer.txx<br>





Line: 188<br>Description: Failed to allocate memory for image.</i></font><br><br>Ok, if I accept that I have to split the image, I have a second question: I was able to run my example programm (code at the end of this mail). Then I copied the code into my actual program. It is a programm with several itk functions and Qt GUI. The only difference is that the image is saved as global variable. I was not able to run the processing. I always had the memory error. Why???<br>





<br>Here now the code for the example processing:<br><br>edgetest.cxx<br><br><font size="1">#include &quot;conio.h&quot;<br><br>#include &quot;itkImageFileWriter.h&quot;<br>#include &quot;itkImageFileReader.h&quot;<br>#include &quot;itkRegionOfInterestImageFilter.h&quot;<br>





#include &quot;itkGradientRecursiveGaussianImageFilter.h&quot;<br>#include &quot;itkGradientToMagnitudeImageFilter.h&quot;<br>#include &quot;itkPasteImageFilter.h&quot;<br>#include &quot;itkImage.h&quot;<br><br>int main(int argc, char* argv[])<br>





{  <br>   // Verify number of parameters in command line<br>  // if( argc &lt; 3 )<br>    // {<br>    // std::cerr &lt;&lt; &quot;Usage: &quot; &lt;&lt; std::endl;<br>    // std::cerr &lt;&lt; argv[0] &lt;&lt; &quot; inputImageFile  outputVectorImageFile &quot; &lt;&lt; std::endl;<br>





    // return EXIT_FAILURE;<br>    // }<br>  typedef float   PixelType;<br>  typedef float   ComponentType;<br>  static const unsigned int Dimension = 3;<br>  typedef itk::Image&lt; PixelType, Dimension &gt; ImageType;<br>





  typedef itk::CovariantVector&lt; ComponentType, <br>                                Dimension  &gt;      OutputPixelType;<br>  typedef itk::Image&lt; OutputPixelType, Dimension &gt;    OutputImageType;<br><br><br>  ImageType::Pointer image = ImageType::New();<br>





<br>  ImageType::IndexType start;<br>  for(int i = 0; i &lt; Dimension; i++)<br>    start[i]=0;<br><br>  ImageType::SizeType size;<br>  size[0] = 300;<br>  size[1] = 300;<br>  size[2] = 512;<br>  <br>  ImageType::RegionType region;<br>





  region.SetSize(size);<br>  region.SetIndex(start);<br>  <br>  ImageType::SpacingType spacing;<br>  spacing[0] = 20;<br>  spacing[1] = 20;<br>  spacing[2] = 4.00493;<br>  <br>  image-&gt;SetRegions(region);<br>  image-&gt;SetSpacing(spacing);<br>





  image-&gt;Allocate();<br><br>  std::cout &lt;&lt; region &lt;&lt; std::endl;<br><br>  OutputImageType::Pointer vec_image = OutputImageType::New();<br>  OutputImageType::RegionType vecregion;<br>    <br>  OutputImageType::SizeType vecsize;        //Size<br>





  vecsize[0] = (image-&gt;GetLargestPossibleRegion().GetSize())[0];<br>  vecsize[1] = (image-&gt;GetLargestPossibleRegion().GetSize())[1];<br>  vecsize[2] = (image-&gt;GetLargestPossibleRegion().GetSize())[2];<br>  std::cout&lt;&lt;&quot;size0: &quot;&lt;&lt; vecsize[0]&lt;&lt; &quot; size1: &quot;&lt;&lt; vecsize[1] &lt;&lt; &quot; size2: &quot; &lt;&lt; vecsize[2] &lt;&lt;std::endl;<br>





  vecregion.SetSize( vecsize );<br><br>  OutputImageType::IndexType vecstart;        //Start<br>  vecstart[0] = (image-&gt;GetOrigin())[0];<br>  vecstart[1] = (image-&gt;GetOrigin())[1];<br>  vecstart[2] = (image-&gt;GetOrigin())[2];<br>





  std::cout&lt;&lt;&quot; start0: &quot;&lt;&lt; vecstart[0]&lt;&lt; &quot; start1: &quot;&lt;&lt; vecstart[1] &lt;&lt; &quot; start2: &quot; &lt;&lt; vecstart[2] &lt;&lt;std::endl;<br>  vecregion.SetIndex( vecstart );<br>





  <br>  vec_image-&gt;SetRegions(vecregion);<br>  vec_image-&gt;SetSpacing(image-&gt;GetSpacing());<br>  vec_image-&gt;Allocate();<br><br>    // The image buffer is initialized to a particular value<br>  OutputImageType::PixelType  initialValue;<br>





<br>  // A vector can initialize all its components to the<br>  // same value by using the Fill() method.<br>  initialValue.Fill( 0.0 );<br><br>  // Now the image buffer can be initialized with this<br>  // vector value.<br>





  vec_image-&gt;FillBuffer( initialValue );<br>  std::cout&lt;&lt; &quot;Allocate&quot; &lt;&lt; std::endl;<br><br>  typedef itk::RegionOfInterestImageFilter&lt; ImageType, ImageType &gt; ROIFilterType;<br>  ROIFilterType::Pointer roifilter = ROIFilterType::New();<br>





<br>  // Number of Regions<br>  int splitcnt_x = 2;<br>  int splitcnt_y = 2;<br>  int overlap = 15;<br><br>  int stepcnt_x = (int) (size[0]*1.0/splitcnt_x + 0.5);<br>  int stepcnt_y = (int) (size[1]*1.0/splitcnt_y + 0.5);<br>





<br><br>  ImageType::IndexType roistart;<br>  roistart[2]=0;<br>  ImageType::SizeType roisize;<br>  roisize[2]=512;<br>  ImageType::RegionType roiregion;<br><br><br>  for (int cnt_x = 0; cnt_x &lt; splitcnt_x; cnt_x++)<br>





  {<br>    for (int cnt_y = 0; cnt_y &lt; splitcnt_y; cnt_y++)<br>    {<br>        roistart[0]= cnt_x*stepcnt_x - overlap;<br>        roistart[1]= cnt_y*stepcnt_y - overlap;<br>        if(cnt_x == 0)<br>        {<br>            roistart[0] = 0;<br>





            roisize[0] = stepcnt_x + overlap;<br>        }<br>        else<br>        {<br>            roisize[0] = stepcnt_x + 2*overlap;<br>        }<br>        if(roisize[0]+roistart[0] &gt; size[0])<br>        {<br>            roisize[0] = size[0]-roistart[0];<br>





        }<br>        if(cnt_y == 0)<br>        {<br>            roistart[1] = 0;<br>            roisize[1] = stepcnt_y + overlap;<br>        }<br>        else<br>        {<br>            roisize[1] = stepcnt_y + 2*overlap;<br>





        }<br>        if(roisize[1]+roistart[1] &gt; size[1])<br>        {<br>            roisize[1] = size[1]-roistart[1];<br>        }<br><br>        <br>        roiregion.SetSize(roisize);<br>        roiregion.SetIndex(roistart);<br>





<br>        std::cout &lt;&lt; &quot;cnt_x: &quot; &lt;&lt; cnt_x &lt;&lt; &quot; cnt_y: &quot; &lt;&lt; cnt_y &lt;&lt; std::endl;<br><br>        std::cout &lt;&lt; roiregion &lt;&lt; std::endl;<br><br>        std::cout &lt;&lt; &quot;ROI region inside image region is &quot; &lt;&lt; region.IsInside(roiregion) &lt;&lt; std::endl;<br>





<br>        roifilter-&gt;SetRegionOfInterest(roiregion);<br>        roifilter-&gt;SetInput(image);<br><br>        //Filter class is instantiated<br>        typedef itk::GradientRecursiveGaussianImageFilter&lt;ImageType, OutputImageType&gt; GradFilterType;<br>





<br>        GradFilterType::Pointer gradfilter = GradFilterType::New();<br>        <br>        //sigma is specified in millimeters<br>        gradfilter-&gt;SetSigma( 1.5 );  <br>        <br>        //  processing pipeline:<br>





        gradfilter-&gt;SetInput(roifilter-&gt;GetOutput());<br>     <br><br>        typedef itk::PasteImageFilter &lt;OutputImageType, OutputImageType &gt; PasteImageFilterType;<br>        // The SetDestinationIndex() method prescribes where in the first<br>





        // input to start pasting data from the second input.<br>        // The SetSourceRegion method prescribes the section of the second<br>        // image to paste into the first.<br>     <br>        OutputImageType::IndexType destinationIndex;<br>





        destinationIndex[0] = cnt_x*stepcnt_x;<br>        destinationIndex[1] = cnt_y*stepcnt_y;<br>        destinationIndex[2] = 0;<br>     <br>        PasteImageFilterType::Pointer pasteFilter = PasteImageFilterType::New ();<br>





        pasteFilter-&gt;SetSourceImage(gradfilter-&gt;GetOutput());<br>        pasteFilter-&gt;SetDestinationImage(vec_image);<br>        <br>        OutputImageType::RegionType pasteregion;<br>        OutputImageType::IndexType pastestart;<br>





        pastestart[2]=0;<br>        OutputImageType::SizeType pastesize;<br>        pastesize[2]=512;<br><br>        pastestart[0]= overlap;<br>        pastestart[1]= overlap;<br>        pastesize[0] = stepcnt_x;<br>        pastesize[1] = stepcnt_y;<br>





<br>        if(cnt_x == 0)<br>        {<br>            pastestart[0] = 0;<br>        }<br>        if(cnt_y == 0)<br>        {<br>            pastestart[1] = 0;<br>        }<br><br>        pasteregion.SetIndex(pastestart);<br>





        pasteregion.SetSize(pastesize);<br><br>        pasteFilter-&gt;SetSourceRegion(pasteregion);<br>        pasteFilter-&gt;SetDestinationIndex(destinationIndex);<br><br>        try<br>        {<br>            pasteFilter-&gt;Update();<br>





        }<br>        catch( itk::ExceptionObject &amp; err )<br>        {<br>            std::cerr &lt;&lt; &quot;ExceptionObject caught !&quot; &lt;&lt; std::endl;<br>            std::cerr &lt;&lt; err &lt;&lt; std::endl;<br>





            return EXIT_SUCCESS;<br>        }<br>    }<br>    typedef itk::GradientToMagnitudeImageFilter&lt; OutputImageType, ImageType &gt; MagFilterType;<br>    MagFilterType::Pointer magfilter = MagFilterType::New();<br>





<br>    magfilter-&gt;SetInput(vec_image);<br><br>    try<br>    {<br>        magfilter-&gt;Update();<br>        image = magfilter-&gt;GetOutput();<br>    }<br>    catch( itk::ExceptionObject &amp; err )<br>    {<br>        std::cerr &lt;&lt; &quot;ExceptionObject caught !&quot; &lt;&lt; std::endl;<br>





        std::cerr &lt;&lt; err &lt;&lt; std::endl;<br>        return EXIT_SUCCESS;<br>    }<br><br>  }<br> <br>  getch();<br>  return EXIT_SUCCESS;<br>}</font><br>
<br></div></div>_____________________________________<br>
Powered by <a href="http://www.kitware.com" target="_blank">www.kitware.com</a><br>
<br>
Visit other Kitware open-source projects at<br>
<a href="http://www.kitware.com/opensource/opensource.html" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
<br>
Kitware offers ITK Training Courses, for more information visit:<br>
<a href="http://www.kitware.com/products/protraining.html" target="_blank">http://www.kitware.com/products/protraining.html</a><br>
<br>
Please keep messages on-topic and check the ITK FAQ at:<br>
<a href="http://www.itk.org/Wiki/ITK_FAQ" target="_blank">http://www.itk.org/Wiki/ITK_FAQ</a><br>
<br>
Follow this link to subscribe/unsubscribe:<br>
<a href="http://www.itk.org/mailman/listinfo/insight-users" target="_blank">http://www.itk.org/mailman/listinfo/insight-users</a><br>
<br></blockquote></div><br>
</blockquote></div><br>
</div></div><br>_____________________________________<br>
Powered by <a href="http://www.kitware.com" target="_blank">www.kitware.com</a><br>
<br>
Visit other Kitware open-source projects at<br>
<a href="http://www.kitware.com/opensource/opensource.html" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
<br>
Kitware offers ITK Training Courses, for more information visit:<br>
<a href="http://www.kitware.com/products/protraining.html" target="_blank">http://www.kitware.com/products/protraining.html</a><br>
<br>
Please keep messages on-topic and check the ITK FAQ at:<br>
<a href="http://www.itk.org/Wiki/ITK_FAQ" target="_blank">http://www.itk.org/Wiki/ITK_FAQ</a><br>
<br>
Follow this link to subscribe/unsubscribe:<br>
<a href="http://www.itk.org/mailman/listinfo/insight-users" target="_blank">http://www.itk.org/mailman/listinfo/insight-users</a><br>
<br></blockquote></div><br></div>