Page 1 of 1

Unable to convert this DICOM jpg variant

Posted: 2013-04-23T02:05:16-07:00
by cuthbert
Hi

Im working on a software library that uses ImageMagick to decompress the image data from DICOM files. This works just fine for many files, but there is this file that is causing problems. When trying to convert the DICOM file to an ordinary image, I get an error:

Code: Select all

C:\samples>convert explicit_ct_jpeg-lossless-nh_mono2.dcm image.png
convert.exe: Unsupported JPEG process: SOF type 0xc3 `C:/WINDOWS/Temp/magick-36364ZcC1LmAuU3a' @ error/jpeg.c/JPEGErrorHandler/319.
convert.exe: no images defined `image.png' @ error/convert.c/ConvertImageCommand/3106.
The file in question is available here:
https://github.com/dicom/ruby-dicom/raw ... _mono2.dcm

According to the file's transfer syntax (1.2.840.10008.1.2.4.70), this jpeg variant has the following description:
JPEG Lossless, Non-Hierarchical, First-Order Prediction (Process 14 [Selection Value 1]): Default Transfer Syntax for Lossless JPEG Image Compression

Would it be possible to add support for this kind of jpg compression to ImageMagick?
If so, that would be awesome!

Best regards,
Chris


Environment information:
Operating system: Windows XP SP3 32 bit
Imagemagick install file: ftp://ftp.imagemagick.org/pub/ImageMagi ... 86-dll.exe

Code: Select all

C:\samples>convert -version
Version: ImageMagick 6.8.4-10 2013-04-13 Q16 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2013 ImageMagick Studio LLC
Features: DPC OpenMP
Delegates: bzlib fontconfig freetype jng jp2 jpeg lcms lzma pango png ps tiff x xml zlib

Code: Select all

C:\samples>convert -list configure

Path: [built-in]

Name           Value
-------------------------------------------------------------------------------
FEATURES       OpenMP
NAME           ImageMagick
QuantumDepth   16

Path: C:\Programfiler\ImageMagick-6.8.4-Q16\configure.xml

Name           Value
-------------------------------------------------------------------------------
CC             vs10
COPYRIGHT      Copyright (C) 1999-2013 ImageMagick Studio LLC
DELEGATES      bzlib freetype jpeg jp2 lcms png tiff x11 xml wmf zlib
FEATURES       OpenMP
HOST           Windows
LIB_VERSION    0x684
LIB_VERSION_NUMBER 6,8,4,10
NAME           ImageMagick
RELEASE_DATE   2013-05-01
VERSION        6.8.4
WEBSITE        http://www.imagemagick.org

Code: Select all

C:\samples>convert -debug module explicit_ct_jpeg-lossless-nh_mono2.dcm image.png
2013-04-23T10:55:14+02:00 0:00.000 0.000u 6.8.4 Module convert.exe[2548]: module.c/OpenModule/1263/Module
  Searching for module "DCM" using filename "IM_MOD_RL_DCM_.dll"
2013-04-23T10:55:14+02:00 0:00.015 0.000u 6.8.4 Module convert.exe[2548]: module.c/GetMagickModulePath/565/Module
  Searching for coder module file "IM_MOD_RL_DCM_.dll" ...
2013-04-23T10:55:14+02:00 0:00.015 0.000u 6.8.4 Module convert.exe[2548]: module.c/OpenModule/1272/Module
  Opening module at path "C:\Programfiler\ImageMagick-6.8.4-Q16\modules\coders\IM_MOD_RL_DCM_.dll"
2013-04-23T10:55:14+02:00 0:00.015 0.000u 6.8.4 Module convert.exe[2548]: module.c/OpenModule/1299/Module
  Method "RegisterDCMImage" in module "DCM" at address 671C44D0
2013-04-23T10:55:14+02:00 0:00.031 0.000u 6.8.4 Module convert.exe[2548]: module.c/OpenModule/1313/Module
  Method "UnregisterDCMImage" in module "DCM" at address 671C4540
2013-04-23T10:55:14+02:00 0:00.062 0.031u 6.8.4 Module convert.exe[2548]: module.c/OpenModule/1263/Module
  Searching for module "JPEG" using filename "IM_MOD_RL_JPEG_.dll"
