# Filter output as input for the same filter

**URL:** https://discourse.itk.org/t/filter-output-as-input-for-the-same-filter/1464
**Category:** Algorithms
**Tags:** processing, filter
**Created:** [December 10, 2018, 9:06am UTC](https://discourse.itk.org/t/filter-output-as-input-for-the-same-filter/1464 "2018-12-10T09:06:07Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Gordian](https://discourse.itk.org/user_avatar/discourse.itk.org/gordian/32/335_2.png) [@Gordian](https://discourse.itk.org/u/Gordian)
#### Post date: [December 10, 2018, 9:06am UTC](https://discourse.itk.org/t/filter-output-as-input-for-the-same-filter/1464/1 "2018-12-10T09:06:07Z")

</div>

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

---

<div class="post-metadata">

### Author: ![fbudin](https://discourse.itk.org/user_avatar/discourse.itk.org/fbudin/32/14_2.png) [@fbudin](https://discourse.itk.org/u/fbudin)
#### Post date: [December 10, 2018, 2:41pm UTC](https://discourse.itk.org/t/filter-output-as-input-for-the-same-filter/1464/2 "2018-12-10T14:41:29Z")

</div>

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?](https://discourse.itk.org/t/how-to-really-disconnect-pipeline/551)  
[2] [https://itk.org/pipermail/insight-users/2002-October/001368.html](https://itk.org/pipermail/insight-users/2002-October/001368.html)
