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

Bradley Lowekamp blowekamp at mail.nih.gov
Sun Jan 12 15:07:26 EST 2014


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



More information about the Insight-users mailing list