繁体   English   中英

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

[英]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返回错误“请求的字节太多”如果使用frameSize - 1而不是frameSize我有错误“非法调用也许是错误的参数”...但为什么?!?

好吧,多亏了DICOM官方论坛,我发现了Image2Dcm::insertEncapsulatedPixelData()函数,它完全符合我的需要。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM