我在 DCMTK 3.6.1 库中苦苦挣扎,现在我在一种常见情况下被阻止:访问 DICOM 图像的压缩数据像素。
正如图书馆的作者在这里建议的那样http://support.dcmtk.org/redmine/projects/dcmtk/wiki/Howto_AccessingCompressedData,这是获取压缩数据的正确方法。
此代码有效,但它们从文件开始创建数据集。在我的代码中,我的数据集以这种方式填充
status = data->putAndInsertUint8Array(DCM_PixelData, pSource, sizeBuffer);
其中 pSource 包含我未压缩的像素数据。在此之后,我添加 Image DICOM 标签(第 28 组)并使用
status = data->chooseRepresentation(EXS_JPEGProcess14SV1, ¶m);
从这个数据集开始,我想访问压缩数据
status = data->findAndGetElement(DCM_PixelData, element);
DcmPixelData *dpix = NULL;
dpix = OFstatic_cast(DcmPixelData*, element);
/* Since we have compressed data, we must utilize DcmPixelSequence
in order to access it in raw format, e. g. for decompressing it
with an external library.
*/
DcmPixelSequence *dseq = NULL;
E_TransferSyntax xferSyntax = EXS_Unknown;
const DcmRepresentationParameter *rep = NULL;
// Find the key that is needed to access the right representation of the data within DCMTK
dpix->getOriginalRepresentationKey(xferSyntax, rep);
// Access original data representation and get result within pixel sequence
status = dpix->getEncapsulatedRepresentation(xferSyntax, rep, dseq);
Uint32 length;
if (status.good())
{
DcmPixelItem* pixitem = NULL;
// Access first frame (skipping offset table)
dseq->getItem(pixitem, 1);
if (pixitem == NULL)
return 1;
Uint8* pixData = NULL;
// Get the length of this pixel item (i.e. fragment, i.e. most of the time, the lenght of the frame)
length = pixitem->getLength();
if (length == 0)
return 1;
// Finally, get the compressed data for this pixel item
status = pixitem->getUint8Array(pixData);
// Metto i Pixel Data compressi su pSorgCompr
pSorgCompr = (LPBYTE)pixData;
}
////////////////////////////
DJEncoderRegistration::cleanup();
DJDecoderRegistration::cleanup();
但行状态 = dpix->getEncapsulatedRepresentation(xferSyntax, rep, dseq); 重新调整失败并出现错误“找不到像素表示”,我不明白为什么。
奇怪的是,如果在访问压缩数据之前,我将压缩文件保存为fileformat.saveFile("compressedPixelData.dcm", EXS_JPEGProcess14SV1); 接下来我使用result = fileformat.loadFile("compressedPixelData.dcm");加载文件 ,一切正常
好像loadfile函数解决了问题,不知道怎么解决的,可能是填了一些标签?
我在调用 chooseRepresentation 函数之前填写的标签是:
- DCM_Rows
- DCM_列
- DCM_BitsStored
- DCM_SamplesPerPixel
- DCM_PlanarConfiguration
- DCM_HighBit
- DCM_BitsAllocated
- DCM_PixelRepresentation
- DCM_RescaleIntercept
- DCM_RescaleSlope
- DCM_PhotometricInterpretation
- DCM_PixelAspectRatio
- DCM_ImagerPixelSpacing
- DCM_PixelSpacing