[Insight-developers] Confused about persistance of filter outputs
Hans Johnson
hans-johnson@uiowa.edu
Mon, 28 Apr 2003 09:14:07 -0500
Luis,
Thanks for your response. After further review, I noticed that I forgot
to call myGrad->Update().
I have been looking at the software guide, and believe that there are
two things missing.
1) An in-depth discussion of how the pipeline works.
-) what does GetOutput() return,
-) why you don't have to call filter->Update when chaining many
filters together
-) When memory is allocated, and when is it released (this is
already described, and may not need any more)
2) A common pitfalls appendix with examples
-) All of the images in MyNewImagesList will have a smart pointer
to the same image.
std::list<itk::Image<>> MyImagesList;
std::list<itk::Image<>> MyNewImagesList;
itk::FilterX X=itk::FilterX::New()
for( currImage in MyImagesList )
{
X.SetInput(currImage);
X.Update();
MyNewImagesList.push_back(X.GetOutput);
}
-) This will cause errors because MyNewImage was never allocated.
itk::Image<> MyImage;
itk::Image<> MyNewImage;
{
itk::FilterX X=itk::FilterX::New()
X.SetInput(MyImage);
//NOTE: No UpdateCommand
MyNewImage=X.GetOutput();
}
itk::FilterY Y=itk::FilterY::New();
Y.SetInput(MyNewImage);
Y.Update();
Both of these issues are closely related to not fully understanding the
pipeline, and making improper assumptions about it's behavior.
Again, Thanks for all your help.
Hans
Luis Ibanez wrote:
>
> Hi Hans,
>
> Your code looks good.
>
> By creating the STL list of SmartPointer to images
> before the for() loop, you should be safely assuring
> the survival of the images.
>
> The destruction of the gradient filters will only
> decrement the reference count of the output images.
>
>
> Luis
>
>
> ----------------------------
>
> Hans J. Johnson wrote:
>
>> Filter and Pipeline experts:
>>
>> I am trying to create a list of gradient images from a list of images.
>> Does the following code produce a list of SmartPointers to gradient
>> images that persist outside the for loop, or are all the SmartPointers
>> invalid outside the for loop?
>>
>>
>> std::list<GradImageType::Pointer > ImageCache;
>> ...read in images...
>>
>> std::list<GradImageType::Pointer > GradientsCache;
>> for (std::list<itk::Image<unsigned char,3>::Pointer >::const_iterator it
>> = ImageCache.begin();
>> it != ImageCache.end(); it++)
>> {
>> typedef itk::GradientImageFilter<itk::Image<unsigned char,3> >
>> myGradType;
>> myGradType::Pointer myGrad=myGradType::New();
>> myGrad->SetInput(*it);
>> GradientsCache.push_back(myGrad->GetOutput());
>> }
>>
>> Thanks,
>> Hans
>>
>>
>
>
>
> _______________________________________________
> Insight-developers mailing list
> Insight-developers@public.kitware.com
> http://public.kitware.com/mailman/listinfo/insight-developers
--
===================================================================
Hans J. Johnson W294 GH
hans-johnson@uiowa.edu Dept. of Psychiatry
http://www.psychiatry.uiowa.edu/~hjohnson The University of Iowa
(319) 353-8587 Iowa City, IA 52242
===================================================================