从 PixelData 值开始解压缩 JPEG DICOM 图像 (DCMTK)

Decompress a JPEG DICOM image starting from PixelData values (DCMTK)

我想像本例中那样使用 DCMTK 解压缩 DICOM 文件 http://support.dcmtk.org/docs/mod_dcmjpeg.html 但是我的问题是我不想加载文件。

我有一个数组,里面有压缩的 PixelData 值。我试过这种方法,但没有用。

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();

文件test.dcm已创建但我无法打开它(免费的Dicom Viewr软件崩溃)并且尺寸等于压缩文件,所以解码程序不起作用......什么是我的错误吗?

我也试过:

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);
        }

getUncompressedFrame return 错误 "Too many bytes requested" 如果使用 frameSize - 1 而不是 frameSize 我有错误 "Illegal call perhaps wrong parameter"... 但为什么?!?

嗯,感谢DICOM官方论坛,我发现了 Image2Dcm::insertEncapsulatedPixelData() 功能,正是我所需要的。