LoadError:无法加载这样的文件 - 使用dicom gem加载rmagick

时间:2016-02-19 10:29:20

标签: ruby-on-rails-4 imagemagick dicom rmagick

我正在编写一份使用dicom gem将dcm转换为jpg图像的作业

这是代码

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


class DicomtojpgJob < ActiveJob::Base
  queue_as :dicom

  def perform(*args)
    puts "were are here"
    dcm_filename = args[0]
    dcm = DObject.read(dcm_filename)
    puts dcm.summary
    dcm_image = dcm.image
    name = dcm_filename.split('.')
    dcm_image.normalize.write(name[0]+".jpg")

    # img = ImageList.new("IM-0004-0044.jpg")
    # img.display
    # args[0].update_attributes(:asset_path_url)
    puts args[0]

    exit
  end

end

这是我在控制台上获得的内容

DICOM Object Properties:Byte Order (CPU):     Little Endian
-------------------------------------------
Source:               File (successfully read): /home/aditya/orthoweb/public/patient-summary-assets/56c6b0b943fe4728c8000007_photo_20160219_122843.dcm

DICOM Object Properties:

Modality:             MR Image Storage-------------------------------------------

Source:               File (successfully read): /home/aditya/orthoweb/public/patient-summary-assets/56c6b0b943fe4728c8000007_photo_20160219_151307.dcm
Modality:             MR Image Storage
Meta Header:          Yes
Value Representation: Explicit
Byte Order (File):    Little Endian
Pixel Data:           Yes
Image Size:           512*288
Number of frames:     1
Meta Header:          YesPhotometry:           MONOCHROME2
Compression:          JPEG 2000 Image Compression

Value Representation: ExplicitBits per Pixel:       16

Byte Order (File):    Little Endian-------------------------------------------

Pixel Data:           Yes
Source:               File (successfully read): /home/aditya/orthoweb/public/patient-summary-assets/56c6b0b943fe4728c8000007_photo_20160219_151307.dcm
Modality:             MR Image Storage
Image Size:           512*288Meta Header:          Yes
Value Representation: Explicit

Number of frames:     1Byte Order (File):    Little Endian

Photometry:           MONOCHROME2Pixel Data:           Yes
Image Size:           512*288

Number of frames:     1Compression:          JPEG 2000 Image Compression

Bits per Pixel:       16Photometry:           MONOCHROME2

-------------------------------------------Compression:          JPEG 2000 Image Compression

Source:               File (successfully read): /home/aditya/orthoweb/public/patient-summary-assets/56c6b0b943fe4728c8000007_photo_20160219_122843.dcmBits per Pixel:       16

Modality:             MR Image Storage
Meta Header:          Yes
Value Representation: Explicit
Byte Order (File):    Little Endian
Pixel Data:           Yes
Image Size:           512*288
Number of frames:     1
2016-02-19T10:07:18.291Z 17868 TID-1ho0x0 DicomtojpgJob JID-4fc6a66b41be878a632b7d9e INFO: fail: 0.014 sec
2016-02-19T10:07:18.291Z 17868 TID-1ho0x0 WARN: {"class"=>"ActiveJob::QueueAdapters::SidekiqAdapter::JobWrapper", "wrapped"=>"DicomtojpgJob", "queue"=>"dicom", "args"=>[{"job_class"=>"DicomtojpgJob", "job_id"=>"345b5c25-82fb-49e7-a59d-b4a5eaf971b6", "queue_name"=>"dicom", "arguments"=>["/home/aditya/orthoweb/public/patient-summary-assets/56c6b0b943fe4728c8000007_photo_20160219_151307.dcm"]}], "retry"=>true, "jid"=>"4fc6a66b41be878a632b7d9e", "created_at"=>1455874987.2288666, "enqueued_at"=>1455876438.270517, "error_message"=>"cannot load such file -- rmagick", "error_class"=>"LoadError", "failed_at"=>1455874987.2376463, "retry_count"=>6, "retried_at"=>1455876438.2907836}
Photometry:           MONOCHROME2
Compression:          JPEG 2000 Image Compression
Bits per Pixel:       162016-02-19T10:07:18.291Z 17868 TID-1ho0x0 WARN: LoadError: cannot load such file -- rmagick

我在github页面here上关注了这个问题 它建议如果我能够使用命令convert -debug module IM-0001-0001.dcm IM.jpg直接将dcm图像转换为jpg,那么dicom不应该显示任何错误。 我可以使用控制台将其转换为jpg,但是dicom正在抛出error 2016-02-19T09:24:03.960Z 14165 TID-1kcakw WARN: LoadError: cannot load such file -- rmagick

我该如何解决这个问题

3 个答案:

答案 0 :(得分:0)

