<div class="gmail_quote">On Mon, Oct 25, 2010 at 3:49 AM, David Doria <span dir="ltr">&lt;<a href="mailto:daviddoria@gmail.com">daviddoria@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div>I don&#39;t believe the following will work. The idea is to pass an image to a function and smooth it &quot;in place&quot;.</div><div><br></div><div>ImageType::Pointer image = get image from somewhere...</div>
<div>SmoothImage(image);</div><div><br></div><div>where:</div><div><br></div><div>void SmoothImage(ImageType::Pointer image)</div><div>{</div><div> // Create and setup a mean filter</div>
<div> typedef itk::MeanImageFilter&lt;</div><div><span style="white-space: pre-wrap;">                </span>  ImageType, ImageType &gt;  filterType;</div><div> </div><div>  filterType::Pointer meanFilter = filterType::New();</div>
<div>  meanFilter-&gt;SetInput(image);</div><div>  meanFilter-&gt;Update();</div><div><br></div><div>  image = meanFilter-&gt;GetOutput();</div><div>}</div><div><br></div><div>Of course you can do this:</div><div><br></div>

<div><div>ImageType::Pointer image = get image from somewhere...</div><div>ImageType::Pointer output = ImageType::Pointer::New();</div>
<div>SmoothImage(image, output);</div></div><div><br></div><div>void SmoothImage(ImageType::Pointer image, ImageType::Pointer output)</div><div><div>{</div><div> // Create and setup a mean filter</div><div> typedef itk::MeanImageFilter&lt;</div>

<div><span style="white-space: pre-wrap;">                </span>  ImageType, ImageType &gt;  filterType;</div><div> </div><div>  filterType::Pointer meanFilter = filterType::New();</div><div>  meanFilter-&gt;SetInput(image);</div>
<div>  meanFilter-&gt;Update();</div><div><br></div><div>  output = meanFilter-&gt;GetOutput();</div><div>}</div></div></blockquote><div><br><br>That&#39;s not an inplace processing of the data. What is being done above is to allocate the output buffer, in addition to the input buffer - executing the filter - and then taking a reference the newly created output buffer into the variable &quot;output&quot;.<br>
<br>You might as well just set ReleaseDataFlagOn() on the meanFilter. That way, the memory footprint remains the same as above, and the code is cleaner. Its input gets released after a downstream filter has consumed its output.<br>
<br>A in-place filter overwrites its input buffer. The snippet below should do that<br><br>  meanFilter-&gt;SetInput(image);<br>  meanFilter-&gt;GraftOutput(image);<br>  meanFilter-&gt;Update();<br><br><br>Filters that derive from itk::InPlaceImageFilter do this automatically bypassing the usual AllocateOutputs prior to execution.<br>
<br><br><br></div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><div><br></div><div>but that seems a bit awkward.</div><div><br>Is there a pattern that makes sense for this &quot;in place filtering&quot; style function?</div>

<div><br></div>Thanks,<br><font color="#888888"><br>David<br>
</font><br>_____________________________________<br>
Powered by <a href="http://www.kitware.com" target="_blank">www.kitware.com</a><br>
<br>
Visit other Kitware open-source projects at<br>
<a href="http://www.kitware.com/opensource/opensource.html" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
<br>
Kitware offers ITK Training Courses, for more information visit:<br>
<a href="http://www.kitware.com/products/protraining.html" target="_blank">http://www.kitware.com/products/protraining.html</a><br>
<br>
Please keep messages on-topic and check the ITK FAQ at:<br>
<a href="http://www.itk.org/Wiki/ITK_FAQ" target="_blank">http://www.itk.org/Wiki/ITK_FAQ</a><br>
<br>
Follow this link to subscribe/unsubscribe:<br>
<a href="http://www.itk.org/mailman/listinfo/insight-users" target="_blank">http://www.itk.org/mailman/listinfo/insight-users</a><br>
<br></blockquote></div><br>