def parse_xml_file(file): # Create an XML Tree, use own method to remove namespaces root = xmlHelper.create_xml_tree(file) # IPython.embed() # Find the Study and Series IDs if possible study_uid = xmlHelper.get_study_uid(root) series_uid = xmlHelper.get_series_uid(root) print("Parsing %s" % file) print("Get study_uid %s and series_uid %s" % (study_uid, series_uid)) if study_uid is None: write_error("Failed to find Study UID: " + file) return # Find the DICOMS matching the study and series ID. # Assuming that all DICOMS to a study/series ID are in one folder. dicom_path, no_of_dicoms = get_dicom_from_study_uid(study_uid, series_uid) if no_of_dicoms < 10: print(dicom_path) print("No DICOM's found for file:", file) return print(dicom_path) # IPython.embed() # Files are saved in a folder with the structure $PatientID/$StudyID/$SeriesID/$DicomName # Removing StudyID, SeriesID and DICOM-Name gives a patient ID --> StudyUID # long_patient_id=os.path.basename(os.path.dirname(os.path.dirname(os.path.dirname(dicom_path)))) patient_id = study_uid # For some patients, more than one scan is provided (for example due to multiple # time points). To ensure that each time point is only scanned one, an appendix # is added to the patient_id, ensuring that multiple time points can be selected. # for appendix in list_of_appendix: # target_path = os.path.join(path_to_nrrds, patient_id+appendix) # if not os.path.exists(target_path): appendix = file[-5] patient_id = patient_id + appendix print(patient_id) # break # Create Nrrd files from DICOMS and reading spacing and orgiin. nrrd_file = create_nrrd_from_dicoms(dicom_path, patient_id) spacing, origin = get_spacing_and_origin(nrrd_file) # Creating multiple planar figures for each reading session. # Each session represents the result of an different expert # Each session gets an session ID that is unique for the given patient ID # Same session ids for differnt patients do not necessarily correspond to the same expert. print("Creating Planar Figure") session_id = 0 for session in root.iter('readingSession'): create_planarfigure_for_session(session, spacing, origin, patient_id, session_id) session_id = session_id + 1 convert_planar_figures_to_masks(nrrd_file, patient_id) print("Merging Planar Figures") merge_planar_figures_per_nodule(nrrd_file, patient_id)
def parse_xml_file(file): # Create an XML Tree, use own method to remove namespaces root=xmlHelper.create_xml_tree(file) # IPython.embed() # Find the Study and Series IDs if possible study_uid=xmlHelper.get_study_uid(root) series_uid=xmlHelper.get_series_uid(root) print("Parsing %s" % file) print("Get study_uid %s and series_uid %s" % (study_uid, series_uid)) if study_uid is None: write_error("Failed to find Study UID: " + file) return # Find the DICOMS matching the study and series ID. # Assuming that all DICOMS to a study/series ID are in one folder. dicom_path, no_of_dicoms=get_dicom_from_study_uid(study_uid, series_uid) if no_of_dicoms < 10: print(dicom_path) print("No DICOM's found for file:",file) return print(dicom_path) # IPython.embed() # Files are saved in a folder with the structure $PatientID/$StudyID/$SeriesID/$DicomName # Removing StudyID, SeriesID and DICOM-Name gives a patient ID --> StudyUID # long_patient_id=os.path.basename(os.path.dirname(os.path.dirname(os.path.dirname(dicom_path)))) patient_id=study_uid # For some patients, more than one scan is provided (for example due to multiple # time points). To ensure that each time point is only scanned one, an appendix # is added to the patient_id, ensuring that multiple time points can be selected. # for appendix in list_of_appendix: # target_path = os.path.join(path_to_nrrds, patient_id+appendix) # if not os.path.exists(target_path): appendix=file[-5] patient_id =patient_id+appendix print(patient_id) # break # Create Nrrd files from DICOMS and reading spacing and orgiin. nrrd_file=create_nrrd_from_dicoms(dicom_path, patient_id)