# Copy output of nested filter to output of outer filter

**URL:** <https://discourse.itk.org/t/copy-output-of-nested-filter-to-output-of-outer-filter/846>\
**Category:** Uncategorized\
**Created:** [April 18, 2018, 12:09pm UTC](https://discourse.itk.org/t/copy-output-of-nested-filter-to-output-of-outer-filter/846 "2018-04-18T12:09:39Z")\
**Posts on this page:** 5\
**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:** [April 18, 2018, 12:09pm UTC](https://discourse.itk.org/t/copy-output-of-nested-filter-to-output-of-outer-filter/846/1 "2018-04-18T12:09:42Z")

</div>

Hello,

i want to copy the output of a nested filter to outer filter. The outer filter has the OutputImagePointer set (w.r. t. region, size, etc.) and I want to replace the output with the result from the nested filter. The images have the same size and PixelType. This looks similar to following code:

inside OuterFilter::GenerateData()  
{  
[…]  
OutputImagePointer output = this-\>GetOutput();

```
[... other filter is running, m_OtherFilter is a member variable, it doesnt need to be in a pipeline]

```

this-\>m\_OtherFilter-\>Update();  
Output = this-\>m\_OtherFilter-\>GetOutput(); // Now Output is the output from OtherFilter-\>GetOutput()  
}

If I call OuterFilter-\>GetOutput() later on it will return the OutputImagePointer that was set before the OuterFilter::GenerateData() call.

How do I get the output from the outer filter to be replaced by the output from the inner filter?  
If more informations needed please ask. Thank you in advance.

Sincerly,  
Gordian

Edit: Moved topic to Uncategorized because no explicit Algorithm is discussed.

---

<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:** [April 19, 2018, 12:08pm UTC](https://discourse.itk.org/t/copy-output-of-nested-filter-to-output-of-outer-filter/846/2 "2018-04-19T12:08:43Z")

</div>

Found a possible way to resolve this.  
If you set the output in the superclass then it will work:

{  
[…]  
Output = this-\>m\_OtherFilter-\>GetOutput(); // Now Output is the output from OtherFilter-\>GetOutput()  
this-\>Superclass::SetPrimaryOutput(Output);  
}

i am not sure if this will fix it but at least the image from the nested filter is the output of the outer filter.

---

<div class="post-metadata">

**Author:** ![blowekamp](https://discourse.itk.org/user_avatar/discourse.itk.org/blowekamp/32/79_2.png) [@blowekamp](https://discourse.itk.org/u/blowekamp)\
**Post date:** [April 19, 2018, 1:06pm UTC](https://discourse.itk.org/t/copy-output-of-nested-filter-to-output-of-outer-filter/846/3 "2018-04-19T13:06:12Z")

</div>

I am not sure what you are doing. I need a large example to under stand better to help. I’d recommend creating a small example to share what you are trying to do and the problem you have encountered.

---

<div class="post-metadata">

**Author:** ![dzenanz](https://discourse.itk.org/user_avatar/discourse.itk.org/dzenanz/32/1093_2.png) [@dzenanz](https://discourse.itk.org/u/dzenanz)\
**Post date:** [April 19, 2018, 1:11pm UTC](https://discourse.itk.org/t/copy-output-of-nested-filter-to-output-of-outer-filter/846/4 "2018-04-19T13:11:06Z")

</div>

The method you might be looking for is [Graft](https://itk.org/Doxygen/html/classitk_1_1Image.html#a22761fd818446d920f847b44303e2726). You can search for examples of how to use it.

---

<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:** [May 1, 2018, 12:50pm UTC](https://discourse.itk.org/t/copy-output-of-nested-filter-to-output-of-outer-filter/846/5 "2018-05-01T12:50:38Z")

</div>

It was the Graft() method I was looking for.  
Thank you.  
The example for the [minipipeline](https://itk.org/Wiki/ITK/Examples/Developer/MiniPipeline) was very helpful.
