3

我在 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, &param);

从这个数据集开始,我想访问压缩数据

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
4

2 回答 2

1

在 DICOM 中,压缩帧的存储方式与像素数据元素 (7FE0, 0010) 下的未压缩(本机)帧不同。这是DICOM中压缩图像编码的基本概念。

封装后的像素流(压缩图像数据)在顶层数据集的像素数据元素(7FE0,0010)下被分割成一个或多个片段(Items)。在封装编码中,像素数据元素是一个序列,它包含两个或多个项目元素(片段),每个片段(项目元素)都有自己的显式长度。此外,封装格式支持单帧和多帧图像编码。一个框架可以完全包含在单个片段(项目)中,也可以跨越多个片段。封装像素流的片段序列由定界符终止。
在编码的像素数据流之前的项目序列中的第一个项目(FFFE,E000)通常是空的,或者可能包含一个基本偏移表项目,该项目保存每个帧的第一个片段的项目标签的第一个字节的字节偏移量在项目序列中。

因此,当您想从 DICOM 数据集中提取压缩的像素流时,您需要跳过 Pixel Data 序列下的第一个 Item 元素。我希望这有助于理解您引用的文档。请参阅 DICOM 标准 PS 3.5 附录 A 了解更多信息。

于 2015-02-02T16:32:14.187 回答
0

好吧,也许我已经解决了这个问题。我已添加说明

dataset->removeAllButCurrentRepresentations(); 

在访问压缩的像素数据之前。

我也可以 PixelData->removeAllButCurrentRepresentations();代替之前的指令,并以相同的方式工作......

但我真的不明白为什么它会起作用....你能解释一下吗?谢谢

于 2015-02-02T14:22:55.240 回答