Skip to content

Commit

Permalink
output files from convert_dir
Browse files Browse the repository at this point in the history
  • Loading branch information
casperdcl committed Oct 31, 2021
1 parent 60eca00 commit 0cd2132
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions dicom2nifti/convert_dir.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ def convert_directory(dicom_directory, output_folder, compression=True, reorient
:param reorient: reorient the dicoms according to LAS orientation
:param output_folder: folder to write the nifti files to
:param dicom_directory: directory with dicom files
:returns: list of created nifti files
"""
# sort dicom files by series uid
dicom_series = {}
Expand Down Expand Up @@ -59,6 +60,7 @@ def convert_directory(dicom_directory, output_folder, compression=True, reorient
traceback.print_exc()

# start converting one by one
nifti_files = []
for series_id, dicom_input in dicom_series.items():
base_filename = ""
# noinspection PyBroadException
Expand Down Expand Up @@ -86,9 +88,11 @@ def convert_directory(dicom_directory, output_folder, compression=True, reorient
nifti_file = os.path.join(output_folder, base_filename + '.nii')
convert_dicom.dicom_array_to_nifti(dicom_input, nifti_file, reorient)
gc.collect()
nifti_files.append(nifti_file)
except: # Explicitly capturing app exceptions here to be able to continue processing
logger.info("Unable to convert: %s" % base_filename)
traceback.print_exc()
return nifti_files


def _is_valid_imaging_dicom(dicom_header):
Expand Down

0 comments on commit 0cd2132

Please sign in to comment.