[Insight-users] Re: writing filter results back to an image buffer

Luis Ibanez luis.ibanez at kitware.com
Wed, 18 Feb 2004 23:23:38 -0500


Hi Michael,

What you are doing here for getting the image
buffer is ok, but the mummification method is
better since you save the time of making the
copy.

In the mummification method you take over the
memory buffer of the image and ask the image
not to delete the buffer when the image is
destroyed. (you will have to delete the buffer
yourself when you are done with it).

In the method that you are using here below,
you get the pointer to the image buffer, you
allocate an equivalent block of memory, memcopy
the entire memory block, and finally destroy
the itk::Image.  With the mummification method
you can avoid the allocation, and the memcopy,
which are actually time consuming.


Regards,


    Luis


------------------
Michael G wrote:

> Hi All,
> 
> I believe I got the answer to copying the result of a filter to an 
> external image buffer:
> 
>    InputImageType::PixelContainerPointer pixContainer;
> 
>    pixContainer = filter->GetOutput()->GetPixelContainer();
>    ImageType::PixelType * pixels = pixContainer->GetImportPointer();
> 
>    memcpy( my_buf, pixels, ((width * height) * sizeof(PixelType)));
> 
> It seems to be working now, but is this the correct method?
> 
> Thank you for all your help,
> 
> Sincerely,
> Michael
> 
> 
>> From: "Michael G" <michaelguiliametti at hotmail.com>
>> To: luis.ibanez at kitware.com
>> CC: insight-users at itk.org
>> Subject: Re: [Insight-users] writing ImageRegistration1 results back 
>> to an image buffer
>> Date: Tue, 17 Feb 2004 20:05:08 +0000
>>
>> Hi Luis,
>>
>> Thanks for pointing me to the tutorial material - I read through 
>> GettingStarted-V - Mummifying the Buffer because that seems like what 
>> I'm trying to do. The end of the example ends with setting 'buffer' 
>> equal to the PixelContainer pointer. Will buffer now be filled with 
>> the data from the container? I included the end of my code below,
>>
>> {
>>    ...
>>    unsigned int * my_buf = new unsigned int[ width * height ];
>>
>>    OutputImageType::PixelContainer *container = 
>> resample->GetOutput()->GetPixelContainer();
>>    container->SetContainerManageMemory( false );
>>    my_buf = container->GetImportPointer();
>>
>>    ... do stuff with my_buf.. is it filled correctly with the results 
>> from *container?
>>
>>    return 0;
>> }
>>
>>
>> Thank you Luis,
>>
>> Michael
>>
>>
>>
>>> From: Luis Ibanez <luis.ibanez at kitware.com>
>>> To: Michael G <michaelguiliametti at hotmail.com>
>>> CC: insight-users at itk.org
>>> Subject: Re: [Insight-users] writing ImageRegistration1 results back 
>>> to an image buffer
>>> Date: Tue, 17 Feb 2004 01:34:59 -0500
>>>
>>>
>>> Hi Michael,
>>>
>>> The methods for passing data between an application and
>>> an ITK filter are described in detail on the tutorial
>>> presentations
>>>
>>> http://www.itk.org/HTML/Tutorials.htm
>>>
>>> In particular in
>>> http://www.itk.org/CourseWare/Training/GettingStarted-V.pdf
>>>
>>>
>>> Regards,
>>>
>>>
>>>    Luis
>>>
>>>
>>> ------------------
>>> Michael G wrote:
>>>
>>>> Hello All,
>>>>
>>>> I've just got reading from image buffers for use with itk motion 
>>>> register functions working ok. I wanted to inquire about writing the 
>>>> results of the registration back to an image buffer as opposed to a 
>>>> file as in ImageRegistration1 - I have set this up:
>>>>
>>>> // motion registration has already been performed at this point
>>>> // the resampler's input gets the data from the image buffer ok
>>>> resample->SetInput( movedItkBuffer->GetOutput() );
>>>>
>>>> // the caster's input is the image buffer
>>>> caster->SetInput( resample->GetOutput() );
>>>>
>>>> // here how could i go about writing the result of caster
>>>> // to a buffer - or is 'movedItkBuffer' being overwritten
>>>> // with the resampled data already because it was set as
>>>> // the input of 'resample' in the first place?
>>>>
>>>> // ImageRegistration1 simply writes it out with an image writer
>>>> writer->SetInput( caster->GetOutput() );
>>>> writer->Update();
>>>>
>>>> // I would like to do something like
>>>> movedItkBuffer->SetInput( caster->GetOuput() );
>>>> movedItkBuffer->Update();
>>>> // but that is illegal
>>>>
>>>>
>>>> Thank you for your time and any pointers,
>>>> Michael.
>>>>