Page 1 of 1

IM 6.9.7 doesn't identify DICOM file

Posted: 2020-01-21T07:49:04-07:00
by kzembower
Hello, this is my first use of Imagemagick in viewing DICOM files. Please let me know if I've done something stupid.

I'm trying to convert a DICOM image to a JPEG format. This is for casual use, and not for diagnosis.

File identifies the file as:

Code: Select all

$ file O0000001 
O0000001: DICOM medical imaging data
identify doesn't work:

Code: Select all

$ identify -verbose O0000001 
identify-im6.q16: Unsupported JPEG process: SOF type 0xc3 `/tmp/magick-28452FP1HtmvUIuKs' @ error/jpeg.c/JPEGErrorHandler/322.
Neither does convert:

Code: Select all

$ convert O0000001 O0000001.jpg
convert-im6.q16: Unsupported JPEG process: SOF type 0xc3 `/tmp/magick-28461qUlh-2p6Sgbx' @ error/jpeg.c/JPEGErrorHandler/322.
convert-im6.q16: no images defined `O0000001.jpg' @ error/convert.c/ConvertImageCommand/3258.
I also used a large variety of commands on this same theme.

Here's the version I'm using, on Ubuntu 18.4.3 LTS:

Code: Select all

$ convert -help
Version: ImageMagick 6.9.7-4 Q16 x86_64 20170114 http://www.imagemagick.org
I'm a little reluctant to release this image, since it's a real x-ray and contains a lot of my HIPPA-protected, PII. If anyone can tell me how to strip this information out, I'll be happy to post the anonymous image for testing and troubleshooting.

Thank you for helping me with this issue. Please let me know if there's any other information I can provide.

-Kevin

Re: IM 6.9.7 doesn't identify DICOM file

Posted: 2020-01-21T08:23:58-07:00
by snibgo
v6.9.7-4 is quite old. I suggest you try with the current v6 or current v7 versions. Does that work? If that doesn't work, a developer may need to take a look.

Re: IM 6.9.7 doesn't identify DICOM file

Posted: 2020-01-21T08:36:39-07:00
by kzembower
Okay, thanks for your thoughts. I try to stick with the distribution's versions, for convenience, but I've compiled and installed later versions before. I'll work on this later today.

Thanks, again.

-Kevin

Re: IM 7.0.9-17 doesn't identify DICOM file

Posted: 2020-01-21T08:55:19-07:00
by kzembower
No joy:

Code: Select all

$ magick -version
Version: ImageMagick 7.0.9-17 Q16 x86_64 2020-01-19 https://imagemagick.org
Copyright: © 1999-2020 ImageMagick Studio LLC
License: https://imagemagick.org/script/license.php
Features: Cipher DPC OpenMP(3.1) 
Delegates (built-in): bzlib djvu fontconfig freetype gvc jbig jng jpeg lcms lqr lzma openexr png raqm tiff wmf x xml zlib

$ magick convert O0000001 O0000001.jpg
convert: Unsupported JPEG process: SOF type 0xc3 `/tmp/magick-29275-g4jE3ZRHRxW' @ error/jpeg.c/JPEGErrorHandler/342.
convert: no images defined `O0000001.jpg' @ error/convert.c/ConvertImageCommand/3273.
$ 
Am I doing something wrong? Any other thoughts?

Thanks for your advice.

-Kevin

Re: IM 6.9.7 doesn't identify DICOM file

Posted: 2020-01-21T09:08:08-07:00
by snibgo
What is the text output from:

Code: Select all

magick identify O0000001
This might say whether IM recognises the file as DCM format.

Also, what does "exiftool O0000001" say? (Remove any confidential text.)

A web search on the error message finds https://irfanview-forum.de/showthread.php?t=1768
"SOF" (Start of Frame) "C3" (0xc3 means a hexadecimal value "c3") means it is a "lossless" JPG.
I suspect IM can't read lossless JPEG. But a developer might comment.

Re: IM 7.0.9-17 doesn't identify DICOM file

Posted: 2020-01-21T09:48:21-07:00
by kzembower
snibgo, thanks for your efforts.

Here's the output:

Code: Select all

$ magick identify O0000001
identify: Unsupported JPEG process: SOF type 0xc3 `/tmp/magick-30104Q4s_hwLsJ3OS' @ error/jpeg.c/JPEGErrorHandler/342.
And the output of exiftool:

