e0404/matRad

Dicom import CT and structures

gleesoi opened this issue · 11 comments

hi i am new to using this code and would like some inoput please to get my going. thanks!

i cant import ct dicom and contours in GUI or code (these are dicom files exported from Raystation). GUI import button remains greyed out. my folder contains all the dicom ct slices and a single structure file.
GUI - when browsed to folder - no dicom files appears in GUI. then i click on CT series number and back to CT radio button and they appear with UIDS. import button greyed out cant import.
image

CODE: i ran new bits below

image
image
image

Hi @gleesoi,
unfortunately using the functions from code is not very intuitive at the moment, so let's first try to find out why the GUI is not working for you.

  • Which Matlab version and operating system are you using?
  • Which Branch are you using if not the master branch? Or are you using a specific release?
  • In the code, the import button is theoretically activated when clicking in the List-Boxes (on the Patient name, on the UID, etc.). How you describe the behavior it seems to me like there is an error somewhere. Does the Matlab command window show an error during handling the GUI?
  • Can you try it with a path that has no spaces?

Now, if nothing helps, you can also try it by code:
I would suggest to use the ´matRad_importDicom´ function (function [ct,cst,pln,stf,resultGUI] = matRad_importDicom(files, dicomMetaBool)

The problem here is how to setup the files , as they are a Matlab ´struct´ with the fields

  • files.ct - contains a cell array of files belonging to the ct
  • files.rtss - file of the RTStruct
  • files.resx, files.resy, files.resz. The resolution needs to be set, unfortunately, manually, in this field, even if you want to use the original ct resolution (in this case just put the exact values in here from the dicom tags PixelSpacing and SliceThickness, you can obtain them from within Matlab via dicominfo() on a ct file.

Thanks for quick response! i use windows 10, master branch v2.10.1, matlab r2019b. it looks like it needed me to simply click onto the patient ID to enable import function button to b live and work. this wasn't clear to me as it appears as if it was already selected in blue :) The data appears to have imported in the command window below
image
however nothing updates in the GUI for me to see the ct/structures? is there something else i must run to see this?

my research aim is to make a script to auto import and plan - the import dicom files code didn't work for me for all the files at same time but i was able to import the ct first (and get resolution via dicominfo as suggested), then rtss and then make the cst structure separately with the code bits. i will continue on and see how i go. it might be useful to have an example script using the [matRad_importDicom.m]. thanks for your assistance.

Yes I agree that the function arguments are not well explained, and I realized I forgot a structure field in my previous answer.
Here's a code example that also uses matRad_scanDicomImportFolder to get the files automatically from a folder in one go:

matRad_rc %Execute in base folder of matRad

[allfiles,patients] = matRad_scanDicomImportFolder("C:\PathToFolder"); %MatRad will also be able to separate multiple patients, but this example will only work if there's only a single patient in the folder.
ctFiles = strcmp(allfiles(:,2),'CT');
rtssFiles = strcmpi(allfiles(:,2),'rtstruct'); %note we can have multiple RT structure sets, matRad will always import the first it finds

importFiles.ct = allfiles(ctFiles,1);%All CT slice filepaths stored in a cell array like {'CTSlice1.dcm','CTSlice2.dcm'}; 
importFiles.rtss = allfiles(rtssFiles,1); %will also be a cell array like {'RTStruct.dcm'}; 

%Use the first ct file to get resolution
dcmInfoCt = dicominfo(importFiles.ct{1}); 
importFiles.resx = dcmInfoCt.PixelSpacing(1);
importFiles.resy = dcmInfoCt.PixelSpacing(2);
importFiles.resz = dcmInfoCt.SliceThickness; %some CT dicoms do not follow the standard and use SpacingBetweenSlices

%We need to set one more variable I forgot to mention above
importFiles.useDoseGrid = false;

[ct,cst] = matRad_importDicom(importFiles);

%Now, after starting the GUI / clicking Refresh, the important patient should show after some precomputations for display
matRadGUI

%Optional saving, we tend to force v7 for compatibility. We use the patient name from the importScan here to identify
save('-v7',['importedPatient' patients{1} '.mat'],'ct','cst');

Regarding the question of the GUI not updating. Usually, at the end of the import, the dicom import GUI will ask you to save the imported dataset to a mat file. Do this and then load the mat file in Matlab / from the matRad GUI.

@amitantony It might make sense to refactor the matRad_scanDicomImportFolder to return a format compatible with matRad_importDicom. We could return a struct directly with fields according to the dicom file type, and if we detect multiple patients, we just return a struct array.
Could turn it into a comprehensive class like the DicomExporter at the same time.
What do you think?

i ran the code above trying to import all ct and rsst files but encountered and error and ended up with no ct or cst variables and gui didnt show anything after refresh. does something else need some change to function?thanks

image

Looks like the import in itself was successful but its throwing an error while saving the matRad structures. This functionality is being reviewed and refurbished.

For now as a "hack" solution, I would suggest setting a matlab break point at the this line (159) in 'matRad_importDicom', afterwhich you should see the ct and cst structures in the workspace variables that you can manually save as .mat files.

Ah I apologize, I think I used a version of the import on a different branch to develop my script, which had the saving already removed from the matRad_importDicom function (my script from above does the saving manually after the import).

Thus my alternate suggestion to the suggestion from @amitantony is to remove the saving part from the matRad_importDicom function, that is, delete these lines (152-165):

%% save ct, cst, pln, dose
matRadFileName = [files.ct{1,3} '.mat']; % use default from dicom
[FileName,PathName] = uiputfile('*','Save as...',matRadFileName);
if ischar(FileName)
% delete unnecessary variables
switch env
case 'MATLAB'
clearvars -except ct cst pln stf resultGUI FileName PathName;
case 'OCTAVE'
clear -x ct cst pln stf resultGUI FileName PathName;
end
% save all except FileName and PathName
save([PathName, FileName], '-regexp', '^(?!(FileName|PathName)$).','-v7.3');
end

The next version of matRad will do this differently.

thanks that did the job.

i am seeing an error bringing in the structures as per your code above on 6 cases from a total of 224 cases. see error below: i tried changing that to false also but didnt work. but when i import ct and structures using the separate scripts like matRad_importDicomRtss it works fine.

image

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

This issue was automatically closed because it has not seen any activity in four weeks. This happens usually when the issue has already been solved or it is no longer relevant. If this is not the case, feel free to reopen the issue.