Biomedical books by Jules J. Berman, Ph.D., M.D.


biomedical informatics cover Perl Programming for Medicine and Biology Cover Ruby for Medicine and Biology Cover


















BASICS OF IMAGE DISPLAY IN RUBY


Ruby is a free, open source, object-oriented programming language. There are many beginner books on Ruby. If you work in the medical or biological fields, you might want to try my book, Ruby Programming for Medicine and Biology, which will be published in the early fall, 2007, by Jones & Bartlett Publishers.

Here is a short introduction to image display in Ruby. The source code will only make sense to those who know something about Ruby programming.


ImageMagick is free software for manipulating images.

An important feature of ImageMagick is that many popular programming languages, including Ruby, provide interfaces to ImageMagick.

RMagick is Ruby's interface to ImageMagick.

Tk is a free language for creating GUIs (graphic user interfaces). Tk employs widgets (small windows within the Tk window) for input and display structures.

If you install ImageMagick, RMagick and Tk onto your computer, you can "require" them into your Ruby scripts and create applications that create, modify, evaluate, and display images. All three applications are available at no cost for users of Windows or Linux/Unix operating systems. Ample instruction is available at the web sites, below. Here are some suggestions for Windows users:


For Windows users, a good way to install RMagick is to follow these instructions.
Go to the RubyForge site and download the combined RMagick and ImageMagick binaries.

1. Go to the RubyForge site:

http://rubyforge.org/frs/?group_id=12&release_id=8170

This page has a combined win32 binary package for RMagick and ImageMagick

Pick the binary that is appropriate for your version of Ruby.

I use Ruby 1.8.4, so I chose the following binary:

rmagick-1.13.0-IM-6.2.9-0-win32.zip 12.39 MB

2. Download the binary (zip file) and expand it.

This produces the subdirectory:

rmagick-1.13.0-IM-6.2.9-0-win32

The subdirectory contains a group of files:

ImageMagick-6.2.9-0-Q8-windows-dll.exe
README-RMAGICK.html
README-RMAGICK.txt
README.html
rmagick-1.13.0-win32.gem

3. Run the ImageMagick .exe file, and it will guide you through its installation.

4. After ImageMagick is installed, you can install the RMagick gem file by invoking Ruby's gem tool with an install command followed by the name of the gem file (add the full path to the gem file if you are not installing from its current subdirectory)

c:\ftp>gem install rmagick-1.13.0-win32.gem

5. All the information you need to start using RMagick from within your own Ruby Scripts is found at:
http://www.simplesystems.org/RMagick/doc/

Then install Tcl/Tk by visiting ActiveState and downloading the Activebinary for Windows users.

You've finished your installations. Now you're ready to write Ruby scripts that use and display images.

Tk does not display JPEG images, but you can load a JPEG file with RMagick and display it in a window with Tk.

The figure below displays a jpeg image of a leaf (obtained from Wikipedia as a public domain file: http://en.wikipedia.org/wiki/Image:Leaf_1_web.jpg, and renamed leaf.jpg for this page).

Rights annotation from Wikipedia:"This image from PD Photo.org has been released into the public domain by its author and copyright holder, Jon Sullivan."

The image of the leaf produced by the Ruby script, and the Ruby script source code that displays the image, is shown below:



Viewing a JPEG image in Ruby

More on displaying images in Ruby


Last modified: June 9, 2007

biomedical informatics cover Perl Programming for Medicine and Biology Cover Ruby for Medicine and Biology Cover