<div class="gmail_quote">On Mon, Oct 25, 2010 at 10:43 AM, Karthik Krishnan <span dir="ltr"><<a href="mailto:karthik.krishnan@kitware.com">karthik.krishnan@kitware.com</a>></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 class="gmail_quote"><div><div></div><div class="h5">On Mon, Oct 25, 2010 at 3:49 AM, David Doria <span dir="ltr"><<a href="mailto:daviddoria@gmail.com" target="_blank">daviddoria@gmail.com</a>></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't believe the following will work. The idea is to pass an image to a function and smooth it "in place".</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<</div><div><span style="white-space: pre-wrap;">                </span> ImageType, ImageType > filterType;</div><div> </div><div> filterType::Pointer meanFilter = filterType::New();</div>
<div> meanFilter->SetInput(image);</div><div> meanFilter->Update();</div><div><br></div><div> image = meanFilter->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<</div>
<div><span style="white-space: pre-wrap;">                </span> ImageType, ImageType > filterType;</div><div> </div><div> filterType::Pointer meanFilter = filterType::New();</div><div> meanFilter->SetInput(image);</div>
<div> meanFilter->Update();</div><div><br></div><div> output = meanFilter->GetOutput();</div><div>}</div></div></blockquote></div></div><div><br><br>That'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 "output".<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->SetInput(image);<br> meanFilter->GraftOutput(image);<br> meanFilter->Update();<br><br></div></div></blockquote>
</div><br>Ascertain this by printing the image object to and after execution.. something like:<br><br> meanFilter->SetInput(image);<br> meanFilter->GraftOutput(image);<br><br> meanFilter->GetInput()->Print(std::cout);<br>
<div> meanFilter->Update();<br> meanFilter->GetOutput()->Print(std::cout);<br><br>... and the internal PixelContainer object on the input as well as the output should (hopefully :) ) have the same address.<br></div>