Search code examples
ruby-on-railsdlldependenciesrubygemsimagemagick

Convert Dicom Image to JPG


I am trying to convert a dicom file to JPG which I would then use to show as thumbnail for the dicom file. I am using the code below to convert the dicom file but When I execute it I get the following error

'write': no encode delegate for this image format `' @ error/constitute.c/WriteImage/1272 (Magick::ImageMagickError)

I am using ruby version 2.7.0 and I have installed ImageMagick 7.1.0-4 and the supportive gems. How to solve this error?

require 'dicom'
require 'rmagick'
include DICOM

dcm = DObject.read("sample.dcm")
image = dcm.image(:frame => 5)
image.normalize.write("test.jpeg");


Solution

  • I had to reinstall ImageMagick-7.1.0-26 along with libgdcm-tools on my system and the above mentioned code worked fine. So Imagemagick needs these additional libraries (libjpeg62-dev, libtiff-dev, libpng-dev, libpng12-0 and libgdcm-tools) to work with these image types. I don't know if this is correct or not but that the problem I was facing has been resolved by following this approach. Here are some of the links which helped me in solving this

    Install ImageMagick with JPG TIFF and PNG Delegates

    How to configure and build with libgcdm for lossless jpeg conversion and dicom support