JPEG to DICOM simple conversion

Some patient medical image viewing systems (e.g. for X-ray, MRI, CT) only export JPEG. Other patient systems only allow uploading DICOM images, which contain metadata about the imaging study. If one needs to quickly convert JPEG images to DICOM, omitting the metadata, the following simple method can be used.

First, install DCMTK:

  • macOS: brew install dcmtk
  • Windows: Download and install from GitHub Releases *-win64.zip or use WSL
  • Linux (or Windows Subsystem for Linux): apt install dcmtk

Convert a single JPEG file to DICOM using the img2dcm command:

img2dcm img1.jpg img1.dcm

This will create a DICOM file img1.dcm from the image data of img1.jpg, but without any metadata. The resulting DICOM file can be uploaded to the patient system that only accepts DICOM, and the image will be viewable, but without any metadata about the imaging study.

Convert multiple JPEG files in a folder with a simple loop in the Unix-like terminal:

for img in *.jpg; do
    img2dcm "$img" "${img%.jpg}.dcm"
done

Or in PowerShell:

Get-ChildItem -Filter *.jpg | ForEach-Object {
    $img = $_.FullName
    $dcm = [System.IO.Path]::ChangeExtension($img, ".dcm")
    img2dcm $img $dcm
}

If the input file isn’t JPEG, first convert it to JPEG using ImageMagick, which can be installed via:

  • macOS: brew install imagemagick
  • Windows: winget install --id=ImageMagick.ImageMagick
  • Linux (or Windows Subsystem for Linux): apt install imagemagick

Then convert the image to JPEG:

magick img1.png img1.jpg