[vtkusers] How to convert vtkImageData to Numpy Array?

Eric E. Monson emonson at cs.duke.edu
Mon Apr 19 10:43:08 EDT 2010


Hey Jothy,

I think the attributes (PointData and CellData) in vtkImageData are just stored internally as 1D arrays, so it's natural that the numpy conversion produces this output. If you're trying to bring vector attributes over to numpy it should deal fine with multi-component arrays, so you shouldn't have to pull out components of vectors separately. 

If you want to have a 3D array in numpy you should be able to use array.reshape to do the 1D->3D conversion. Notice that reshape has an optional "order" parameter {'C', 'F'} to "Determines whether the array data should be viewed as in C (row-major) order or FORTRAN (column-major) order."

-Eric

------------------------------------------------------
Eric E Monson
Duke Visualization Technology Group


On Apr 19, 2010, at 7:20 AM, Jothybasu K Selvaraj wrote:

> Hi all,
> 
> I want to convert a vtkImageData to Numpy array.The built in numpy support only seem to support linear array.
> 
> Is there any other method to do this? If not, I have to create by getting the scalarComponet one by one to create the 3D array.
> 
> Thanks,
> 
> Jothy
> _______________________________________________
> Powered by www.kitware.com
> 
> Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html
> 
> Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ
> 
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtkusers




More information about the vtkusers mailing list