Code: Select all

$ exiftool O0000001ExifTool Version Number         : 10.80
File Name                       : O0000001
Directory                       : .
File Size                       : 2.8 MB
File Modification Date/Time     : 2020:01:17 11:15:12-05:00
File Access Date/Time           : 2020:01:21 09:18:04-05:00
File Inode Change Date/Time     : 2020:01:20 21:37:25-05:00
File Permissions                : rw-------
File Type                       : DICOM
File Type Extension             : dcm
MIME Type                       : application/dicom
File Meta Info Group Length     : 194
File Meta Info Version          : 0 1
Media Storage SOP Class UID     : Computed Radiography Image Storage
Media Storage SOP Instance UID  : 1.3.6.1.4.1.19179.1.1144226186167172161.3.30579.89712
Transfer Syntax UID             : JPEG Lossless, Non-Hierarchical, First-Order Prediction (Process 14-1)
Implementation Class UID        : 1.2.826.0.1.3680043.2.93.0.99
Implementation Version Name     : ERAD_60
Identifying Group Length        : 886
Specific Character Set          : ISO 2022 IR 6
Image Type                      : DERIVED\PRIMARY
SOP Class UID                   : Computed Radiography Image Storage
SOP Instance UID                : 1.3.6.1.4.1.19179.1.1144226186167172161.3.30579.89712
Study Date                      : 2020:01:17
Series Date                     : 2020:01:17
Acquisition Date                : 2020:01:17
Content Date                    : 2020:01:17
Study Time                      : 11:03:10
Series Time                     : 11:07:33
Acquisition Time                : 11:07:34
Content Time                    : 11:07:34
Accession Number                : 14332691
Modality                        : CR
Presentation Intent Type        : FOR PRESENTATION
Manufacturer                    : 
...
Study Description               : XR Orbits For Foreign Body
Procedure Code Sequence         : 
Series Description              : 
Institutional Department Name   : XRAY
Physicians Of Record            : 
Performing Physician Name       : 
Name Of Physician Reading Study : 
Operators Name                  : 
Admitting Diagnoses Description : 
Manufacturers Model Name        : 
Referenced Study Sequence       : 
Referenced Procedure Step Sequence: 
Derivation Description          : Lossless JPEG compression, selection value 1, point transform 0, compression ratio 2.005334
Anatomic Region Sequence        : 
Derivation Code Sequence        : 
...
Acquisition Group Length        : 406
Body Part Examined              : SKULL
KVP                             : 0
Device Serial Number            : 
Software Version                : 1.0.0.86b27
Protocol Name                   : SKULL
Distance Source To Detector     : 0
Distance Source To Patient      : 0
Exposure Time                   : 0
X Ray Tube Current              : 0
Exposure                        : 0
Exposure In Micro Amp Sec       : 0
Image Area Dose Product         : 0.00
Imager Pixel Spacing            : 0.14\0.14
Date Of Last Calibration        : 2019:06:05
Time Of Last Calibration        : 15:01:14
Positioner Type                 : 
View Position                   : PA
Detector Temperature            : 0
Detector Type                   : SCINTILLATOR
Detector Configuration          : AREA
Detector Mode                   : Normal
Detector ID                     : 0
Detector Binning                : 1\1
Detector Manufacturer Name      : Vieworks Co.,Ltd
Detector Manufacturers Model Name: FXRD-1417WB
Exposure Time In Micro Sec      : 0
X Ray Tube Current In Micro Amps: 0
Relationship Group Length       : 186
Study Instance UID              : 1.2.826.0.1.3680043.2.93.9.2.285417568635.2014024924
Series Instance UID             : 1.3.6.1.4.1.19179.1.1144226186167172161.2.30576.89711
Study ID                        : 8413
Series Number                   : 1
Instance Number                 : 1
Patient Orientation             : 
Laterality                      : 
Image Laterality                : 
Image Comments                  : 
Image Presentation Group Length : 256
Samples Per Pixel               : 1
Photometric Interpretation      : MONOCHROME2
Number Of Frames                : 1
Rows                            : 1915
Columns                         : 1532
Pixel Spacing                   : 0.14\0.14
Bits Allocated                  : 16
Bits Stored                     : 14
High Bit                        : 13
Pixel Representation            : Unsigned
Smallest Image Pixel Value      : 0
Largest Image Pixel Value       : 16383
Smallest Pixel Value In Series  : 0
Largest Pixel Value In Series   : 16383
Burned In Annotation            : YES
Pixel Intensity Relationship    : LIN
Pixel Intensity Relationship Sign: -1
Window Center                   : 7788
Window Width                    : 9182
Rescale Intercept               : 0
Rescale Slope                   : 1
Rescale Type                    : US
Lossy Image Compression         : 00
Scheduled Study Start Date      : 2020:01:17
Scheduled Study Start Time      : 10:39:00
...
Scheduled Procedure Step ID     : 70030
Performed Procedure Step Start Date: 2020:01:17
Performed Procedure Step Start Time: 11:07:33
Performed Procedure Step ID     : 
Performed Procedure Step Description: 
Performed Protocol Code Sequence: 
Request Attributes Sequence     : 
Acquisition Context Sequence    : 
Requested Procedure ID          : 70030
...
Requested Procedure Priority    : STAT
Filler Order Num-Imaging Service Req: 14332691
View Code Sequence              : 
Patient Orientation Code Sequence: 
Pixel Data Group Length         : 2926012
Pixel Data                      : (Binary data 0 bytes, use -b option to extract)
Start Of Item                   : (Binary data 2925976 bytes, use -b option to extract)
End Of Sequence                 : 
Shutter Speed                   : 0
$ 
So, it does seem to be a lossless JPEG.

Thanks, again.

-Kevin

Re: IM 6.9.7 doesn't identify DICOM file

Posted: 2020-01-21T10:48:24-07:00
by snibgo
Yes, lossless JPEG. IM uses a JPEG library. Maybe the library can read lossless, and a minor change to IM will use that facility. But if the JPEG library can't read it, that is where the change is needed.

Possibly some other tool, eg djpeg or jpegtopnm, can read the file.

An IM developer may comment.

Re: IM 6.9.7 doesn't identify DICOM file

Posted: 2020-01-21T22:37:03-07:00
by dlemstra
Is it possible to share the file? Feel free to reach out in a private message or email if it isn't.

Re: IM 6.9.7 doesn't identify DICOM file

Posted: 2020-02-06T13:00:41-07:00
by dlemstra
It appears that this type of JPEG is very obscure and not supported by the jpeg library:

Code: Select all

    /* Currently unsupported SOFn types */
    case M_SOF3:                /* Lossless, Huffman */

Re: IM 6.9.7 doesn't identify DICOM file

Posted: 2020-02-06T14:35:38-07:00
by magick
Before JPEG-2000 was readily available, some DICOM files included a lossless JPEG format which required a special patch to the libjpeg delegate library. The patch is likely still available and if you apply it, ImageMagick will likely read you image.

Re: IM 6.9.7 doesn't identify DICOM file

Posted: 2020-02-15T12:56:48-07:00
by kzembower
Hello, magick, thanks for replying. I'm not familiar with patching libraries. I found this link:

https://stackoverflow.com/questions/383 ... sless-jpeg

Is this related to what you're describing?

Any beginner hints on how to patch a library?

Thanks, again.

-Kevin