0

我尝试使用以下代码使用 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。请在此处找到这两个示例

4

1 回答 1

1

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

按照设计,GDCM 仍然会加载它可以加载的任何内容,直到出现错误。因此,如果您new Exception在代码中删除您的,您可以决定(例如)将 传递imagereader.GetFile()给 agdcm::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
于 2016-09-22T12:06:29.867 回答