[Insight-users] `Image Memory Management

Luis Ibanez luis.ibanez@kitware.com
Tue, 10 Dec 2002 17:31:51 -0500


Hi David,

The pixel data in an image is stored in an object
of class

    ImportImageContainer.

http://www.itk.org/Doxygen/html/classitk_1_1ImportImageContainer.html

This seems to be the object you want.

The ImportImageContainer derives from itk::Object
and defines an interface to a C-like array of pixels.

If you get the pointer to the ImportImageContainer from
an image and assign this pointer to a SmartPointer this
will prevent the memory from being released and destroyed
when the image is destroyed.

As you are taking this from the pipeline,
you may want to do something like:

// define the smart pointer to the container
// outside of the scope of the pipeline.

ImageType::PixelContainerPointer pixelContainer;

{ // start filter/pipeline scope

    FilterType::Pointer filter = FilterType::New();
    ....
    filter->Update();
    pixelContainer = filter->GetOutput()->GetPixelContainer();

} // end of filter scope, the filter will be destroyed here



// here the pixelContainer SmartPointer will still
// hold the memory containing pixel data.
// data can be used here:

ImageType::PixelType * pixels = pixelContainer->GetImportPointer();



Please let us know if you have further questions,


   Thanks


    Luis


====================

David Holmes wrote:

> I thought that I'd add one more thing.  I would
> actually prefer to keep this seperate from the filters
> in the fact that I'd much prefer to set a flag for the
> ITK Image which is similar to that of the Image
> container that says that the image object does not
> need to manage the memory and so therefore it can
> exist beyond the scope of the image.
> 
> I couldn't find an appropriate method to do so.  Any
> help would be appreciated.
> 
> Thanks
> 
> david
>