[英]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, ¶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我有錯誤“非法調用也許是錯誤的參數”...但為什么?!?
好吧,多虧了DICOM官方論壇,我發現了Image2Dcm::insertEncapsulatedPixelData()
函數,它完全符合我的需要。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.