Filter output as input for the same filter

filter
processing

(Gordian) #1

Hello,

just a question of good practice:

It is okay to use the output of a filter as input for the same filter instance?

(non-functional) Example:

auto AddFilter = itk::AddImageFilter::New();
AddFilter->SetInput1(ImageX);

for (auto i = 0; i < somenumber; ++i)
{
  AddFilter->SetInput2(OtherImageSource(i))
  AddFilter->Update();

  if(i<somenumber-1)
   AddFilter->SetInput1(AddFilter->GetOutput());
}
auto Result = AddFilter->GetOutput();

I have implemented this and it works. Is this good practice or should i create somenumber of AddImageFilter and concatenate the Outputs and Inputs (getting rid of the for-loop for processing)?

with best regards,
Gordian


(Francois Budin) #2

When you have a circular pipeline, you want to make sure that you disconnect the result. In general, if you don’t disconnect it, you will run into problems. In your case, you want to call Add->Filter->DisconnectPipeline(); [1][2] after calling Update().

[1] How to _really_ disconnect pipeline?
[2] https://itk.org/pipermail/insight-users/2002-October/001368.html