[vtkusers] Extract Data from vtkImageReslice to numpy array
Peter Bloomfield
peter.bloomfield at camhpet.ca
Tue Jun 30 12:44:13 EDT 2009
Hey Eric,
Thanks, that seems to have got it.
Peter
On Tuesday 30 June 2009 12:25:49 pm Eric E. Monson wrote:
> Try image_point_data = reader.GetOutput().GetPointData() and print
> that -- the real data is probably in arrays there.
>
> -Eric
>
> On Jun 30, 2009, at 12:09 PM, Peter Bloomfield wrote:
> > Hi,
> >
> > I just tried the following,
> >
> > I read my flat image data (I assume)
> > reader = vtk.vtkImageReader2()
> > reader.SetFileName("MyImage.img")
> > reader.SetDataExtent(0, 255, 0, 255, 0, 206)
> > reader.SetDataSpacing(1.218750, 1.218750, 1.218750)
> > reader.SetDataOrigin(0.0, 0.0, 0.0)
> > reader.SetDataScalarTypeToFloat()
> > reader.SetFileDimensionality(3)
> > reader.Update()
> >
> > and then tried the following
> > image_cells = reader.GetOutput().GetCellData()
> > print image_cells
> > vtkCellData (0x833e630)
> > Debug: Off
> > Modified Time: 211
> > Reference Count: 2
> > Registered Events: (none)
> > Number Of Arrays: 0
> > Number Of Components: 0
> > Number Of Tuples: 0
> > Copy Tuple Flags: ( 1 1 1 1 1 0 1 )
> > Interpolate Flags: ( 1 1 1 1 1 0 0 )
> > Pass Through Flags: ( 1 1 1 1 1 1 1 )
> > Scalars: (none)
> > Vectors: (none)
> > Normals: (none)
> > TCoords: (none)
> > Tensors: (none)
> > GlobalIds: (none)
> > PedigreeIds: (none)
> >
> > So have i actually loaded the image data and is image_cells empty?
> >
> > Thanks for your help
> >
> > Peter
> >
> > On Tuesday 30 June 2009 10:35:53 am Eric E. Monson wrote:
> >> 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
> >
> > _______________________________________________
> > 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
--
Peter M. Bloomfield
Physicist,
PET Centre,
Centre for Addiction and Mental Health,
250 College St.,
Toronto, Ontario,
Canada M5T 1R8
Tel: 416 535 8501 Ext. 4243
More information about the vtkusers
mailing list