[Insight-users] WG: Pipeline problems: How to delete input data after calculation
Luis Ibanez
luis.ibanez at kitware.com
Fri Apr 9 19:17:17 EDT 2010
Hi Gerald,
Please see my comments below
------------------------------------------------------------
On Fri, Apr 9, 2010 at 2:17 AM, Lodron, Gerald <Gerald.Lodron at joanneum.at>wrote:
>
>
> Hi,
>
> So, let me see if i understand in my following example:
>
> Typedef Itk::ImageReader<Type> Treader;
> Typedef itk::ImageFilter1<Type, Type> TFilter1;
>
> Treader::Pointer oReader = Treader::New();
> TFilter1::Pointer oFilter1 = TFilter1::New();
>
> oReader->SetFileName("InImage.mha");
> oReader->ReleaseDataFlagOn();
>
> oFilter1->SetInput(oReader->GetOutput());
> oFilter1->Update();
>
> -> Is it correct that now there is the image only one times in memory which
> is in the output of oFilter1?
>
>
Yes,
At this point the buffer of the image that was
allocated by the reader has been deleted,
so the only pixel buffer in memory at this
point is he one of the oFilter1 output image.
> My second example:
>
> Typedef itk::Image<short, 2> Timage;
> Typedef Itk::ImageReader<Timage> Treader;
> Typedef itk::ImageFilter1<Timage, Timage> TFilter1;
>
> Treader::Pointer oReader = Treader::New();
> TFilter1::Pointer oFilter1 = TFilter1::New();
>
> oReader->SetFileName("InImage.mha");
> oReader->ReleaseDataFlagOn();
> Timage::Pointer oPointerToInput = oReader->GetOutput();
>
> oFilter1->SetInput(oReader->GetOutput());
> oFilter1->Update();
>
>
> -> What exactly happens here? Does the reader reads the image two times or
> only one times (at oFilter1->Update())?
>
Grabbing a pointer to the output image of the reader
doesn't change the behavior. So this will be equivalent
to your first example.
The behavior doesn't change because the actual mechanism
of the Release data flag is not to destroy the image but to
destroy its buffer. This is done by internally calling the Initialize()
method of the image.
Whose code is essentially:
Image<TPixel, VImageDimension>
::Initialize()
{
Superclass::Initialize();
m_Buffer = PixelContainer::New();
}
Note that, on the other hand, the behavior will have changed
if you hold a smart pointer to the buffer.
Something like
PixelContainer::Pointer pixelContainer =
reader->GetOutput()->GetPixelContainer()
since in that case the Image code
m_Buffer = PixelContainer::New();
will not result in the destruction of the pixel
container.
------------------------------------------
> -> If one times, where does oPointerToInput points at? Is it a null
> pointer?
>
Nope, the Smart pointer to the output image is still
a valid pointer to an image, but this time it is to
an image whose buffer is emtpy. Therefore, if you
attempt to use such image, you most likely will get
a segmentation fault.
-> Would it be the same if i would replace
> "oFilter1->SetInput(oReader->GetOutput());" with
> "oFilter1->SetInput(oPointerToInput);"
>
>
Yes, it will be the same,
because the call to Image::Initialize() happens
as a secondary (internal) effect of the call to
oFilter1->Update();
not as an effect of
reader->Update();
If you want to get a first hand feeling on how
this works, you can simply do:
Apply this patch:
===================================================================
RCS file: /cvsroot/Insight/Insight/Code/Common/itkImage.txx,v
retrieving revision 1.103
diff -r1.103 itkImage.txx
58a59
> std::cout << "Image::Initialize" << std::endl;
and use the attached file as an example.
When you run it as:
./MedianImageFilter input.mhd output.mhd 0
it will not use the release data flag
so you won't see the message from the Initialize method.
You will only see the following messages:
Reader updated
Filter 1 updated
Filter 2 updated
Writer updated
While if you call the same program as
./MedianImageFilter input.mhd output.mhd 1
then you will see the following messages:
Reader updated
Image::Initialize
Filter 1 updated
Image::Initialize
Filter 2 updated
Image::Initialize
Writer updated
-------------------------------------------------------------------------
"Glimpsing at the Source Leaves No Doubt " :-)
Regards,
Luis
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20100409/e35351ab/attachment.htm>
-------------- next part --------------
CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
IF(COMMAND CMAKE_POLICY)
CMAKE_POLICY(SET CMP0003 NEW)
ENDIF(COMMAND CMAKE_POLICY)
PROJECT(ReleaseDataFlag)
FIND_PACKAGE(ITK REQUIRED)
INCLUDE(${ITK_USE_FILE})
ADD_EXECUTABLE(MedianImageFilter MedianImageFilter.cxx )
TARGET_LINK_LIBRARIES(MedianImageFilter ITKIO)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: MedianImageFilter.cxx
Type: text/x-c++src
Size: 2714 bytes
Desc: not available
URL: <http://www.itk.org/pipermail/insight-users/attachments/20100409/e35351ab/attachment.cxx>
More information about the Insight-users
mailing list