<html><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">Hello,<div><br></div><div>You can manually create a vtkImageData and then you have a couple of options for populating the array data values (and I am sure there are more that I don't know). Here is an example where "chem" is a 3d numpy array that I'm grabbing from an HDF5 file (I also needed to swap the X and Z axes in this case"):</div><div><br></div><div><div># ----</div><div>import vtk</div><div>import numpy as N</div><div># ...code omitted...</div><div>gridSpacing = 6.25</div><div># reading chemical array and stripping off outer zero/ghost planes</div><div>chem = h5file.getNode(snapGroup._v_pathname + '/' + snapName + '/' + chemArrayNames[cc]).read()[1:-1,1:-1,1:-1]</div><div>sideDim = chem.shape[0]</div><div>numPts = chem.size</div><div><br></div><div>vol = vtk.vtkImageData()</div><div>vol.SetDimensions(sideDim,sideDim,sideDim)</div><div>vol.SetOrigin(0,0,0)</div><div>vol.SetSpacing(gridSpacing,gridSpacing,gridSpacing)</div><div><br></div><div>sc = vtk.vtkFloatArray()</div><div>sc.SetNumberOfValues(numPts)</div><div>sc.SetNumberOfComponents(1)</div><div>sc.SetName('tnf')</div><div><br></div><div>for ii,tmp in enumerate(N.ravel(chem.swapaxes(0,2))):</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>sc.SetValue(ii,tmp)</div><div><br></div><div>vol.GetPointData().SetScalars(sc)</div><div><div># ----</div><div><br></div></div><div>Instead of creating a vtkFloatArray and then manually populating its entries, you can also use the VTK numpy_support module to create one directly from a numpy array:</div><div><br></div><div># ----</div><div>import vtk<br>import vtk.util.numpy_support as VN<br></div><div>import numpy as N</div><div><br></div><div>x = N.random.random(10)</div><div>y = VN.numpy_to_vtk(x)</div><div><div># ----</div><div><br></div></div><div>and y is now a vtkDoubleArray containing the 10 random values, and in principle could be used in a SetScalars(y) or AddArray(y) if it was the correct size.</div><div><br></div><div>Talk to you later,</div><div>-Eric</div><div><br></div></div><div><div apple-content-edited="true"> <span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0; "><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div>------------------------------------------------------</div><div>Eric E Monson</div><div>Duke Visualization Technology Group</div><div><span class="Apple-style-span" style="font-size: medium;"><br></span></div></div></span> </div><br><div><div>On Jun 30, 2009, at 11:40 AM, Lic. José M. Rodriguez Bacallao wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div>as I said before, until now, I have been using vtkGDCMImageReader but<br>now I wan't to use pydicom, this is how I read the image with pydicom:<br><br>import dicom<br>dataset = dicom.read_file('./path/to/file.dcm')<br>pixel_array = ds.pixel_array #numpy array<br>pixel_data = ds.PixelData #string of bytes<br><br>question is: How do I visualize any of these with vtk to see a dicom image?<font class="Apple-style-span" color="#000000"><font class="Apple-style-span" color="#144FAE"><br></font></font></div></blockquote></div></div></body></html>