Thanks for your replies.<br><br>Neil, I splitted the image and repeated the process (see the code at the end of my e-mail). The strange thing I totally don't understand is why the processing is working when I run just this processing in a separate programm and not when I include the processing as a "function" in my acutal program.In the separate program it is just working when I split the image in 4 parts.<br>
<br>Gerald, I used now for every filter: filter->SetReleaseDataFlag(true);<br>There was no difference... unfortunately :-(<br><br><br><div class="gmail_quote">2011/4/13 Lodron, Gerald <span dir="ltr"><<a href="mailto:Gerald.Lodron@joanneum.at">Gerald.Lodron@joanneum.at</a>></span><br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div>
<div dir="ltr" align="left"><span><font color="#0000ff" face="Verdana" size="2">itk uses pipelining which means that there is one image in
memory after each filtering. So when you have</font></span></div>
<div dir="ltr" align="left"><span><font color="#0000ff" face="Verdana" size="2"></font></span> </div>
<div dir="ltr" align="left"><span><font color="#0000ff" face="Verdana" size="2">->image->filter1->filter2->filter3</font></span></div>
<div dir="ltr" align="left"><span><font color="#0000ff" face="Verdana" size="2"></font></span> </div>
<div dir="ltr" align="left"><span><font color="#0000ff" face="Verdana" size="2">you get the memory of the image 4 times. If you want to
release the memory after each filter step you can use the release data flag of
each filter (SetReleaseDataFlagOn). Then you hage the memory only one
time</font></span></div>
<div dir="ltr" align="left"><span><font color="#0000ff" face="Verdana" size="2"></font></span> </div>
<div dir="ltr" align="left"><span><font color="#0000ff" face="Verdana" size="2">If you have an image of 300x300x512x3 with float (4 byte)
you have 527 MB memory per image, windows 32 theoretically only allows
propgramms 2GB (in my tests this theoretically is 1.2 GB in practice) so you
only can have the image stored into two vairables, in the third time the
allocation will fail!</font></span></div>
<div dir="ltr" align="left"><span><font color="#0000ff" face="Verdana" size="2"></font></span> </div>
<div dir="ltr" align="left"><span><font color="#0000ff" face="Verdana" size="2">Another solution is to use the RequestedRegion instead of
largestpossibleregion but this is not supported for all filters. here only a
part of an image is loaded and processed...I have no experience with
this</font></span></div>
<div dir="ltr" align="left"><span><font color="#0000ff" face="Verdana" size="2"></font></span> </div>
<div dir="ltr" align="left"><span></span><span><font color="#0000ff" face="Verdana" size="2">best
regards</font></span></div><br>
<div dir="ltr" align="left" lang="de">
<hr>
<font face="Tahoma" size="2"><b>Von:</b> <a href="mailto:insight-users-bounces@itk.org" target="_blank">insight-users-bounces@itk.org</a>
[mailto:<a href="mailto:insight-users-bounces@itk.org" target="_blank">insight-users-bounces@itk.org</a>] <b>Im Auftrag von </b>Melanie
Uks<br><b>Gesendet:</b> Mittwoch, 13. April 2011 15:34<br><b>An:</b>
<a href="mailto:insight-users@itk.org" target="_blank">insight-users@itk.org</a><br><b>Betreff:</b> Re: [Insight-users] Memory
problem<br></font><br></div><div><div></div><div class="h5">
<div></div>Sorry, I don't have that much expertice: what does "individual
chunks" mean and how to implement?<br><br>
<div class="gmail_quote">2011/4/13 Neil Panjwani <span dir="ltr"><<a href="mailto:paniwani@gmail.com" target="_blank">paniwani@gmail.com</a>></span><br>
<blockquote style="border-left:#ccc 1px solid;margin:0px 0px 0px 0.8ex;padding-left:1ex" class="gmail_quote">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'd have to apply your algorithm on individual
chunks at a time and combine them at the end.
<div>
<div></div>
<div><br><br>
<div class="gmail_quote">On Wed, Apr 13, 2011 at 9:22 AM, Melanie Uks <span dir="ltr"><<a href="mailto:meluks2010@googlemail.com" target="_blank">meluks2010@googlemail.com</a>></span> wrote:<br>
<blockquote style="border-left:#ccc 1px solid;margin:0px 0px 0px 0.8ex;padding-left:1ex" class="gmail_quote">I am running 32 bit.
<div>
<div></div>
<div><br><br>
<div class="gmail_quote">2011/4/13 Neil Panjwani <span dir="ltr"><<a href="mailto:paniwani@gmail.com" target="_blank">paniwani@gmail.com</a>></span><br>
<blockquote style="border-left:#ccc 1px solid;margin:0px 0px 0px 0.8ex;padding-left:1ex" class="gmail_quote">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"><<a href="mailto:meluks2010@googlemail.com" target="_blank">meluks2010@googlemail.com</a>></span>
wrote:<br></div></div>
<blockquote style="border-left:#ccc 1px solid;margin:0px 0px 0px 0.8ex;padding-left:1ex" class="gmail_quote">
<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'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'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: "class
itk::CovariantVector<float,3> *__thiscall
itk::ImportImageConta<br>iner<unsigned long,class
itk::CovariantVector<float,3> >::AllocateElements(unsig<br>ned
long) const"<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 "conio.h"<br><br>#include
"itkImageFileWriter.h"<br>#include "itkImageFileReader.h"<br>#include
"itkRegionOfInterestImageFilter.h"<br>#include
"itkGradientRecursiveGaussianImageFilter.h"<br>#include
"itkGradientToMagnitudeImageFilter.h"<br>#include
"itkPasteImageFilter.h"<br>#include "itkImage.h"<br><br>int main(int
argc, char* argv[])<br>{ <br> // Verify number of
parameters in command line<br> // if( argc < 3
)<br> // {<br> // std::cerr <<
"Usage: " << std::endl;<br> // std::cerr
<< argv[0] << " inputImageFile outputVectorImageFile "
<< 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< PixelType, Dimension >
ImageType;<br> typedef itk::CovariantVector< ComponentType,
<br>
Dimension
> OutputPixelType;<br> typedef
itk::Image< OutputPixelType, Dimension >
OutputImageType;<br><br><br> ImageType::Pointer image =
ImageType::New();<br><br> ImageType::IndexType start;<br>
for(int i = 0; i < 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->SetRegions(region);<br>
image->SetSpacing(spacing);<br>
image->Allocate();<br><br> std::cout << region <<
std::endl;<br><br> OutputImageType::Pointer vec_image =
OutputImageType::New();<br> OutputImageType::RegionType
vecregion;<br> <br> OutputImageType::SizeType
vecsize; //Size<br>
vecsize[0] =
(image->GetLargestPossibleRegion().GetSize())[0];<br>
vecsize[1] =
(image->GetLargestPossibleRegion().GetSize())[1];<br>
vecsize[2] =
(image->GetLargestPossibleRegion().GetSize())[2];<br>
std::cout<<"size0: "<< vecsize[0]<< " size1: "<<
vecsize[1] << " size2: " << vecsize[2]
<<std::endl;<br> vecregion.SetSize( vecsize );<br><br>
OutputImageType::IndexType vecstart;
//Start<br> vecstart[0] =
(image->GetOrigin())[0];<br> vecstart[1] =
(image->GetOrigin())[1];<br> vecstart[2] =
(image->GetOrigin())[2];<br> std::cout<<" start0:
"<< vecstart[0]<< " start1: "<< vecstart[1] << "
start2: " << vecstart[2] <<std::endl;<br>
vecregion.SetIndex( vecstart );<br> <br>
vec_image->SetRegions(vecregion);<br>
vec_image->SetSpacing(image->GetSpacing());<br>
vec_image->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->FillBuffer(
initialValue );<br> std::cout<< "Allocate" <<
std::endl;<br><br> typedef itk::RegionOfInterestImageFilter<
ImageType, ImageType > 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 < splitcnt_x;
cnt_x++)<br> {<br> for (int cnt_y = 0; cnt_y
< 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]
> 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]
> 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 << "cnt_x: " << cnt_x <<
" cnt_y: " << cnt_y << std::endl;<br><br>
std::cout << roiregion <<
std::endl;<br><br> std::cout
<< "ROI region inside image region is " <<
region.IsInside(roiregion) << std::endl;<br><br>
roifilter->SetRegionOfInterest(roiregion);<br>
roifilter->SetInput(image);<br><br>
//Filter class is instantiated<br>
typedef
itk::GradientRecursiveGaussianImageFilter<ImageType,
OutputImageType> GradFilterType;<br><br>
GradFilterType::Pointer gradfilter =
GradFilterType::New();<br>
<br> //sigma is specified in
millimeters<br>
gradfilter->SetSigma( 1.5 ); <br>
<br> //
processing pipeline:<br>
gradfilter->SetInput(roifilter->GetOutput());<br>
<br><br> typedef
itk::PasteImageFilter <OutputImageType, OutputImageType >
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->SetSourceImage(gradfilter->GetOutput());<br>
pasteFilter->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->SetSourceRegion(pasteregion);<br>
pasteFilter->SetDestinationIndex(destinationIndex);<br><br>
try<br>
{<br>
pasteFilter->Update();<br>
}<br> catch( itk::ExceptionObject
& err )<br>
{<br> std::cerr
<< "ExceptionObject caught !" <<
std::endl;<br>
std::cerr << err << std::endl;<br>
return
EXIT_SUCCESS;<br>
}<br> }<br> typedef
itk::GradientToMagnitudeImageFilter< OutputImageType, ImageType >
MagFilterType;<br> MagFilterType::Pointer magfilter =
MagFilterType::New();<br><br>
magfilter->SetInput(vec_image);<br><br>
try<br> {<br>
magfilter->Update();<br> image =
magfilter->GetOutput();<br> }<br>
catch( itk::ExceptionObject & err )<br>
{<br> std::cerr <<
"ExceptionObject caught !" << std::endl;<br>
std::cerr << err <<
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></div></div></blockquote>
</div><br></div></div></div>
</blockquote></div><br>