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

Reinhard Hameeteman k.hameeteman+maillist at gmail.com
Wed Dec 5 11:34:57 EST 2007


To comment on my own questions:
The error in the second approach, was due to an invalid pointer the
was passed to the itk filter.
However the other 2 questions still remain. And since this approach
preferable because you allocate the memory once it is needed and not
long before that (depending on your filter), I would very much get
some comments on those issues.
Is someone capable of doing so?

Reinhard


On Dec 3, 2007 11:50 AM, Reinhard Hameeteman
<k.hameeteman+maillist at gmail.com> wrote:
> 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