我想使用 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, ¶m_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 我有错误“非法调用可能是错误的参数”......但是为什么?!?