Modern large language models like Google's MedGemma are revolutionizing healthcare, but they cannot natively interpret raw DICOM (.dcm) images, which is the the standard format used in hospitals and radiology.
This script helps bridge that gap by converting DICOM images into standard JPEG format — making them accessible for AI models, image viewers, machine learning pipelines, and web applications. It also supports both grayscale and color images, and has batch conversion ablities.
- Supports both color and grayscale DICOM images
- Applies Modality LUT and VOI LUT for accurate windowing
- Outputs 8-bit JPEG images
- Easy command-line usage
- Ability to batch convert multiple files in a folder
-
Python 3.10+
-
Install the following Python library dependencies.
pip install pydicom pillow numpy
Recommended to use #1 and #4
-
Convert one DICOM file → JPEG (auto-named in same folder)
python dcm2jpg.py test-rgb.dcm
-
Input: test-rgb.dcm
-
Output: test-rgb.jpg (next to the .dcm file)
-
Use case: Quick single-file conversion using default filename
-
Output name is auto-generated by replacing .dcm with .jpg.
-
-
Convert one DICOM file → one JPEG (explicit filename)
python dcm2jpg.py test-rgb.dcm test-rgb.jpg
-
Input: test-rgb.dcm
-
Output: test-rgb.jpg (in current directory)
-
Use case: You want to specify exactly where and what the output image will be named.
-
Output will be in the same folder as the source file, and renamed to the specified file name
-
-
Batch convert all .dcm files in a folder → JPEGs in same folder
python dcm2jpg.py ./example-dicom
-
Input folder: ./example-dicom/
-
Output: JPEGs saved as file1.jpg, file2.jpg, etc. in the same folder
-
Use case: You want to convert all files in-place
-
Output filenames match DICOM names (image123.dcm → image123.jpg).
-
-
Batch convert a folder → JPEGs in a separate folder
python dcm2jpg.py ./example-dicom ./jpg-output
-
Input: All .dcm files inside ./example-dicom
-
Output: All JPEGs saved to ./jpg-output/ with same base names
-
Use case: You want to keep .dcm and .jpg files separated
-
Output folder is auto-created if missing.
-