added implicit VR to dicom files that do not have a default, caused by pydicom v1.0
@@ -49,13 +49,29 @@ def is_dicom_image(file):
result = False
try:
img = pydicom.dcmread(file, force=True)
+ if 'TransferSyntaxUID' not in img.file_meta:
+ img.file_meta.TransferSyntaxUID = pydicom.uid.ImplicitVRLittleEndian
img.pixel_array
result = True
- except:
+ except (AttributeError, TypeError):
pass
return result
+def retrieve_dicom_image(file):
+ """Read and return the DICOM dataset.
+
+ Parameters
+ ----------
+ file : str
+ The path to the file.
+ """
+ img = pydicom.dcmread(file, force=True)
+ if 'TransferSyntaxUID' not in img.file_meta:
+ img.file_meta.TransferSyntaxUID = pydicom.uid.ImplicitVRLittleEndian
+ return img
+
+
def is_zipfile(file):
"""Wrapper function for detecting if file is a true ZIP archive"""
return zipfile.is_zipfile(file)
