[ITK Community] [Insight-users] Convert image to (multi-dimensional) array in SimpleITK

Zhongliu Xie zhongliu.xie10 at imperial.ac.uk
Sun Jan 12 15:24:06 EST 2014


Dear Brad,

Thanks for your reply. Yet the method image.GetBufferAsFloat() returns 
an IntPtr, how do I convert it to float[] then? Also, in the SimpleITK 
docs it says:
uint8_t *buffer = img->GetBufferAsUInt8();
buffer[c + numComponents*(x+ xSize* (y*+ySize*z))]
what is c in this case?

Regards,
Zhongliu


On 12/01/2014 20:07, Bradley Lowekamp wrote:
> Hello,
>
> Available only in C++ and C#, are a set of methods which being as "GetBufferAs":
>
> itk::simple::Image::GetBufferAsInt8;
> itk::simple::Image::GetBufferAsUInt8;
> itk::simple::Image::GetBufferAsInt16;
> itk::simple::Image::GetBufferAsUInt16;
> itk::simple::Image::GetBufferAsInt32;
> itk::simple::Image::GetBufferAsUInt32;
> itk::simple::Image::GetBufferAsInt64;
> itk::simple::Image::GetBufferAsUInt64;
> itk::simple::Image::GetBufferAsFloat;
> itk::simple::Image::GetBufferAsDouble;
>
> These return a pointer or array to the image buffer that you are looking for. The correctly typed method mush be call, or else an exception will be thrown. The array returned has not line padding, and a SimpleITK image always begins with an index of [0,0,0].
>
> This is a 1-D array but can be access as a 3-D. Given an image of size [xS,yS,zS], you can access the image at index [x,y,z] as you wish by image[x+y*xS+z*xS*yS], so x is the fastest axis and z is the slowest.
>
> Brad
>
>
> On Jan 12, 2014, at 1:35 PM, Zhongliu Xie <zhongliu.xie10 at imperial.ac.uk> wrote:
>
>> Dear fellow ITK users,
>>
>> Recently I have been using Simple ITK under C# environment. I wonder whether there is a way to quickly convert an image into an array of intensities (leaving out the meta info)? In particular, is it possible to directly convert to a multidimensional array such as intensity[x,y,z] (or intensity[x][y][z] in C++) indicating the intensity of voxel at <x,y,z>?
>>
>> BTW, I also noticed there is something called Buffer which seems related. Could someone explain what  buffer is more explicitly so that I can make sure I understand it correctly?
>>
>> Thanks in advance,
>> Zhongliu
>> _____________________________________
>> 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.php
>>
>> 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

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/community/attachments/20140112/bab73072/attachment-0002.html>
-------------- next part --------------
_____________________________________
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.php

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 Community mailing list