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


















MORE ON 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.

We have previously described what you need to install to manipulate images in Ruby (ImageMagick, RMagick, and Tcl/Tk). Here is a short Ruby script that shows how to use RMagick (Ruby's interface to ImageMagick) to modify and display an image.


#!/usr/local/bin/ruby
require 'RMagick'
include Magick
leaf = ImageList.new("leaf.jpg").resize!(0.4)
leaf.write("leaf.gif")
leaf2 = ImageList.new("leaf.jpg").first.resize(0.4).blur_image(radius=0.0, sigma=2.5).border(10,10,'rgb(255,110,140)')
leaf2.write("new.gif")
require 'tk'
root = TkRoot.new {title "view"}
TkButton.new(root) do
  image TkPhotoImage.new{file "leaf.gif"}
  command {exit}
  pack
end
TkButton.new(root) do
  image TkPhotoImage.new{file "new.gif"}
  command {exit}
  pack
end
Tk.mainloop
exit




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 sits atop the same image, modified by the "blur_image" method and wrapped by a border.



Viewing a a modified JPEG image in Ruby

More on creating and displaying images in Ruby

Last modified June 19, 2007





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