[Insight-users] WG: Pipeline problems: How to delete input data after calculation

Lodron, Gerald Gerald.Lodron at joanneum.at
Fri Apr 9 02:17:27 EDT 2010



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?

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())? 
-> If one times, where does oPointerToInput points at? Is it a null pointer? 
-> Would it be the same if i would replace "oFilter1->SetInput(oReader->GetOutput());" with "oFilter1->SetInput(oPointerToInput);"

Best regards




-----Ursprüngliche Nachricht-----
Von: Luis Ibanez [mailto:luis.ibanez at kitware.com] 
Gesendet: Donnerstag, 08. April 2010 21:23
An: Lodron, Gerald
Cc: insight-users at itk.org
Betreff: Re: [Insight-users] WG: Pipeline problems: How to delete input data after calculation

Hi Gerald,

You may want to try


         TFilter1->ReleaseDataFlagOn()


and..., another option is to try to use InPlace filters, (if possible).


That said, your method of creating filters in a local scope, running them, capturing the output and destroying the filter, should work just as well.

It is not the "pipeline-way" of doing things but it should help you with the memory restrictions.



    Regards,


          Luis


-------------------------------------------
On Thu, Apr 8, 2010 at 6:12 AM, Lodron, Gerald <Gerald.Lodron at joanneum.at> wrote:
>
> Hi
>
> Since i have a lot of memory problems i try to release my data of the front pipline elements and do not exactly know how to do that, my example (pseudo code, may not work):
>
> //Typedefs
> Typedef Itk::ImageReader<Type> Treader; Typedef 
> itk::ImageFilter1<Type, Type> TFilter1; Typedef 
> itk::ImageFilter2<Type, Type> TFilter2; Typedef itk::ImageWriter<Type> 
> Twriter;
>
> //Create Instances
> Treader::Pointer oReader = Treader::New(); TFilter1::Pointer oFilter1 
> = TFilter1::New(); TFilter2::Pointer oFilter2 = TFilter2::New(); 
> Treader::Pointer oWriter = Treader::New();
>
> //Settings
> oReader->SetFileName("InImage.mha");
> oWriter->SetFileName("OutImage.mha");
>
> //Pipeline
> oFilter1->SetInput(oReader->GetOutput());
> oFilter2->SetInput(oFilter1->GetOutput());
> oWriter->SetInput(oFilter2->GetOutput());
>
> The programm works but i think here I need the memory of InImage.mha three times:
> - First after reader
> - Second after Filter1
> - Third after Filter2
>
> I want to do the following:
> - First load Image on memory
> - Calculate result of Filter1, release memory of reader
> - Calculate result of Filter2, release memory of filter1
>
> Now i need the memory only one time. It is not allowed to call the delete function of the process objects so how can i tell the smart pointers to relese that stuff, currently i make the following strange thing:
>
> //Typedefs
> Typedef Itk::ImageReader<Type> Treader; Typedef 
> itk::ImageFilter1<Type, Type> TFilter1; Typedef 
> itk::ImageFilter2<Type, Type> TFilter2; Typedef itk::ImageWriter<Type> 
> Twriter;
>
> Itk::Image<Type>::Pointer oPointer;
>
> {
>        Treader::Pointer oReader = Treader::New();
>        oReader->SetFileName("InImage.mha");
>        oReader->Update();
>        oPointer = oReader->GetOutput();
>        oPointer->DisconnectPipeline(); } {
>        TFilter1::Pointer oFilter1 = TFilter1::New();
>        oFilter1->SetInput(oPointer);
>        oFilter1->Update();
>        oPointer = oFilter1->GetOutput();
>        oPointer->DisconnectPipeline(); } {
>        TFilter2::Pointer oFilter2 = TFilter2::New();
>        oFilter2->SetInput(oPointer);
>        oFilter2->Update();
>        oPointer = oFilter2->GetOutput();
>        oPointer->DisconnectPipeline(); }
>
> {
>        Treader::Pointer oWriter = Treader::New();
>        oWriter ->SetInput(oPointer);
>        oWriter->SetFileName("OutImage.mha");
>        oWriter->Update();
> }
>
> Better suggestions?
>
> _____________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at 
> http://www.kitware.com/opensource/opensource.html
>
> Kitware offers ITK Training Courses, for more information visit:
> http://www.kitware.com/products/protraining.html
>
> Please keep messages on-topic and check the ITK FAQ at:
> http://www.itk.org/Wiki/ITK_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.itk.org/mailman/listinfo/insight-users
>


More information about the Insight-users mailing list