2015-02-10 100 views
0

我想使用DCMTK解壓縮DICOM文件(如本例中所示)http://support.dcmtk.org/docs/mod_dcmjpeg.html 但我的問題是我不想加載文件。從PixelData值(DCMTK)開始解壓縮JPEG DICOM圖像

我有一個數組裏面有壓縮的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框架尺寸,而不是我有錯誤「非法調用也許錯參數」 ......但爲什麼?!?

+1

0xcd 0xcd 0xcd是在調試模式下的未初始化數據(對於VS,至少gcc使用0xcc)。見https://stackoverflow.com/questions/370195/when-and-why-will-an-os-initialise-memory-to-0xcd-0xdd-etc-on-malloc-free-new – sashoalm 2015-02-10 16:29:12

+0

謝謝,現在我知道了這意味着PixelData是未初始化的...我需要了解爲什麼我有'非法呼叫'狀態 – GiordiX 2015-02-10 16:46:18

+0

我不能幫助你做更多的事情。我建議你重寫你的問題,因爲你知道cdcd的含義,希望別人會來。 – sashoalm 2015-02-10 17:02:34

回答

0

好吧,感謝DICOM官方論壇,我發現了功能,這正是我所需要的功能。