[Insight-users] If you use mini-pipeline/GraftOutput in an itk ImageToImageFilter, do you need to allocate the output?

Gaëtan Lehmann gaetan.lehmann at jouy.inra.fr
Fri Jul 24 16:54:27 EDT 2009


Le 24 juil. 09 à 20:55, kent williams a écrit :

> I'm writing an filter derived from itk::ImageToImageFilter.  It's
> adapted from a function already written.  In other words I'm going
> from
>
> itk::Image::Pointer DoesSomething(...) { // do something and return a
> pointer to an image }
>
> to a filter which has the code from DoesSomething pulled into the
> filter's GenerateData method.
>
> The way I implemented this was pretty simple:
>
> template <class TInputImage, class TOutputImage>
> void
> MyFilter<TInputImage,TOutputImage>
> ::GenerateData()
> {
>   this->AllocateOutputs()
>   // code from original function
>   this->GraftOutput(lastFilter->GetOutput();
> }
>
> My question is this, since I'm using GraftOutput to use the output of
> the last filter in my mini-pipeline, do I even need to call
> AllocateOutputs?


It's a bit more complex. You have to make the last filter of your code  
use the right data, by using GraftOutput() on the output image, update  
your pipeline, and then use GraftOutput() to put the result back in  
the output image. There are several example in ITK. This one is from  
WhiteTophatImageFilter:

   // graft our output to the subtract filter to force the proper  
regions
   // to be generated
   subtract->GraftOutput( this->GetOutput() );

   // run the algorithm
   progress->RegisterInternalFilter(open,.9f);
   progress->RegisterInternalFilter(subtract,.1f);

   subtract->Update();

   // graft the output of the subtract filter back onto this filter's
   // output. this is needed to get the appropriate regions passed
   // back.
   this->GraftOutput( subtract->GetOutput() );

So yes, you have to allocate the output, to be able to run the first  
GraftOutput().

Gaëtan


-- 
Gaëtan Lehmann
Biologie du Développement et de la Reproduction
INRA de Jouy-en-Josas (France)
tel: +33 1 34 65 29 66    fax: 01 34 65 29 09
http://voxel.jouy.inra.fr  http://www.itk.org
http://www.mandriva.org  http://www.bepo.fr

-------------- next part --------------
A non-text attachment was scrubbed...
Name: PGP.sig
Type: application/pgp-signature
Size: 203 bytes
Desc: Ceci est une signature ?lectronique PGP
URL: <http://www.itk.org/pipermail/insight-users/attachments/20090724/3876a5d4/attachment.pgp>


More information about the Insight-users mailing list