2013-04-23T10:55:14+02:00 0:00.078 0.031u 6.8.4 Module convert.exe[2548]: module.c/GetMagickModulePath/565/Module
  Searching for coder module file "IM_MOD_RL_JPEG_.dll" ...
2013-04-23T10:55:14+02:00 0:00.078 0.031u 6.8.4 Module convert.exe[2548]: module.c/OpenModule/1272/Module
  Opening module at path "C:\Programfiler\ImageMagick-6.8.4-Q16\modules\coders\IM_MOD_RL_JPEG_.dll"
2013-04-23T10:55:14+02:00 0:00.078 0.031u 6.8.4 Module convert.exe[2548]: module.c/OpenModule/1299/Module
  Method "RegisterJPEGImage" in module "JPEG" at address 675A7090
2013-04-23T10:55:14+02:00 0:00.093 0.031u 6.8.4 Module convert.exe[2548]: module.c/OpenModule/1313/Module
  Method "UnregisterJPEGImage" in module "JPEG" at address 675A4610
convert.exe: Unsupported JPEG process: SOF type 0xc3 `C:/WINDOWS/Temp/magick-2548hJpza5pGNdaR' @ error/jpeg.c/JPEGErrorH
andler/319.
convert.exe: no images defined `image.png' @ error/convert.c/ConvertImageCommand/3106.

Re: Unable to convert this DICOM jpg variant

Posted: 2013-04-23T04:13:45-07:00
by magick
Find a version of the JPEG library that supports lossless encoding. Build it with ImageMagick and that should permit you to read DICOM images with lossless JPEG embedded. Its been a few years since we tried the lossless JPEG delegate library but it just worked the last time we tested it.

Re: Unable to convert this DICOM jpg variant

Posted: 2013-04-23T06:14:44-07:00
by cuthbert
I appreciate your response, however, the sad truth is that I'm basically lost as to how to achieve what you propose. I wouldn't know what jpeg delegate library to use, or how to compile it with ImageMagick. I'm sure there are other users in the same boat as well. If you could point us in the right direction, that would be much appreciated.

Furthermore, I'm somewhat surprised that this isn't included in ImageMagick by default. ImageMagick seems to be such a powerful tool, supporting countless image formats, with bindings to a host of programming languages. Could you give us a hint as to how come this lossless jpeg format isn't supported by default in ImageMagick, and whether it would be conceivable for such support to be included going forward?

Re: Unable to convert this DICOM jpg variant

Posted: 2013-04-23T06:29:22-07:00
by magick
Our development group is too small to support all the variations of ImageMagick that the user community requests. Instead its up to the user to build one-off distributions to meet their requirements. We currently have no plans to support lossless JPEG in the binary distributions of ImageMagick. Instead we support lossless JPEG-2000 (Jasper) which is the more accepted standard for lossless JPEG encoding. However, DICOM wants the lossless JPEG library which is available for a custom build of ImageMagick. We have seen it work many times in the past, its just something we do not want to include in the Windows binary distribution because there is not much of a demand for it.

Re: Unable to convert this DICOM jpg variant

Posted: 2013-04-23T06:33:56-07:00
by glennrp
cuthbert wrote:...I'm somewhat surprised that this isn't included in ImageMagick by default. ImageMagick seems to be such a powerful tool, supporting countless image formats, with bindings to a host of programming languages. Could you give us a hint as to how come this lossless jpeg format isn't supported by default in ImageMagick, and whether it would be conceivable for such support to be included going forward?
Lots of formats are not supported by default but by delegates instead. PostScript, TIFF, PNG, JPEG, DCRAW, JP2, to name several. How come? Generally because they require large third-party libraries that are supported by others. Support going forward? ImageMagick already supports them (including lossless JPEG) via delegates.

Re: Unable to convert this DICOM jpg variant

Posted: 2013-04-23T07:22:24-07:00
by cuthbert
Ok, it seems that supporting such a rare format in a binary distribution is difficult/cumbersome.

That being accepted, is there a way of compiling ImageMagick on Windows with such jpeg support that's within the reach of a Joe Schmoe like me?! I.e. is there a recipe or resource somewhere that could help me along? Any links or similar would be appreciated.

Regards,
Chris

Re: Unable to convert this DICOM jpg variant

Posted: 2013-04-23T07:37:17-07:00
by magick