Library for reading, editing and writing DICOM files, as well as handling DICOM network communication. Written in the Ruby language.
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.


Ruby DICOM is a small and simple library for handling DICOM in Ruby. DICOM (Digital Imaging and Communications in Medicine) is a standard for handling, storing, printing, and transmitting information in medical imaging. It includes a file format definition and a network communications protocol. Ruby DICOM supports reading from, editing and writing to this file format. It also features basic support for select network communication modalities like querying, moving, sending and receiving files.


gem install dicom


  • Ruby 1.9.3 (if you are still on Ruby 1.8, gems up to version 0.9.1 can be used)


Load & Include

require 'dicom'
include DICOM

Read, modify and write

# Read file:
dcm ="some_file.dcm")
# Extract the Patient's Name value:
# Add or modify the Patient's Name element:
dcm.patients_name = "Anonymous"
# Remove a data element from the DICOM object:
dcm.pixel_data = nil
# Write to file:

Modify using tag strings instead of dictionary method names

# Extract the Patient's Name value:
# Modify the Patient's Name element:
dcm["0010,0010"].value = "Anonymous"
# Delete a data element from the DICOM object:

Extracting information about the DICOM object

# Display a short summary of the file's properties:
# Print all data elements to screen:
# Convert the data element hierarchy to a nested hash:

Handle pixel data

# Retrieve the pixel data in a Ruby Array:
# Load the pixel data to an numerical array (NArray):
# Load the pixel data to an RMagick image object and display it on screen (X):

Transmit a DICOM file

# Send a local file to a server (PACS) over the network:
node ="", 104)

Start a DICOM server

# Initiate a simple storage provider which can receive DICOM files of all modalities:
s =, :host_ae => "MY_DICOM_SERVER")

Log settings

# Change the log level so that only error messages are displayed:
DICOM.logger.level = Logger::ERROR
# Setting up a simple file log:
l ='my_logfile.log')
DICOM.logger = l
# Create a logger which ages logfile daily/monthly:
DICOM.logger ='foo.log', 'daily')
DICOM.logger ='foo.log', 'monthly')


When working with Ruby DICOM in irb, you may be annoyed with all the information that is printed to screen, regardless if you have set verbose as false. This is because in irb every variable loaded in the program is automatically printed to the screen. A useful hack to avoid this effect is to append ";0" after a command. Example:

dcm ="some_file.dcm") ;0



Copyright 2008-2018 Christoffer Lervåg

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see .


  • Name: Christoffer Lervåg
  • Location: Norway
  • Email: chris.lervag []

Please don't hesitate to email me if you have any feedback related to this project!