DClunies and DICOM samples, fragment headers

Sep 15, 2012 at 9:58 PM


I have managed to extract the JPEG-LS things from DClunies sample files. The bad part is, that they cant be decoded. (Even real dicoms incoming from CTs have a similar issue)

Please, have a look at those files (in the link) and tell me what am I doing wrong, if you have any idea. I will appreciate it very much.

Anyway Iam, too, interested in jpeg-ls decoding, so I have sent a mail to dclunie (Attached below). As soon as he responses, i will post his answer too.

(BTW I saw a similar problem about fragmented headers here, so Iam posting the link to the extracted dclunies files for you too. If my dicom extractor is OK, I can help you too - feel free to send me another dicom samples to khajj@seznam.cz, i will extract the fragment headers for you)


Link to 2shared:


Copy of mail to DClunie:


i was studying your site for JPEG-LS decoding of DICOM images for work to school. Thank you for resources.
But I have a problem - after extracting jpeg-ls raw data from DICOM images (like removing the fragment headers) by a proper dicom parser, i send the JPEG-LS coded images through 2 decoders - CharLS and "original HP loco code".
The problem is, that every sample image (excluding "mr1") threw an error (like premature end of file, failed assertion on an constant etc) on both implementations (charLS,loco).
I would like to make an functional jpeg-ls decoder.
Can you please check, if I extracted the data right? (probably yes, thats the reason why mr1 succeeded)
What JPEG-LS decoder do you personally use? (Can you send me the code please?)
Attached link to 2shared, in the zip file there are included
1) original dicom images (yours)
2) extracted pure jpeg-ls data (named after serie name+.bin) - I would be gratefull, if you check them against your original images, maybe the error.
3) mr1out.bin result after completing loco code
4) my sample project of loco code in BCB5 (that is not currently downloadable by the way)
Thank you wery much,
Martin Holecek


Apr 14, 2014 at 2:40 AM
Decoding & Reading DICOM Image
Solved problem? I also met the similar issue for decoding DICOM images.
Apr 14, 2014 at 6:05 AM
Yes problem solved. Please do not post your spam here.

How to solve:

Code sample - while reading the header, store all the chunk data positions and lengths in an array

else if ( fElement == elPixelData || (fElement==elItem && fContext==elPixelData))//dodelat: bacha, spravny cteni dicomu ma mit moznost znat kontext elItemu,coz bude prave pixelData (=tag nadtim)
        if (fContext==elNone) //first time
          InitPixelProcessValues();    // setting fImageType, fBytesPerPixel, SetWinWidthHU() a SetWinCenterHU()
          fExtendedDicomRead=((fImageType==ivtJPEGLS || fImageType==ivtJPEGLOSSLESSRGB8 || fImageType==ivtJPEGLOSSLESSBW8) && fNumberOfFrames<=1);

        if (fExtendedDicomRead)
          if (fPixelDataLength>0)

then using decode this way:

if (fTransferSyntaxUID=="1.2.840.10008." || fTransferSyntaxUID=="1.2.840.10008.")
{  //CharLS way

  JlsParameters xHeadInfo;
  JLS_ERROR jlsErr;
    jlsErr=JpegLsReadHeader(fRawData->Data, fSize, &xHeadInfo);

    if (jlsErr!=OK) return;

    //oprava co kdyz mel dicom neco jinyho v hlavicce:
    switch (fImageType) 
      case ivtJPEGLOSSLESSRGB8:
      case ivtJPEGLOSSLESSBW8:
      default: break;


    int xBPP=FmtImgBPP(fInternalFormat);
    if (fBytesAlloc>=0 && fBytesAlloc<fColumns*fRows*xBPP)
      *pPtrThisMem = (BYTE *)realloc(*pPtrThisMem,fBytesAlloc);


    jlsErr=JpegLsDecode(*pPtrThisMem, fBytesAlloc, fRawData->Data, fSize, &xHeadInfo);