3
votes

I have a question regarding DICOM standard and libjpeg library. In the DICOM standard, there are, among others, Transfer Syntax:

JPEG Lossless, Nonhierarchical, First- Order Prediction (Processes 14 [Selection Value 1]): Default Transfer Syntax for Lossless JPEG Image Compression

As far as I know, this Transfer Syntax corresponds with JPEG-1 Lossles format. I started researching libjpeg library and I found out that it doesn't support (?) Lossless JPEG, as stated here: JPEG Lossless in DICOM

Also, in libjpeg documentation there is a part saying:

Unsupported ISO options include: * Hierarchical storage * Lossless JPEG * DNL marker * Nonintegral subsampling ratios

However, in library code, in compression parameters structure jpeg_compress_struct there is a field:

boolean lossless;       /* TRUE=lossless encoding, FALSE=lossy */

What does is all mean? I'm really confused. Could anyone describe which standards of JPEG are supported by the library? Furthermore, how to set parameters for compression to be compatible with DICOM JPEG Lossless standard?

1
It appears that libjpeg supports the lossless mode (JPEG-LS) which is different from the lossless JPEG you're working with. I haven't seen any implementations of this codec except in DICOM libraries. I wrote my own and it's actually very simplistic.BitBank
Are you sure libjpeg supports JPEG-LS? I think it's later modification of JPEG and libjpeg - as far as i know - supports the "basic" oneArtyshan
I'm not 100% sure, but I didn't see anything that looked like it would help you. The truth is that to decode the DICOM lossless JPEG requires about 100 lines of C code (for the specific lossless algorithm). It's similar to PNG with a filter method and delta values encoded with max-length 16 Huffman codes.BitBank
Could you please tell me, what were you relying on writing your own decompressor? If it is simple, i would do it on my own rather than investigate how to use specific libraries to do it for me :)Artyshan

1 Answers

6
votes

Let's do some clarifications here first. What you should start with is the famous JPEG 6b (aka 62) release. Start by reading the code from here. You'll discover that there is no mention to your boolean lossless. libjpeg 6b is the reference codebase that served two forks:

  • Guido Vollbeding (IJG maintainer): libjpeg 7 and up with the famous SmartScale extension
  • dcommander libjpeg-turbo, in particular reads the comments from here.

So if this is the libjpeg you were talking about, then yes it does not support the lossless mode specified in the standard. The lossless patch was created by Ken Murchison, and you should still be able to find it (eg. here). It should apply directly over libjpeg 6b. If you do not want to patch the lib yourself, have a quick look at GDCM and or DCMTK, since they are both using a convenient copy of libjpeg + the famous lossless patch (with some further patch, thanks to DCMTK team).

At this point this should answer your question.

For further details on libjpeg (IJG) and libjpeg-turbo informations I suggest you read informations from:


In case you are still reading, I sugest you also have a quick look at another library (purposely) also called libjpeg, see it here at github. In particular go over the README file (here). And you'll discover that this libjpeg is a full implementation of ITU 81 (lossy, lossless, 8/12/16bits and even hierarchical all in one single code, without the need to do multiple compilations !).

And for completeness, I found that the following links were very usefull: