【问题标题】:GDCM library cannot read dicom file in C#GDCM 库无法读取 C# 中的 dicom 文件
【发布时间】:2016-09-22 10:56:36
【问题描述】:

我尝试使用 GDCM 库使用此代码读取 DICOM 文件:

gdcm.ImageReader imagereader = new gdcm.ImageReader();
imagereader.SetFileName(@"E:\sample_success.dcm");
if (!imagereader.Read()) throw new Exception("Cannot read dicom file!");

对于“sample_success.dcm”文件,我可以很好地阅读该文件(sample_success.png)。 但是使用“sample_failed.dcm”文件,GDCM 会抛出异常,因为它无法读取它。我尝试使用其他 DICOM 查看器(例如 Radiant)打开该文件,它可以正常工作。我的 GDCM 版本有问题吗?为什么它无法读取?

我使用 GDCM 2.6.5。请找到两个样本here.

【问题讨论】:

    标签: c# dicom gdcm


    【解决方案1】:

    您的文件在偏移量0x1480aa(在像素数据属性中的某个位置)之后包含垃圾(一堆二进制 0)。如果没有正确报告错误,您对工具包有什么期望?

    根据设计,GDCM 仍会加载任何内容,直到出现错误。因此,如果您在代码中删除 new Exception,您可以决定(例如)将 imagereader.GetFile() 传递给 gdcm::Writer 并将文件重写为干净的 DICOM。

    顺便说一句,我无法访问Radiant 软件,但我觉得很奇怪,在这种情况下它并不表示错误。

    我检查过 DCMTK 和 dicom3tools,它们都报告了解析问题。

    使用 gdcm 命令行工具,您几乎可以使用以下方法重写文件:

    $ gdcmconv -I sample_failed.dcm sample_failed_correct.dcm
    

    由于您的输入数据集无效,GDCM(错误地)相信看到一个属性,您可以使用以下方法将其删除:

    $ gdcmanon --dumb --remove 0,0 sample_failed_correct.dcm sample_failed_correct_clean.dcm
    

    然后:

    $ gdcminfo sample_failed_correct.dcm 
    MediaStorage is 1.2.840.10008.5.1.4.1.1.3.1 [Ultrasound Multi-frame Image Storage]
    TransferSyntax is 1.2.840.10008.1.2.4.50 [JPEG Baseline (Process 1): Default Transfer Syntax for Lossy JPEG 8 Bit Image Compression]
    NumberOfDimensions: 3
    Dimensions: (800,600,21)
    SamplesPerPixel    :3
    BitsAllocated      :8
    BitsStored         :8
    HighBit            :7
    PixelRepresentation:0
    ScalarType found   :UINT8
    PhotometricInterpretation: YBR_FULL_422
    PlanarConfiguration: 0
    TransferSyntax: 1.2.840.10008.1.2.4.50
    Origin: (0,0,0)
    Spacing: (0.0106324,0.0106324,1)
    DirectionCosines: (1,0,0,0,1,0)
    Rescale Intercept/Slope: (0,1)
    Orientation Label: AXIAL
    

    这与像素数据中的片段数有效:

    $ gdcmdump sample_failed_correct.dcm | grep Item | grep "ff.d8" | wc
         21     126    2856
    

    【讨论】:

    • 如何使用代码重写文件?我试图将imagereader.GetFile() 传递给 ImageWriter,结果文件为空。由于 'imagereader.Read()' 失败,它不会返回任何图像。
    • @rg11 更新了我的答案。只需将gdcm::File 传递给gdcm::Writer
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-18
    相关资源
    最近更新 更多