我从您建议的存储库中下载了第一张图像,并运行了以下命令:

convert -debug module IM-0001-0001.dcm a.jpg

<强>输出

2016-02-19T12:25:56+00:00 0:00.000 0.000u 6.9.3 Module convert[86871]: module.c/OpenModule/1286/Module
  Searching for module "DCM" using filename "dcm.la"
2016-02-19T12:25:56+00:00 0:00.000 0.000u 6.9.3 Module convert[86871]: module.c/GetMagickModulePath/556/Module
  Searching for coder module file "dcm.la" ...
2016-02-19T12:25:56+00:00 0:00.000 0.000u 6.9.3 Module convert[86871]: module.c/OpenModule/1295/Module
  Opening module at path "/usr/local/Cellar/imagemagick/6.9.3-0_2/lib/ImageMagick//modules-Q16/coders/dcm.la"
2016-02-19T12:25:56+00:00 0:00.000 0.000u 6.9.3 Module convert[86871]: module.c/OpenModule/1322/Module
  Method "RegisterDCMImage" in module "DCM" at address 0x1076bd758
2016-02-19T12:25:56+00:00 0:00.000 0.000u 6.9.3 Module convert[86871]: module.c/OpenModule/1336/Module
  Method "UnregisterDCMImage" in module "DCM" at address 0x1076c0ff2
2016-02-19T12:25:56+00:00 0:00.000 0.000u 6.9.3 Module convert[86871]: module.c/OpenModule/1286/Module
  Searching for module "JP2" using filename "jp2.la"
2016-02-19T12:25:56+00:00 0:00.000 0.000u 6.9.3 Module convert[86871]: module.c/GetMagickModulePath/556/Module
  Searching for coder module file "jp2.la" ...
2016-02-19T12:25:56+00:00 0:00.000 0.000u 6.9.3 Module convert[86871]: module.c/OpenModule/1295/Module
  Opening module at path "/usr/local/Cellar/imagemagick/6.9.3-0_2/lib/ImageMagick//modules-Q16/coders/jp2.la"
2016-02-19T12:25:56+00:00 0:00.000 0.000u 6.9.3 Module convert[86871]: module.c/OpenModule/1322/Module
  Method "RegisterJP2Image" in module "JP2" at address 0x1076e3a24
2016-02-19T12:25:56+00:00 0:00.000 0.000u 6.9.3 Module convert[86871]: module.c/OpenModule/1336/Module
  Method "UnregisterJP2Image" in module "JP2" at address 0x1076e572e
2016-02-19T12:25:56+00:00 0:00.000 0.000u 6.9.3 Module convert[86871]: module.c/OpenModule/1286/Module
  Searching for module "JPEG" using filename "jpeg.la"
2016-02-19T12:25:56+00:00 0:00.000 0.000u 6.9.3 Module convert[86871]: module.c/GetMagickModulePath/556/Module
  Searching for coder module file "jpeg.la" ...
2016-02-19T12:25:56+00:00 0:00.000 0.000u 6.9.3 Module convert[86871]: module.c/OpenModule/1295/Module
  Opening module at path "/usr/local/Cellar/imagemagick/6.9.3-0_2/lib/ImageMagick//modules-Q16/coders/jpeg.la"
2016-02-19T12:25:56+00:00 0:00.000 0.000u 6.9.3 Module convert[86871]: module.c/OpenModule/1322/Module
  Method "RegisterJPEGImage" in module "JPEG" at address 0x107e9ce7c
2016-02-19T12:25:56+00:00 0:00.000 0.000u 6.9.3 Module convert[86871]: module.c/OpenModule/1336/Module
  Method "UnregisterJPEGImage" in module "JPEG" at address 0x107ea07b3

enter image description here

我认为问题在于您缺少JPEG2000模块。您可以使用

检查已安装的代理人
identify -version

Version: ImageMagick 6.9.3-0 Q16 x86_64 2016-02-19 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2016 ImageMagick Studio LLC
License: http://www.imagemagick.org/script/license.php
Features: Cipher DPC Modules 
Delegates (built-in): bzlib fontconfig freetype jng jp2 jpeg lcms ltdl lzma openexr png tiff webp x xml lib

在这里你看到我有jp2。如果您缺少该模块,则在安装并运行./configure时,请尝试添加以下内容以查找所需的开关:

./configure --help | grep -Ei "JP|2000"

然后以通常的方式运行configuremake以及make install

答案 1 :(得分:0)

它还没有与RMagick合作。 但是使用mini_magick正常工作

要求'mini_magick'

DICOM.image_processor =:mini_magick

答案 2 :(得分:0)

通过将rmagick升级到2.13.4或更高版本来解决此问题。