From 5a5afbc02d506d6a8e3cfaeea65c08bd9ef5b351 Mon Sep 17 00:00:00 2001 From: Chenjie Xu Date: Sat, 1 Oct 2022 22:32:24 +0800 Subject: [PATCH 1/2] Fix AttributeError If attributes Modality and ImageType don't exist in dicom file, AttributeError will occur. Using get as in https://github.com/pydicom/pydicom/issues/781 --- dicom2nifti/convert_generic.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dicom2nifti/convert_generic.py b/dicom2nifti/convert_generic.py index 362c672..3b4918e 100644 --- a/dicom2nifti/convert_generic.py +++ b/dicom2nifti/convert_generic.py @@ -214,10 +214,10 @@ def remove_localizers_by_imagetype(dicoms): # Loop overall files and build dict filtered_dicoms = [] for dicom_ in dicoms: - if 'ImageType' in dicom_ and 'LOCALIZER' in dicom_.ImageType: + if 'ImageType' in dicom_ and 'LOCALIZER' in dicom_.get('ImageType'): continue # 'Projection Image' are Localizers for CT only see MSMET-234 - if 'CT' in dicom_.Modality and 'ImageType' in dicom_ and 'PROJECTION IMAGE' in dicom_.ImageType: + if 'CT' in dicom_.get('Modality') and 'ImageType' in dicom_ and 'PROJECTION IMAGE' in dicom_.get('ImageType'): continue filtered_dicoms.append(dicom_) return filtered_dicoms From 42d9743c32dce02ec6f1b6c0a38c62528245636d Mon Sep 17 00:00:00 2001 From: Chenjie Xu Date: Sat, 1 Oct 2022 22:46:49 +0800 Subject: [PATCH 2/2] Fix TypeError --- dicom2nifti/convert_generic.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dicom2nifti/convert_generic.py b/dicom2nifti/convert_generic.py index 3b4918e..717cc19 100644 --- a/dicom2nifti/convert_generic.py +++ b/dicom2nifti/convert_generic.py @@ -214,10 +214,10 @@ def remove_localizers_by_imagetype(dicoms): # Loop overall files and build dict filtered_dicoms = [] for dicom_ in dicoms: - if 'ImageType' in dicom_ and 'LOCALIZER' in dicom_.get('ImageType'): + if 'ImageType' in dicom_ and 'LOCALIZER' in dicom_.ImageType: continue # 'Projection Image' are Localizers for CT only see MSMET-234 - if 'CT' in dicom_.get('Modality') and 'ImageType' in dicom_ and 'PROJECTION IMAGE' in dicom_.get('ImageType'): + if 'Modality' in dicom_ and 'CT' in dicom_.Modality and 'ImageType' in dicom_ and 'PROJECTION IMAGE' in dicom_.ImageType: continue filtered_dicoms.append(dicom_) return filtered_dicoms