0
votes

I want to decompress a DICOM file using DCMTK like in this example http://support.dcmtk.org/docs/mod_dcmjpeg.html But my problem is that I don't want to load a file.

I have an array which inside there are the PixelData values Compressed. I have tried in this way but doesn't work.

DJDecoderRegistration::registerCodecs();
DJEncoderRegistration::registerCodecs();

DcmFileFormat fileformat;
DJ_RPLossless param_lossless;

DcmDataset *pDataset = fileformat.getDataset();
pDataset->chooseRepresentation(EXS_JPEGProcess14SV1, &param_lossless);

BYTE*   pBufferImg = (BYTE*)pArray->ImgDicom.GetAt(0); //here I have my PixelData
//I put it into my dataset
pDataset->putAndInsertUint8Array(DCM_PixelData, pBufferImg, pArray->NumByteImg);
//decompress
OFCondition status = pDataset->chooseRepresentation(EXS_LittleEndianExplicit, NULL); //status is OK
...
//add all the tags like Rows, Columuns, BitStored, etc
...
if (pDataset->canWriteXfer(EXS_LittleEndianExplicit))
{
   fileformat.saveFile("test.dcm", EXS_LittleEndianExplicit);
}

DJDecoderRegistration::cleanup(); // deregister JPEG codecs
DJEncoderRegistration::cleanup();

The file test.dcm is created but I can't open it (free Dicom Viewr software crash) and the dimension is equal to the compressed file, so the decode procedure doesn't work... What is my error?

I have also tried:

DcmElement * dummyElem;
        pDataset->findAndGetElement(DCM_PixelData, dummyElem);

        Uint32 frameSize;
        dummyElem->getUncompressedFrameSize(pDataset, frameSize);

        BYTE* buf = new BYTE[frameSize];
        OFString decompressedColorModel;
        Uint32 startFragment = 0;

        dummyElem->getUncompressedFrame(pDataset, 0, startFragment, buf, frameSize, decompressedColorModel);

        pDataset->putAndInsertUint8Array(DCM_PixelData, (const Uint8*)buf, frameSize);
        pDataset->removeAllButCurrentRepresentations();
        //check if everything went well
        if (pDataset->canWriteXfer(EXS_LittleEndianExplicit))
        {
            fileformat.saveFile("test.dcm", EXS_LittleEndianExplicit);
        }

The getUncompressedFrame return the error "Too many bytes requested" If use frameSize - 1 instead of frameSize I have the error "Illegal call perhaps wrong parameter"... but why?!?

1
0xcd 0xcd 0xcd is for uninitialized data in debug mode (for VS at least, gcc uses 0xcc). See stackoverflow.com/questions/370195/…sashoalm
Thanks, Now I know that means that PixelData is uninitialized... I need to understand why I have the Illegal call statusGiordiX
I can't help you further than that. I advice you to rewrite your question since you know do know what cdcd means, and hopefully someone else will come by.sashoalm
I think is not correct ask again, I hope someone can read the question :SGiordiX
You do realize there's an edit link, right? You can edit your question without asking a new one.sashoalm

1 Answers

0
votes

Well, thanks to the DICOM official forum, I have discovered the Image2Dcm::insertEncapsulatedPixelData() function, that do exactly what I need.