[Insight-users] Passing pixel data from or to itk filter

Reinhard Hameeteman k.hameeteman+maillist at gmail.com
Mon Dec 3 05:50:39 EST 2007


Hi,

I am experiencing similar problems as described in
http://www.itk.org/pipermail/insight-users/2005-December/016027.html.
I use an itk pipeline within another image processing framework
(MeVisLab). To avoid unnecessary memory copying I want to pass a
pointer to the image data output from a itk filter output to an other
data structure. As Luis described in e.g.
http://www.itk.org/pipermail/insight-users/2007-May/022343.html there
are 2 methods:
1) Mummify the buffer of the output filter
2) Provide the memory buffer to the output filter so when it computes
the output image, it is already stored in the buffer that you
provided.

Until now, I used method 1 with success. Like this:
CustomDatatType m_MemberImage.;
m_MemberImage.setData(
itkFilter->GetOutput()->GetPixelContainer()->GetImportPointer() );
itkFilter->GetOutput()->GetPixelContainer()->SetContainerManageMemory(false);

However this only works when I have a scalar voxel type and now I have
created a pipeline that produces a  itk::Image< itk::Vector< float, 3
>, 3> image. The creation of the image and the passing of the pointer
to my own data structure works fine. But as soon as I try to release
the memory, my program crashes. This does not happen when the voxel
type is of type int which is still unexplained.

I used the second method as mentioned by Luis like this:

   CustomDatatType m_MemberImage;
   // Set size of m_MemberImage and allocate memory

   // Set size of itk output image
   region.SetSize( size );
   region.SetIndex( start );
   itkFilter->GetOutput(1)->SetRegions( region);

   // Set pointer of filter image to allocated data
   ItkFilterType::VectorVoxelType * pixelData;
   pixelData = static_cast<ItkFilterType::VectorVoxelType* >(
m_MemberImage.getData() );
   itkFilter->GetOutput(1)->
                 GetPixelContainer()->
                 SetImportPointer(pixelData, m_MemberImage.getSize(), false);

Using this method, there is still a problem with the vector voxel
typed image. Using an image with int voxels things works fine, but as
soon as the mentioned vector voxel type is used, access violations
occur when the itk filter writes to the output buffer. This suggests
that somehow the size of the buffer or the datatype is not set
correctly. I checked both and they are ok.

My questions:
- Could someone comment on the difference in deleting a scalar and
vector voxel typed image buffer.
- Is there more generally, any difference in the memory management of
scalar and multiple component voxel typed images?
- Are there any suggestions on where to look for the problem in the
second approach?

Thanks a lot.


More information about the Insight-users mailing list