Since PyRadiomics does not support DICOM-RTSTRUCT as input mask, I am trying to convert the files to labelmaps (.nrrd files). I have more than 100 files, so I was hoping to do this using a batch processing script. I found the BatchStructureSetConversion.py-file and tried the following:
However, this produces only one .nrrd file (size: 9x10x12), and the size/dimensions does not correspond to that of the PET images…
My input folder contains one subfolder for each patient where the PET DICOM-RT files and the DICOM-RTSTRUCT file are stored together (data from the MICCAI 2018 PET Radiomics Challenge). Could the problem be the folder structure or the file types? I am really stuck on this problem and any help would be much appreciated!
I assume you are talking about this script, right? Since this is public data, it would be great if you can set up a simple test case that’s easy to reproduce and file an issue.
Ideally your test case should automatically download the data files to reproduce the issue, but if that’s not feasible for you at least include links to the data and the specific versions of the code you are using and the exact steps to reproduce.
Thank you so much for the quick reply! That’s the script, yes.
I’m sorry but I’m very new to this and I don’t know how to set up that type of test case. I have downloaded a folder (named Training) containing a number of subfolders (one for each patient) where the PET slices and the segmentation contour data (.DCM file) are stored together. I’m trying to obtain a labelmap/binary segmentation mask for each patient.
When I run the script on a subset of 3 patients (HN-MICCAI2018-0002, HN-MICCAI2018-0004 and HN-MICCAI2018-0005) I get the following output (in addition to one .nrrd file):
Import DICOM data from /Users/stine/PycharmProjects/radiomics/data/PET/TrainingSUB
Switching to temporary DICOM database: /var/folders/1p/dw77r3v93yvbpqkp6vj9wtnm0000gn/T/Slicer-stine/20181105_185446_TempDICOMDatabase
Original DICOM database: /var/folders/1p/dw77r3v93yvbpqkp6vj9wtnm0000gn/T/Slicer-stine/20181105_184533_TempDICOMDatabase
Failed to obtain reference to ‘qSlicerMainWindow’
Failed to obtain reference to ‘qSlicerMainWindow’
QSqlDatabasePrivate::removeDatabase: connection ‘SLICER’ is still in use, all queries will cease to work.
QSqlDatabasePrivate::addDatabase: duplicate connection name ‘SLICER’, old connection removed.
TagCacheDatabase adding table
QSqlDatabasePrivate::removeDatabase: connection ‘SLICER’ is still in use, all queries will cease to work.
QSqlDatabasePrivate::addDatabase: duplicate connection name ‘SLICER’, old connection removed.
QSqlDatabasePrivate::removeDatabase: connection ‘SLICER’ is still in use, all queries will cease to work.
QSqlDatabasePrivate::addDatabase: duplicate connection name ‘SLICER’, old connection removed.
Failed to obtain reference to ‘qSlicerMainWindow’
Could not find main window
Could not find moduleSelector in the main window
E: DcmElement: CommandField (0000,0100) larger (828667202) than remaining bytes in file
Could not load “/Users/stine/PycharmProjects/radiomics/data/PET/TrainingSUB/.DS_Store”
DCMTK says: I/O suspension or premature end of stream
Could not read DICOM file:/Users/stine/PycharmProjects/radiomics/data/PET/TrainingSUB/.DS_Store
New patient inserted: 1
New patient inserted as : 1
Need to insert new study: “1.3.6.1.4.1.14519.5.2.1.1707.8040.916101888211223106723732084398”
Study Added
Need to insert new series: “1.3.6.1.4.1.14519.5.2.1.1707.8040.276182720375307817025066820423”
Series Added
E: DcmElement: CommandField (0000,0100) larger (828667202) than remaining bytes in file
Could not load “/Users/stine/PycharmProjects/radiomics/data/PET/TrainingSUB/HN-MICCAI2018-0002/.DS_Store”
DCMTK says: I/O suspension or premature end of stream
Could not read DICOM file:/Users/stine/PycharmProjects/radiomics/data/PET/TrainingSUB/HN-MICCAI2018-0002/.DS_Store
New patient inserted: 2
New patient inserted as : 2
Need to insert new series: “1.2.276.0.7230010.3.1.4.4252153939.211348.1528745918.141”
Series Added
Found patient in the database as UId: 1
Used existing series: “1.3.6.1.4.1.14519.5.2.1.1707.8040.276182720375307817025066820423”
Series Added
Used existing series: “1.3.6.1.4.1.14519.5.2.1.1707.8040.276182720375307817025066820423”
Series Added
Used existing series: “1.3.6.1.4.1.14519.5.2.1.1707.8040.276182720375307817025066820423”
Series Added
Used existing series: “1.3.6.1.4.1.14519.5.2.1.1707.8040.276182720375307817025066820423”
Series Added
Used existing series: “1.3.6.1.4.1.14519.5.2.1.1707.8040.276182720375307817025066820423”
Series Added
Used existing series: “1.3.6.1.4.1.14519.5.2.1.1707.8040.276182720375307817025066820423”
Series Added
Used existing series: “1.3.6.1.4.1.14519.5.2.1.1707.8040.276182720375307817025066820423”
Series Added
Used existing series: “1.3.6.1.4.1.14519.5.2.1.1707.8040.276182720375307817025066820423”
Series Added
Used existing series: “1.3.6.1.4.1.14519.5.2.1.1707.8040.276182720375307817025066820423”
Series Added
Used existing series: “1.3.6.1.4.1.14519.5.2.1.1707.8040.276182720375307817025066820423”
Series Added
Used existing series: “1.3.6.1.4.1.14519.5.2.1.1707.8040.276182720375307817025066820423”
Series Added
Used existing series: “1.3.6.1.4.1.14519.5.2.1.1707.8040.276182720375307817025066820423”
Series Added
Used existing series: “1.3.6.1.4.1.14519.5.2.1.1707.8040.276182720375307817025066820423”
Series Added
Used existing series: “1.3.6.1.4.1.14519.5.2.1.1707.8040.276182720375307817025066820423”
Series Added
Used existing series: “1.3.6.1.4.1.14519.5.2.1.1707.8040.276182720375307817025066820423”
Series Added
Used existing series: “1.3.6.1.4.1.14519.5.2.1.1707.8040.276182720375307817025066820423”
Series Added
Used existing series: “1.3.6.1.4.1.14519.5.2.1.1707.8040.276182720375307817025066820423”
Series Added
Used existing series: “1.3.6.1.4.1.14519.5.2.1.1707.8040.276182720375307817025066820423”
Series Added
Used existing series: “1.3.6.1.4.1.14519.5.2.1.1707.8040.276182720375307817025066820423”
Series Added
Used existing series: “1.3.6.1.4.1.14519.5.2.1.1707.8040.276182720375307817025066820423”
Series Added
Used existing series: “1.3.6.1.4.1.14519.5.2.1.1707.8040.276182720375307817025066820423”
Series Added
Used existing series: “1.3.6.1.4.1.14519.5.2.1.1707.8040.276182720375307817025066820423”
Series Added
Used existing series: “1.3.6.1.4.1.14519.5.2.1.1707.8040.276182720375307817025066820423”
Series Added
Used existing series: “1.3.6.1.4.1.14519.5.2.1.1707.8040.276182720375307817025066820423”
Series Added
Used existing series: “1.3.6.1.4.1.14519.5.2.1.1707.8040.276182720375307817025066820423”
Series Added
Used existing series: “1.3.6.1.4.1.14519.5.2.1.1707.8040.276182720375307817025066820423”
Series Added
Used existing series: “1.3.6.1.4.1.14519.5.2.1.1707.8040.276182720375307817025066820423”
Series Added
Used existing series: “1.3.6.1.4.1.14519.5.2.1.1707.8040.276182720375307817025066820423”
Series Added
Used existing series: “1.3.6.1.4.1.14519.5.2.1.1707.8040.276182720375307817025066820423”
Series Added
Used existing series: “1.3.6.1.4.1.14519.5.2.1.1707.8040.276182720375307817025066820423”
Series Added
Used existing series: “1.3.6.1.4.1.14519.5.2.1.1707.8040.276182720375307817025066820423”
Series Added
Used existing series: “1.3.6.1.4.1.14519.5.2.1.1707.8040.276182720375307817025066820423”
Series Added
Used existing series: “1.3.6.1.4.1.14519.5.2.1.1707.8040.276182720375307817025066820423”
Series Added
Used existing series: “1.3.6.1.4.1.14519.5.2.1.1707.8040.276182720375307817025066820423”
Series Added
New patient inserted: 3
New patient inserted as : 3
Need to insert new study: “1.3.6.1.4.1.14519.5.2.1.1707.8040.338589861935722567365981799683”
Study Added
Need to insert new series: “1.3.6.1.4.1.14519.5.2.1.1707.8040.397286022729450579606108175191”
Series Added
New patient inserted: 4
New patient inserted as : 4
Need to insert new series: “1.2.276.0.7230010.3.1.4.4252153939.211348.1528746083.145”
Series Added
Found patient in the database as UId: 3
Used existing series: “1.3.6.1.4.1.14519.5.2.1.1707.8040.397286022729450579606108175191”
Series Added
Used existing series: “1.3.6.1.4.1.14519.5.2.1.1707.8040.397286022729450579606108175191”
Series Added
Used existing series: “1.3.6.1.4.1.14519.5.2.1.1707.8040.397286022729450579606108175191”
Series Added
Used existing series: “1.3.6.1.4.1.14519.5.2.1.1707.8040.397286022729450579606108175191”
Series Added
Used existing series: “1.3.6.1.4.1.14519.5.2.1.1707.8040.397286022729450579606108175191”
Series Added
Used existing series: “1.3.6.1.4.1.14519.5.2.1.1707.8040.397286022729450579606108175191”
Series Added
Used existing series: “1.3.6.1.4.1.14519.5.2.1.1707.8040.397286022729450579606108175191”
Series Added
Used existing series: “1.3.6.1.4.1.14519.5.2.1.1707.8040.397286022729450579606108175191”
Series Added
Used existing series: “1.3.6.1.4.1.14519.5.2.1.1707.8040.397286022729450579606108175191”
Series Added
Used existing series: “1.3.6.1.4.1.14519.5.2.1.1707.8040.397286022729450579606108175191”
Series Added
Used existing series: “1.3.6.1.4.1.14519.5.2.1.1707.8040.397286022729450579606108175191”
Series Added
Used existing series: “1.3.6.1.4.1.14519.5.2.1.1707.8040.397286022729450579606108175191”
Series Added
Used existing series: “1.3.6.1.4.1.14519.5.2.1.1707.8040.397286022729450579606108175191”
Series Added
Used existing series: “1.3.6.1.4.1.14519.5.2.1.1707.8040.397286022729450579606108175191”
Series Added
Used existing series: “1.3.6.1.4.1.14519.5.2.1.1707.8040.397286022729450579606108175191”
Series Added
Used existing series: “1.3.6.1.4.1.14519.5.2.1.1707.8040.397286022729450579606108175191”
Series Added
Used existing series: “1.3.6.1.4.1.14519.5.2.1.1707.8040.397286022729450579606108175191”
Series Added
Used existing series: “1.3.6.1.4.1.14519.5.2.1.1707.8040.397286022729450579606108175191”
Series Added
Used existing series: “1.3.6.1.4.1.14519.5.2.1.1707.8040.397286022729450579606108175191”
Series Added
Used existing series: “1.3.6.1.4.1.14519.5.2.1.1707.8040.397286022729450579606108175191”
Series Added
Used existing series: “1.3.6.1.4.1.14519.5.2.1.1707.8040.397286022729450579606108175191”
Series Added
Used existing series: “1.3.6.1.4.1.14519.5.2.1.1707.8040.397286022729450579606108175191”
Series Added
Used existing series: “1.3.6.1.4.1.14519.5.2.1.1707.8040.397286022729450579606108175191”
Series Added
Used existing series: “1.3.6.1.4.1.14519.5.2.1.1707.8040.397286022729450579606108175191”
Series Added
Used existing series: “1.3.6.1.4.1.14519.5.2.1.1707.8040.397286022729450579606108175191”
Series Added
New patient inserted: 5
New patient inserted as : 5
Need to insert new study: “1.3.6.1.4.1.14519.5.2.1.1707.8040.563642908585179401817164347275”
Study Added
Need to insert new series: “1.3.6.1.4.1.14519.5.2.1.1707.8040.338955629943308958335236734341”
Series Added
New patient inserted: 6
New patient inserted as : 6
Need to insert new series: “1.2.276.0.7230010.3.1.4.4252153939.211348.1528746059.143”
Series Added
Found patient in the database as UId: 5
Used existing series: “1.3.6.1.4.1.14519.5.2.1.1707.8040.338955629943308958335236734341”
Series Added
Used existing series: “1.3.6.1.4.1.14519.5.2.1.1707.8040.338955629943308958335236734341”
Series Added
Used existing series: “1.3.6.1.4.1.14519.5.2.1.1707.8040.338955629943308958335236734341”
Series Added
Used existing series: “1.3.6.1.4.1.14519.5.2.1.1707.8040.338955629943308958335236734341”
Series Added
Used existing series: “1.3.6.1.4.1.14519.5.2.1.1707.8040.338955629943308958335236734341”
Series Added
Used existing series: “1.3.6.1.4.1.14519.5.2.1.1707.8040.338955629943308958335236734341”
Series Added
Used existing series: “1.3.6.1.4.1.14519.5.2.1.1707.8040.338955629943308958335236734341”
Series Added
Used existing series: “1.3.6.1.4.1.14519.5.2.1.1707.8040.338955629943308958335236734341”
Series Added
Used existing series: “1.3.6.1.4.1.14519.5.2.1.1707.8040.338955629943308958335236734341”
Series Added
Used existing series: “1.3.6.1.4.1.14519.5.2.1.1707.8040.338955629943308958335236734341”
Series Added
Used existing series: “1.3.6.1.4.1.14519.5.2.1.1707.8040.338955629943308958335236734341”
Series Added
Used existing series: “1.3.6.1.4.1.14519.5.2.1.1707.8040.338955629943308958335236734341”
Series Added
Used existing series: “1.3.6.1.4.1.14519.5.2.1.1707.8040.338955629943308958335236734341”
Series Added
Used existing series: “1.3.6.1.4.1.14519.5.2.1.1707.8040.338955629943308958335236734341”
Series Added
Used existing series: “1.3.6.1.4.1.14519.5.2.1.1707.8040.338955629943308958335236734341”
Series Added
Used existing series: “1.3.6.1.4.1.14519.5.2.1.1707.8040.338955629943308958335236734341”
Series Added
Used existing series: “1.3.6.1.4.1.14519.5.2.1.1707.8040.338955629943308958335236734341”
Series Added
Used existing series: “1.3.6.1.4.1.14519.5.2.1.1707.8040.338955629943308958335236734341”
Series Added
Used existing series: “1.3.6.1.4.1.14519.5.2.1.1707.8040.338955629943308958335236734341”
Series Added
Used existing series: “1.3.6.1.4.1.14519.5.2.1.1707.8040.338955629943308958335236734341”
Series Added
Used existing series: “1.3.6.1.4.1.14519.5.2.1.1707.8040.338955629943308958335236734341”
Series Added
Used existing series: “1.3.6.1.4.1.14519.5.2.1.1707.8040.338955629943308958335236734341”
Series Added
Used existing series: “1.3.6.1.4.1.14519.5.2.1.1707.8040.338955629943308958335236734341”
Series Added
Used existing series: “1.3.6.1.4.1.14519.5.2.1.1707.8040.338955629943308958335236734341”
Series Added
Used existing series: “1.3.6.1.4.1.14519.5.2.1.1707.8040.338955629943308958335236734341”
Series Added
Used existing series: “1.3.6.1.4.1.14519.5.2.1.1707.8040.338955629943308958335236734341”
Series Added
Used existing series: “1.3.6.1.4.1.14519.5.2.1.1707.8040.338955629943308958335236734341”
Series Added
Used existing series: “1.3.6.1.4.1.14519.5.2.1.1707.8040.338955629943308958335236734341”
Series Added
Used existing series: “1.3.6.1.4.1.14519.5.2.1.1707.8040.338955629943308958335236734341”
Series Added
Used existing series: “1.3.6.1.4.1.14519.5.2.1.1707.8040.338955629943308958335236734341”
Series Added
Used existing series: “1.3.6.1.4.1.14519.5.2.1.1707.8040.338955629943308958335236734341”
Series Added
Used existing series: “1.3.6.1.4.1.14519.5.2.1.1707.8040.338955629943308958335236734341”
Series Added
Used existing series: “1.3.6.1.4.1.14519.5.2.1.1707.8040.338955629943308958335236734341”
Series Added
Used existing series: “1.3.6.1.4.1.14519.5.2.1.1707.8040.338955629943308958335236734341”
Series Added
Used existing series: “1.3.6.1.4.1.14519.5.2.1.1707.8040.338955629943308958335236734341”
Series Added
Used existing series: “1.3.6.1.4.1.14519.5.2.1.1707.8040.338955629943308958335236734341”
Series Added
Used existing series: “1.3.6.1.4.1.14519.5.2.1.1707.8040.338955629943308958335236734341”
Series Added
Used existing series: “1.3.6.1.4.1.14519.5.2.1.1707.8040.338955629943308958335236734341”
Series Added
Used existing series: “1.3.6.1.4.1.14519.5.2.1.1707.8040.338955629943308958335236734341”
Series Added
Used existing series: “1.3.6.1.4.1.14519.5.2.1.1707.8040.338955629943308958335236734341”
Series Added
Used existing series: “1.3.6.1.4.1.14519.5.2.1.1707.8040.338955629943308958335236734341”
Series Added
Used existing series: “1.3.6.1.4.1.14519.5.2.1.1707.8040.338955629943308958335236734341”
Series Added
Used existing series: “1.3.6.1.4.1.14519.5.2.1.1707.8040.338955629943308958335236734341”
Series Added
Used existing series: “1.3.6.1.4.1.14519.5.2.1.1707.8040.338955629943308958335236734341”
Series Added
Used existing series: “1.3.6.1.4.1.14519.5.2.1.1707.8040.338955629943308958335236734341”
Series Added
Used existing series: “1.3.6.1.4.1.14519.5.2.1.1707.8040.338955629943308958335236734341”
Series Added
Used existing series: “1.3.6.1.4.1.14519.5.2.1.1707.8040.338955629943308958335236734341”
Series Added
Used existing series: “1.3.6.1.4.1.14519.5.2.1.1707.8040.338955629943308958335236734341”
Series Added
Used existing series: “1.3.6.1.4.1.14519.5.2.1.1707.8040.338955629943308958335236734341”
Series Added
Used existing series: “1.3.6.1.4.1.14519.5.2.1.1707.8040.338955629943308958335236734341”
Series Added
Used existing series: “1.3.6.1.4.1.14519.5.2.1.1707.8040.338955629943308958335236734341”
Series Added
“DICOM indexer has successfully processed 298 files [1.90s]”
Load first patient into Slicer
reg inside examine
W: OperatorsName (0008,1070) absent in RTSeriesModule (type 2)
reg inside examine
W: OperatorsName (0008,1070) absent in RTSeriesModule (type 2)
Loading series ‘1: RTSTRUCT: MICCAI2018’ from file ‘/Users/stine/PycharmProjects/radiomics/data/PET/TrainingSUB/HN-MICCAI2018-0002/MICCAI2018.DCM’
W: OperatorsName (0008,1070) absent in RTSeriesModule (type 2)
Loading with imageIOName: GDCM
Window/level found in DICOM tags (center=6857.729132, width=13715.458265) has been applied to volume 65690: LOR-RAMLA
Irregular volume geometry detected, but maximum error non-zero but is within tolerance (maximum error of 8.00488e-06 mm, tolerance threshold is 0.001 mm).
Convert loaded structure set to labelmap volumes
Converting structure set 1: RTSTRUCT: MICCAI2018
Save labelmaps to directory /Users/stine/PycharmProjects/radiomics/data/PET/TrainingNRRD
Saving structure 1: RTSTRUCT: MICCAI2018_GTVp
to file 1_RTSTRUCT_MICCAI2018_GTVp.nrrd
Generic Warning: In /Volumes/Dashboards/Stable/Slicer-4100/Libs/MRML/Core/vtkDataFileFormatHelper.cxx, line 237
vtkDataFileFormatHelper::GetFileExtensionFromFormatString: please update deprecated extension-only format specifier to ‘File format name (.ext)’ format! Current format string: .nrrd
I’m thinking that the folder structure and/or the file types might be the problem. What does the script expect? How should the data files be arranged within the input folder, and what format should the PET images have?
The folder you specify simply needs to contain DICOM data. The script creates a database there, imports all the DICOM in the folder, and processes each patient one by one. In each patient it will iterate through the structure sets, and within those the structures, and saves each as a labelmap with the geometry of the referenced anatomical image.
Unfortunately the log shows nothing interesting.
What happens if you:
Open Slicer, open the DICOM browser
Import one of the studies you want to convert
Load the study to Slicer (make sure you have SlicerRT extension installed)
Go to Segmentations module
Open the section called Export/import models and labelmaps
Open Advanced, make sure the reference volume is the anatomical image you want (let us know if it’s not the proper one by default)
Click Export
Show the resulting labelmap in the slice views. If you’re not sure how to do it then go to the Data module and click the show icon in the row of the labelmap ( called [StructureSetName]-label)
Okey, but the input folder can contain subfolders for each patient?
The procedure described above produces a labelmap that looks good and the default reference volume is correct (there is only one option except for the “None”-option).
I don’t think it matters how the folders are arranged within the input folder. As long as it can be imported into a DICOM database, it’s fine.
Batch Structure Set Conversion works basically the same way the steps above that produced a good labelmap. So not sure what goes wrong with your data without seeing it.