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

Luis Ibanez luis.ibanez at kitware.com
Sat Dec 8 20:37:46 EST 2007


Hi Reinhard,


I'm afraid that by now,
your questions are too entangled to address them correctly.


Let me rephrase the questions and please correct me if I'm getting
them wrong.


1) you are running an ITK pipeline and you want the output of the
    pipeline to store its result in a block of memory that you have
    pre-allocated from your application.


2) You want to do this with a filter that produces as output an
    image whose pixel type is Vector<float,3>.


3) You are attempting to use the following method:

     m_Filter->GetOutput()->SetRegions(region);

     m_Filter->GetOutput()->GetPixelContainer()->SetImportPointer(
         static_cast< OutputPixelType * >( applicationAllocatedBuffer ),
         totalNumberOfPixels, false);

     m_Filter->GetOutput()->Allocate( );


4) When you run it, it crashes at the moment of dealocating the
    memory.



Is that right ?


If so, this leads to suspect that


A) you have not allocated the right size of memory in your application


or


B) your assumptions about the organization of the pixel components
    in memory are not correct.



Please provide a fresh description of the state of your problem.


   Thanks



      Luis




---------------------------
Reinhard Hameeteman wrote:
> 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.
>>
> 
> _______________________________________________
> Insight-users mailing list
> Insight-users at itk.org
> http://www.itk.org/mailman/listinfo/insight-users
> 


More information about the Insight-users mailing list