[vtkusers] Extract Data from vtkImageReslice to numpy array

Eric E. Monson emonson at cs.duke.edu
Tue Jun 30 10:35:53 EDT 2009


Hey Peter,

There is a handy set of utilities for converting between vtkDataArray  
(e.g. vtkDoubleArray, vtkIntArray) and numpy arrays called  
numpy_support that may help you. Try something like this:

import vtk
import vtk.util.numpy_support as VN

reader = vtk.vtkXMLImageDataReader()
reader.SetFileName('chombo3d_1.vti')
reader.Update()
image_cells = reader.GetOutput().GetCellData()
phi_array = VN.vtk_to_numpy(image_cells.GetArray('phi'))

Note that numpy_to_vtk() is also in there. There may be other nice  
tricks, but I find this module very useful.

Good luck,
-Eric

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


On Jun 30, 2009, at 9:54 AM, Peter Bloomfield wrote:

>
> Hello,
>
> I am new to VTK, so if this has been asked before I apologise.
>
> I am trying to use VTK from within Python. I successfully downloaded  
> and
> compiled VTK V5.4.2 including the python wrappings/bindings, and  
> issuing
> 'import vtk' from within python works good.
>
> Initially I want to do is take a volume of data (float), re-slice it  
> in an
> arbitrary orientation and then extract the re-sliced plane from vtk  
> and return
> it to a numpy array.
>
> I am using vtk.vtkImageReslice(), but do not know how to get the  
> data out from
> here.
>
> Does anyone have any suggestions of how I can achieve this? I have  
> tried
> looking at vtkImageExportToArray but have no idea how to use this  
> from within
> python.
>
> Many thanks
>
>
> Peter
> _______________________________________________
> 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