[Insight-users] fast assign ITK image to an array?
Bill Lorensen
bill.lorensen at gmail.com
Sat Apr 23 12:39:54 EDT 2011
It is unfortunate that we exposed the GetBufferPointer() method.
Currently, the memory is allocated contiguously. For backward
compatibility we are probably stuck with GetBufferPointer although in
the future, it could be an inefficient mechanism if we need to
rearrange memory on the fly just to maintain backward compatibility.
I would recommend not using it.
Bill
On Tue, Apr 19, 2011 at 4:17 PM, Dongfeng Han <handongfeng at gmail.com> wrote:
> I also have one concern.
> In fact, I want to use memcpy. to do such operation
> memcpy( imgDest->GetBufferPointer(), imgDrc->GetBufferPointer(),
> sizrof(pixelType) * x_size*y_size*z_size)
>
> Can we make sure img->GetBufferPointer() is continuous?;
> That means , ITK will allocate memory continuously?
> I guess, ITK should support allocate memory slice by slice.
> anyone can confirm it?
> Best
> dongfeng
>
>
> On Sun, Apr 17, 2011 at 2:11 PM, Neil Panjwani <paniwani at gmail.com> wrote:
>>
>> I have some code that treats images as arrays. Using GetBufferPointer()
>> works perfectly. You can in fact set the value using the normal notation:
>> PixelType * imgArray = img->GetBufferPointer();
>> imgArray[100] = 1;
>> I don't think there is any padding. I'm unfamiliar with the
>> ImportImageFilter.
>> - Neil
>> On Sun, Apr 17, 2011 at 5:06 AM, Francis Girard
>> <francis.girard07 at gmail.com> wrote:
>>>
>>> Hi,
>>> Can we iterate safely using this raw buffer pointer?
>>> Maybe there is some padding to ensure some byte alignment property?
>>> Also if there is a GetBufferPointer notice that there is no
>>> SetBufferPointer. So I don't think you can just set some buffer pointer as
>>> is the case with some C++ STL containers. With that API, you will at least
>>> need to make a copy of the contents, and even then we must make sure that
>>> there is enough allocated memory.
>>> After all, what would be the usefulness of the "ImportImageFilter" if we
>>> could simply and safely set a raw buffer pointer?
>>> And finally what precisely the "ImportImageFilter" does under the hood?
>>> Apprently it does _NOT_ make a copy of your buffer pointer. So maybe that is
>>> fast. But I am not sure of what I am saying.
>>> Thanks
>>> Francis
>>>
>>>
>>>
>>> 2011/4/17 Neil Panjwani <paniwani at gmail.com>
>>>>
>>>> You can access the image in 1D C++ array form using the
>>>> GetBuferPointer() function.
>>>> - Neil
>>>>
>>>>
>>>> On Sat, Apr 16, 2011 at 8:53 PM, Dongfeng Han <handongfeng at gmail.com>
>>>> wrote:
>>>>>
>>>>> Hello everyone,
>>>>> Anyone know how to fast assign ITK image data to an c++ array?
>>>>> The common approach is to use the iterator of the ITK image and assign
>>>>> the c++ array.
>>>>> Any other fast way?
>>>>> Best
>>>>> df
>>>>>
>>>>>
>>>>> _____________________________________
>>>>> Powered by www.kitware.com
>>>>>
>>>>> Visit other Kitware open-source projects at
>>>>> http://www.kitware.com/opensource/opensource.html
>>>>>
>>>>> Kitware offers ITK Training Courses, for more information visit:
>>>>> http://www.kitware.com/products/protraining.html
>>>>>
>>>>> Please keep messages on-topic and check the ITK FAQ at:
>>>>> http://www.itk.org/Wiki/ITK_FAQ
>>>>>
>>>>> Follow this link to subscribe/unsubscribe:
>>>>> http://www.itk.org/mailman/listinfo/insight-users
>>>>>
>>>>
>>>>
>>>> _____________________________________
>>>> Powered by www.kitware.com
>>>>
>>>> Visit other Kitware open-source projects at
>>>> http://www.kitware.com/opensource/opensource.html
>>>>
>>>> Kitware offers ITK Training Courses, for more information visit:
>>>> http://www.kitware.com/products/protraining.html
>>>>
>>>> Please keep messages on-topic and check the ITK FAQ at:
>>>> http://www.itk.org/Wiki/ITK_FAQ
>>>>
>>>> Follow this link to subscribe/unsubscribe:
>>>> http://www.itk.org/mailman/listinfo/insight-users
>>>>
>>>
>>
>
>
> _____________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Kitware offers ITK Training Courses, for more information visit:
> http://www.kitware.com/products/protraining.html
>
> Please keep messages on-topic and check the ITK FAQ at:
> http://www.itk.org/Wiki/ITK_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.itk.org/mailman/listinfo/insight-users
>
>
More information about the Insight-users
mailing list