我想使用DCMTK解压缩DICOM文件,如本例http://support.dcmtk.org/docs/mod_dcmjpeg.html 但我的问题是我不想加载文件。
我有一个数组里面有PixelData值Compressed。我试过这种方式但是没有用。
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,我会收到错误“非法调用可能错误的参数”......但为什么?!?
答案 0 :(得分:0)
好吧,多亏了DICOM官方论坛,我发现了
Image2Dcm::insertEncapsulatedPixelData()
功能,完全符合我的需要。