Are you resampling dose to match the CT spacing?
I just wasn’t sure how you were going about getting these into the pixle-space, but I guess vtkGDCMImageReader does that internally.
If the FrameOfReferenceUIDs of the CT and the RT dose are the same, they both exist in the same coordinate system, if they don’t, you will have to register the dose to the CT somehow.
Because the resolution of the dose will generally be different than the CT a reasonable strategy is to loop through your CT voxels and use the position at the center of that voxel to sample into the RT Dose grid. When you sample into the RT Dose you may need to interpolate the actual dose value. That dose value determines your shading.
The other issue to be aware of is that the dose grid may not completely cover the CT image data. This is probably why the origins are different for your data.
-- Scott
From: vtkusers...@vtk.org [mailto:vtkusers...@vtk.org] On Behalf Of Jothy
Sent: Wednesday, February 23, 2011 11:38 AM
To: gdcm-developers; VTK Mailing List; itk;
python-...@googlegroups.com
import dicom as dcm
import numpy
import glob
For the DICOM RT dose dataset:
ds = dcm.read_file('rtdose.dcm')
rows = ds.Rows
columns = ds.Columns
pixel_spacing = ds.PixelSpacing
image_position = ds.ImagePositionPatient
x = numpy.arange(columns)*pixel_spacing[0] + image_position[0]
y = numpy.arange(rows)*pixel_spacing[1] + image_position[1]
z = numpy.array(ds.GridFrameOffsetVector) + image_position[2]
The coordinate of the first pixel in the numpy array for the dose is
then (x[0], y[0], z[0])
For the CT dataset:
I read in all the CT images for a directory:
images = {}
for file in glob.glob(dataset_dir+'*'):
ds = dcm.read_file(file)
# Check to see if it is an image file.
if ds.SOPClassUID == '1.2.840.10008.5.1.4.1.1.2':
#
# Add the image to the images dictionary based on its z
coordinate position.
#
images[ds.ImagePositionPatient[2]] = ds.pixel_array
else:
pass
# The ImagePositionPatient tag gives you the x,y,z coordinates of the
center of
# the first pixel. The slices are randomly accessed so we don't know
which one
# we have after looping through the CT slice so we will set the z
position after
# sorting the z coordinates below.
image_position = ds.ImagePositionPatient
# Construct the z coordinate array from the image index.
z = slices.keys()
z.sort()
ct_z = numpy.array(z)
image_position[2] = ct_z[0]
# The pixel spacing or planar resolution in the x and y directions.
ct_pixel_spacing = ds.PixelSpacing
# Verify z dimension spacing
b = ct_z[1:] - ct_z[0:-1]
z_spacing = 2.5 # Typical spacing for our institution
if b.min() == b.max():
z_spacing = b.max()
# Append z spacing so you have x,y,z spacing for the array.
ct_pixel_spacing.append(z_spacing)
# Build the z ordered 3D CT dataset array.
ct_array = np.array([slices[i] for i in z])
# Now construct the coordinate arrays
x = numpy.arange(ct_array.shape[2])*ct_pixel_spacing[0] + image_position[0]
y = numpy.arange(ct_array.shape[1])*ct_pixel_spacing[1] + image_position[1]
z = (numpy.arange(ct_array.shape[0])*z_spacing) + image_position[2]
The coordinate of the first pixel in the numpy array for the ct is then
(x[0], y[0], z[0])
These two datasets are now registered in the same coordinate space. If
you want to visualize them using VTK you need to transpose the numpy
arrays since VTK expects the increase in coordinates to be x, followed
by y followed by z while numpy has the opposite.
Thanks to Steve for helping me with this for the dose grid a few months
back. The CT stuff above is just an extension of what he shared with me.
The above code works for me using Mayavi which in turn uses VTK for the
visualization.
-Mike
What are the direction cosines?
There is a problem where VTK reinterprets the direction cosines to
change the directions of images produced by the dicom reader.
DICOM specifies that the image patient position is always the upper
left pixel (if you look at the image as a 2D image on a plane like a
monitor). VTK will take the direction cosine and potentially flip the
image along those cosines.
Mark
> ------------------------------------------------------------------------------
> Free Software Download: Index, Search & Analyze Logs and other IT data in
> Real-Time with Splunk. Collect, index and harness all the fast moving IT
> data
> generated by your applications, servers and devices whether physical,
> virtual
> or in the cloud. Deliver compliance at lower cost and gain new business
> insights. http://p.sf.net/sfu/splunk-dev2dev
> _______________________________________________
> Gdcm-developers mailing list
> Gdcm-de...@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/gdcm-developers
>
>
_____________________________________
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.html
Please keep messages on-topic and check the ITK FAQ at:
http://www.itk.org/Wiki/ITK_FAQ
Follow this link to subscribe/unsubscribe:
The only issue I can think of is that the incorrect rendering has
something to do with the pixel spacing of [1.074, 1.074] vs [2.5, 2.5]
for the dose grid and the CT data respectively along with an incorrect
origin. The top right corner of the dose plane is almost at the center
of the CT image, which needs to be transposed. The same test data
renders correctly in dicompyler.
Adit
> --
> Python in Medical Physics resources can be found at:
> https://sites.google.com/site/pythonmedphys/
>
--
You received this message because you are subscribed to the Google Groups "Python in Medical Physics" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python-medphys+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python-medphys/eb2cff38-f466-43fb-bd1c-43b1c468029dn%40googlegroups.com.