Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow to use dcmdjpeg instead of gdcmconv #68

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 23 additions & 3 deletions dicom2nifti/compressed_dicom.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,23 @@ def _get_gdcmconv():
return gdcmconv_executable


def _get_dcmdjpeg():
"""
Get the full path to gdcmconv.
If not found raise error
"""
dcmdjpeg_executable = settings.dcmdjpeg_path
if dcmdjpeg_executable is None:
dcmdjpeg_executable = _which('dcmdjpeg')
if dcmdjpeg_executable is None:
dcmdjpeg_executable = _which('dcmdjpeg.exe')

if dcmdjpeg_executable is None:
raise ConversionError('DCMDJPEG_NOT_FOUND')

return dcmdjpeg_executable


def compress_directory(dicom_directory):
"""
This function can be used to convert a folder of jpeg compressed images to an uncompressed ones
Expand Down Expand Up @@ -128,9 +145,12 @@ def _decompress_dicom(dicom_file, output_file):

:param input_file: single dicom file to decompress
"""
gdcmconv_executable = _get_gdcmconv()

subprocess.check_output([gdcmconv_executable, '-w', dicom_file, output_file])
try:
dcmdjpeg_executable = _get_dcmdjpeg()
subprocess.check_output([dcmdjpeg_executable, dicom_file, output_file])
except ConversionError:
gdcmconv_executable = _get_gdcmconv()
subprocess.check_output([gdcmconv_executable, '-w', dicom_file, output_file])


def _which(program):
Expand Down
11 changes: 11 additions & 0 deletions dicom2nifti/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
validate_multiframe_implicit = True
pydicom_read_force = False
gdcmconv_path = None
dcmdjpeg_path = None
resample = False
resample_padding = 0
resample_spline_interpolation_order = 0 # spline interpolation order (0 nn , 1 bilinear, 3 cubic)
Expand Down Expand Up @@ -157,3 +158,13 @@ def set_gdcmconv_path(path):
"""
global gdcmconv_path
gdcmconv_path = path


def set_dcmdjpeg_path(path):
"""
Set where the filepath to the dcmdjpeg executable (needed is it is not found in your PATH)

:param path: the file path to the dcmdjpeg executable
"""
global dcmdjpeg_path
dcmdjpeg_path = path