I’m currently an MS student in Medical Physics and I have a great need to be able to overlay an isodose distribution from an RTDOSE file onto a CT image from a .dcm file set.
I’ve managed to extract the image and the dose pixel arrays myself using pydicom and dicom_numpy, but the two arrays are not the same size! So, if I overlay the two together, the dose will not be in the correct position based on what the Elekta Gamma Plan software exported it as.
I’ve played around with slicerrt and it obviously is able to do this even though the arrays are not the same size. However, I think I cannot export the numerical data when using slicerrt…I can only scroll through and view it as an image. What section of the code has the algorithm for overlaying the RTDOSE to an image?
If you only want to use Slicer’s GUI for a few cases and do the rest of your work in batch mode without GUI that i fine, too: you can install any Python packages and run any scripts in Slicer’s Python environment. Slicer even provides a Jupyter kernel so you can access it from Jupyter notebooks.
I am planning to overlay the rt dose file with the CT images to feed both arrays to a neural network; however, when I try to import the rt dose file as dicom array, I will get something like this: 135,98,115.
Additionally, when I import the CT images as an array I will get the following array: 70,512,512
As you can see in these array shapes, neither the slice number nor the image dimension are the same, but I found out that slicerrt has the ability to overlay RT dose file with the CT images in the correct position.
I am writing to ask how this module can correct the position of RT dose files.
I would appreciate it if you could please send me any python script of slicerrt which you know of.
Did you get any clue about my question that can help me?
I really need to to overlay the rt dose file with the CT images to feed both arrays to a neural network with the same shape, any help from you or others will be appreciated,
Can you please describe how you loaded the DICOM-RT dose? Just to make sure that you load it the way it is intended, because then matching overlay should be automatic.
Dimensions are usually very different, so that’s normal.
I import ct images and rt dose file into 3dslicer and then export them as nrrd file,
when I read them with pynrrd library I will confront with issue that I mentioned before.
I used the dicom button on the top left and then in the new window I use import button to import image directory then I click on patient name and select on meta data such as rt dose, rt struc and rt plan file with ct images then I click on load button,after that I click on save button and export ct images and rt dose file as nrrd format, when I open these files with python I will get different array shape
Thanks! The method of loading seems correct. Before you save it to nrrd, I assume the CT and the dose do not align? Can you make screenshots of the Volume information section in the Volumes module for both images?
Thanks! Just trying to double check they don’t overlap. I created two volumes with exactly the same geometry as what you show in the screenshots, and they don’t match exactly, although the dose volume is inside the CT, which may be valid:
This is quite unusual if you exported them from a treatment planning system. At this point (if the dose is indeed smaller than what it’s supposed to be) it is up to you to manually fix the dose volume’s geometry so that it matches the CT.
You can use the Resample Scalar Volumes module (the same one I used to create these two volumes above).
I got the same array shape via resample module, but there is another problem, when I compared new rt dose file with the original, I noticed that there is difference between resample module output and the original file, it seems that they are not the same,
Values in the original and resampled dose volumes cannot be the same as you resampled its voxels. If that’s a problem then instead you can resample the CT volume using the dose volume as reference.
I got the same problem. I try to export RTDOSE and CT with python script but the array of the two are not the same size. I also check by manual export and it not work. Can you explain more about “Resample Scalar Volumes module”?, I check in “Python scripting doc” and got no detaill. This is My script.
Thank you.
loadedNodeIDs = [] # this list will contain the list of all loaded node IDs
from DICOMLib import DICOMUtils
def pathFromNode(node):
storageNode=node.GetStorageNode()
if storageNode is not None: # loaded via drag-drop
filepath=storageNode.GetFullNameFromFileName()
else: # loaded via DICOM browser
instanceUIDs=node.GetAttribute('DICOM.instanceUIDs').split()
filepath=slicer.dicomDatabase.fileForInstance(instUids[0])
return filepath
with DICOMUtils.TemporaryDICOMDatabase() as db:
DICOMUtils.importDicom(dicomDataDir, db)
patientUIDs = db.patients()
for patientUID in patientUIDs:
studyList=db.studiesForPatient(patientUID)
for study in studyList:
node = slicer.util.getNode(study)
slicer.util.saveNode(node , '/tmp/output.nrrd')