Write DICOM Image as .jpg

66 views
Skip to first unread message

Jörg

unread,
Jun 24, 2011, 8:01:26 AM6/24/11
to ruby-dicom
Hi Chris,

I want to write an image of a DICOM file as .jpg with the following
example code:

require 'dicom'
include DICOM
require 'RMagick'
include Magick

obj = DICOM::DObject.new("myFile.dcm")
image = obj.image
image.write("dicom.jpg")

The written image result is completely black what should not be the
case.

Thx in advance for any help!

Chris

unread,
Jun 26, 2011, 2:24:55 PM6/26/11
to ruby-...@googlegroups.com
Hi Jorg,

This is (probably) because the extracted image contains the entire gray scale extracted from the CT scan or whatever the source, and you cant see any details. In this case you need to level your image according to the kind of organs you want high contrast for.

Try using the :level option:

image = obj.image(:level => true)

Or even specifying an exact range of hounsfield units for the leveling:

image = obj.image(:level => [-200,1000])

Best regards,
Chris

Jörg

unread,
Jun 27, 2011, 11:06:20 AM6/27/11
to ruby-dicom
Hi Chris,

with leveling as mentioned above and your hint to normalize before
writing the image it works out:

#image = obj.image(:level=>true)
image = obj.image(:level=>[100, 500])
image.normalize.write("test.jpg")

Thanks,
Jörg
Reply all
Reply to author
Forward
0 new messages