[Insight-users] Seg. fault with ReleaseDataFlag and JoinImageFilter

Benjamin King king.benjamin at mh-hannover.de
Mon, 02 Feb 2004 09:15:15 +0100


Hi Luis,

Thanks for your help. I have another question related to memory 
consumption. As I understand, the StreamingImageFilter would be a good 
tool to limit peak memory usage. But when I tried to use it in a project, 
I found that some of the upstream filters didn't support it. Sorry for 
being so unspecific, but I don't quite remember where I used it. Is there 
a simple way to see which filters support streaming? Or do I have to 
search the repository for filters that override 
EnlargeOutputRequestedRegion()?

cheers,
   Benjamin

>
> Hi Benjamin,
>
> This looks like a bug...
>
> It has been entered as Bug# 560
> http://www.itk.org/Bug/bug.php?op=show&bugid=560&pos=0
>
> -----
>
> The worst thing that should happen by using
> the ReleaseDataFlagOn() in a particular order
> is that the reader would be forced to reallocate
> an output image and to read the data from the
> file again.
>
>
> Independently of the fact that it is crashing,
> you probably don't get any advantage in invoking
> the Release data flag in this configuration of
> the pipeline.
>
>
> If you have strong memory concerns, a better way to
> go may be to progressively destroy the filters that
> are no longer needed.  A simple way to do this is to
> use "{"  "}" and let the compiler destroy the filters
> when they go out of scope.
>
>
>
> Regards,
>
>
>     Luis
>
>
>
> -----------------------
> Benjamin King wrote:
>
>> Hello,
>>
>> the attached code implements the following pipeline:
>>
>> reader-->gradient magnitude-->JoinImageFilter
>> |                                   ^
>> |                                   |
>> |-----------------------------------|
>>
>> When I use reader->ReleaseDataFlagOn(), the program produces a 
>> segmentation fault on joiner->Update() _unless_ preceeded by a 
>> gradient->Update(). Please see the comments in the code. I use a fairly 
>> recent ITK checkout and Linux.
>>
>> My questions are:
>>
>> 1) Why does this happen? Maybe during Update(), the gradient magnitude 
>> filter makes the erroneous assumption that the reader's output is still 
>> valid...
>>
>> 2) Is there a better way to reduce the memory footprint than using 
>> ReleaseDataFlagOn()?
>>
>>
>> Thanks for the help,
>>   Benjamin
>>
>>
>> #include <iostream>
>> #include <stdexcept>
>> #include "itkImage.h"
>> #include "itkImageFileReader.h"
>> #include "itkGradientMagnitudeImageFilter.h"
>> #include "itkJoinImageFilter.h"
>>
>> using std::exception;
>>
>> int main(int argc, char *argv[])
>> {
>>   if (argc != 2)
>>   {
>>     std::cout <<
>>       "Makes a two component image of scalar value vs. gradient 
>> magnitude\n"
>>       "\n"
>>       "USAGE: " << argv[0] << " <volume>\n"
>>       "  <volume>: ITK volume file, e.g. Analyze. Example: foo.hdr\n"
>>       << std::endl;
>>     return 1;
>>   }
>>
>>   typedef itk::Image<unsigned short, 3> InputImageType;
>>   typedef itk::Image<float, 3> DerivativeImageType;
>>
>>   typedef itk::ImageFileReader<InputImageType> ImageReaderType;
>>   ImageReaderType::Pointer reader = ImageReaderType::New();
>>   reader->SetFileName(argv[1]);
>>   reader->ReleaseDataFlagOn(); // Either insert comment to prevent 
>> seg.  fault...
>>
>>   typedef itk::GradientMagnitudeImageFilter<InputImageType, 
>> DerivativeImageType> GradientFilterType;
>>   GradientFilterType::Pointer gradient = GradientFilterType::New();
>>   gradient->ReleaseDataFlagOn();
>>   gradient->SetInput(reader->GetOutput());
>>
>>   typedef itk::JoinImageFilter<InputImageType, DerivativeImageType> 
>> JoinFilterType;
>>   JoinFilterType::Pointer combined = JoinFilterType::New();
>>   combined->SetInput1(reader->GetOutput());
>>   combined->SetInput2(gradient->GetOutput());
>>
>>   try
>>   {
>>     // gradient->Update();  // ...or remove this comment to prevent 
>> seg. fault
>>     combined->Update();
>>   }
>>   catch (itk::ExceptionObject & e)
>>   {
>>     std::cerr << "ITK exception: " << e << std::endl;
>>   }
>>   catch (std::exception & e)
>>   {
>>     std::cerr << "std exception: " << e.what() << std::endl;
>>   }
>>
>>   return 0;
>> }
>>
>
>
>
> _______________________________________________
> Insight-users mailing list
> Insight-users at itk.org
> http://www.itk.org/mailman/listinfo/insight-users



-- 
Benjamin King
Institut für Medizinische Informatik
Medizinische Hochschule Hannover
Tel.: +49  511  532-2663