Converting Medical Images from DICOM to JPG on Mac OS X

GE Centricity Viewer DVDs of radiology images (PET / MRI) are saved in DICOM format and come with software for viewing the images. In order to use these images in other places, it may be necessary to convert them to a more standard format.  I found one guide one that covered the necessary steps, but I found that a number of details were missing in order to complete a successful installation on Mac OS X.

The following steps are what worked for me:


  1. Install Xcode from App Store

    This is a prerequisite for compiling programs.

  2. Install Ruby

    Here’s a good guide:


  3. Install DICOM

    Now install dicom support for ruby (in terminal):

    $ gem install dicom

  4. Install Homebrew

    This is needed for the following two steps.

    $ ruby -e "$(curl -fsSL"


  5. Install ImageMagick

    The default install does not include jpeg 2000 support by default, which is needed to work with DICOM files, so you will need to specify the jp2 option when you install it:

    $ brew install imagemagick --with-jp2


  6. Install pkg-config

    This is a prerequisite for the next step.

    $ brew install pkg-config


  7. Install Rmagick Gem

    You may need to adjust the paths to match the current version numbers.

    $ sudo C_INCLUDE_PATH=/usr/local/Cellar/imagemagick/6.9.1-10/include/ImageMagick-6/ PKG_CONFIG_PATH=/usr/local/Cellar/imagemagick/6.9.1-10/lib/pkgconfig/ gem install rmagick


Doing the conversion

  1. Ruby conversion script

    Create the following ruby program in a text editor and save it as dicom-convert.rb. This finds all matching files in the current directory and all subdirectories and converts each one to jpeg format. If the files have a .dcm file extension, use *.dcm, otherwise find a different wildcard (e.g. MRI*) that matches your files.

    require 'dicom'
    include DICOM
    dcimfiles = File.join("**", “*.dcm")
    filenames = Dir.glob(dcimfiles)
    filenames.each do |filename|
    dcm =
    dcm_image = dcm.image
    dcm_image.normalize.write(filename + ".jpg")

    Or if you wish to use the script manually on individual files, you can use:

    require 'dicom'
    include DICOM
    dcm ="MRI000001.dcm")
    dcm_image = dcm.image

    This is a useful resource if you need to customize the script further:

  2. Running the script

    Place the program in the root of your DICOM files directory, open terminal, change to that directory,and run the following command:

    $ ruby dicom-convert.rb

This was based upon a guide written on; however, I found that additional steps were required to get it to work successfully. The sitepoint guide also includes instructions for Windows and Linux.


Add Yours →

Leave a Reply