Hi Gerald,<br><br>Please see my comments below<br><br>------------------------------------------------------------<br><div class="gmail_quote">On Fri, Apr 9, 2010 at 2:17 AM, Lodron, Gerald <span dir="ltr"><<a href="mailto:Gerald.Lodron@joanneum.at">Gerald.Lodron@joanneum.at</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;"><br>
<br>
Hi,<br>
<br>
So, let me see if i understand in my following example:<br>
<div class="im"><br>
Typedef Itk::ImageReader<Type> Treader;<br>
Typedef itk::ImageFilter1<Type, Type> TFilter1;<br>
<br>
</div><div class="im">Treader::Pointer oReader = Treader::New();<br>
TFilter1::Pointer oFilter1 = TFilter1::New();<br>
<br>
</div>oReader->SetFileName("InImage.mha");<br>
oReader->ReleaseDataFlagOn();<br>
<br>
oFilter1->SetInput(oReader->GetOutput());<br>
oFilter1->Update();<br>
<br>
-> Is it correct that now there is the image only one times in memory which is in the output of oFilter1?<br>
<br></blockquote><div><br><br>Yes,<br>At this point the buffer of the image that was <br>allocated by the reader has been deleted,<br>so the only pixel buffer in memory at this <br>point is he one of the oFilter1 output image.<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;">
My second example:<br>
<br>
Typedef itk::Image<short, 2> Timage;<br>
Typedef Itk::ImageReader<Timage> Treader;<br>
Typedef itk::ImageFilter1<Timage, Timage> TFilter1;<br>
<div class="im"><br>
Treader::Pointer oReader = Treader::New();<br>
TFilter1::Pointer oFilter1 = TFilter1::New();<br>
<br>
</div>oReader->SetFileName("InImage.mha");<br>
oReader->ReleaseDataFlagOn();<br>
Timage::Pointer oPointerToInput = oReader->GetOutput();<br>
<br>
oFilter1->SetInput(oReader->GetOutput());<br>
oFilter1->Update();<br>
<br>
<br>
-> What exactly happens here? Does the reader reads the image two times or only one times (at oFilter1->Update())?<br></blockquote><div><br>Grabbing a pointer to the output image of the reader <br>doesn't change the behavior. So this will be equivalent<br>
to your first example.<br><br>The behavior doesn't change because the actual mechanism<br>of the Release data flag is not to destroy the image but to<br>destroy its buffer. This is done by internally calling the Initialize() <br>
method of the image.<br><br>Whose code is essentially:<br><br> Image<TPixel, VImageDimension><br> ::Initialize()<br> {<br> Superclass::Initialize();<br>
m_Buffer = PixelContainer::New();<br> }<br><br><br>Note that, on the other hand, the behavior will have changed<br>if you hold a smart pointer to the buffer.<br><br>Something like<br><br>
PixelContainer::Pointer pixelContainer = <br> reader->GetOutput()->GetPixelContainer()<br><br>since in that case the Image code<br><br> m_Buffer = PixelContainer::New();<br><br>will not result in the destruction of the pixel<br>
container.<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;">
-> If one times, where does oPointerToInput points at? Is it a null pointer?<br></blockquote><div><br><br>Nope, the Smart pointer to the output image is still<br>a valid pointer to an image, but this time it is to<br>
an image whose buffer is emtpy. Therefore, if you<br>attempt to use such image, you most likely will get<br>a segmentation fault.<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;">
-> Would it be the same if i would replace "oFilter1->SetInput(oReader->GetOutput());" with "oFilter1->SetInput(oPointerToInput);"<br>
<br></blockquote><div><br>Yes, it will be the same, <br>because the call to Image::Initialize() happens<br>as a secondary (internal) effect of the call to<br><br> oFilter1->Update();<br><br>not as an effect of <br>
<br> reader->Update();<br><br><br>If you want to get a first hand feeling on how<br>this works, you can simply do:<br><br><br>Apply this patch:<br><br>===================================================================<br>
RCS file: /cvsroot/Insight/Insight/Code/Common/itkImage.txx,v<br>retrieving revision 1.103<br>diff -r1.103 itkImage.txx<br>58a59<br>> std::cout << "Image::Initialize" << std::endl;<br><br><br>and use the attached file as an example.<br>
<br>When you run it as:<br><br>./MedianImageFilter input.mhd output.mhd 0<br><br>it will not use the release data flag<br>so you won't see the message from the Initialize method.<br>You will only see the following messages:<br>
<br>Reader updated<br>Filter 1 updated<br>Filter 2 updated<br>Writer updated<br><br><br>While if you call the same program as<br><br> ./MedianImageFilter input.mhd output.mhd 1<br><br><br>then you will see the following messages:<br>
<br>Reader updated<br>Image::Initialize<br>Filter 1 updated<br>Image::Initialize<br>Filter 2 updated<br>Image::Initialize<br>Writer updated<br><br><br></div></div>-------------------------------------------------------------------------<br>
<br><br>"Glimpsing at the Source Leaves No Doubt " :-)<br><br><br> Regards,<br><br><br> Luis<br><br>