Skip to content

Commit

Permalink
Improve compatibility of mrd2dicom output and bump pydicom version
Browse files Browse the repository at this point in the history
  • Loading branch information
kspaceKelvin committed Nov 8, 2024
1 parent f7d8c16 commit b411954
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 4 deletions.
2 changes: 1 addition & 1 deletion docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ RUN cd /opt/code && \

# matplotlib is used by rgb.py and provides various visualization tools including colormaps
# pydicom is used by dicom2mrd.py to parse DICOM data
RUN pip3 install --no-cache-dir matplotlib==3.8.2 pydicom==2.4.3
RUN pip3 install --no-cache-dir matplotlib==3.8.2 pydicom==3.0.1

# Cleanup files not required after installation
RUN apt-get clean && \
Expand Down
2 changes: 1 addition & 1 deletion environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ dependencies:
- libxml2=2.9.12 # For ismrmrd
- h5py=3.7.0 # For ismrmrd
- matplotlib=3.8.2 # used by rgb.py and provides various visualization tools including colormaps
- pydicom=2.4.3 # used by dicom2mrd.py to parse DICOM data
- pydicom=3.0.1 # used by dicom2mrd.py to parse DICOM data
- numpy=1.26.0
- git=2.30.2
- dos2unix=7.4.2 # For fixing line ending issues from Windows
2 changes: 1 addition & 1 deletion environment_windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ dependencies:
- libxml2=2.9.12 # For ismrmrd
- h5py=3.7.0 # For ismrmrd
- matplotlib=3.8.2 # used by rgb.py and provides various visualization tools including colormaps
- pydicom=2.4.3 # used by dicom2mrd.py to parse DICOM data
- pydicom=3.0.1 # used by dicom2mrd.py to parse DICOM data
- numpy=1.26.0
- git=2.30.2
- dos2unix=7.4.2 # For fixing line ending issues from Windows
7 changes: 6 additions & 1 deletion mrd2dicom.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ def main(args):
xml_header = xml_header.decode("utf-8")
mrdHead = ismrmrd.xsd.CreateFromDocument(xml_header)

filesWritten = 0
for group in groups:
if ( (group == 'config') or (group == 'config_file') or (group == 'xml') ):
continue
Expand Down Expand Up @@ -117,6 +118,7 @@ def main(args):
dicomDset = pydicom.dataset.Dataset.from_json(base64.b64decode(meta['DicomJson']))
else:
dicomDset = pydicom.dataset.Dataset()
dicomDset = pydicom.dataset.Dataset()

# Enforce explicit little endian for written DICOM files
dicomDset.file_meta = pydicom.dataset.FileMetaDataset()
Expand Down Expand Up @@ -276,7 +278,10 @@ def main(args):
# Write DICOM files
fileName = "%02.0f_%s_%03.0f.dcm" % (dicomDset.SeriesNumber, dicomDset.SeriesDescription, dicomDset.InstanceNumber)
print(" Writing file %s" % fileName)
dicomDset.save_as(os.path.join(args.out_folder, fileName))
dicomDset.save_as(os.path.join(args.out_folder, fileName), enforce_file_format=True)
filesWritten += 1

print("Wrote %d DICOM files to %s" % (filesWritten, args.out_folder))
return

if __name__ == '__main__':
Expand Down

0 comments on commit b411954

Please sign in to comment.