我想使用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
的不是框架尺寸我有错误“非法调用也许错参数” ......那是为什么?!?
好吧,多亏了DICOM官方论坛,我才发现了Image2Dcm::insertEncapsulatedPixelData()
功能,正是我需要的功能。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句