在R中打开dicom文件时出错

时间:2014-09-06 15:13:13

标签: r dicom

我正在尝试使用以下代码在R中打开dicom文件:

library(oro.dicom)
dcmobject <- readDICOMFile(filename)

有些文件正常打开,我可以显示它们。但是,某些文件会出现不同类型的错误:

第一个错误:对于某些人,我收到错误:

Error in file(con, "rb") : cannot open the connection

第二个错误:在其他情况下,我在使用dicom文件时出现以下错误:http://www.barre.nom.fr/medical/samples/files/OT-MONO2-8-hip.gz

Error in readDICOMFile(filename) : DICM != DICM

第三个错误:此文件出现以下错误:http://www.barre.nom.fr/medical/samples/files/CT-MONO2-16-chest.gz

Error in parsePixelData(fraw[(132 + dcm$data.seek + 1):fsize], hdr, endian,  : 
  Number of bytes in PixelData not specified

第四个错误:一个dicom文件出现以下错误:

Error in rawToChar(fraw[129:132]) : embedded nul in string: '\0\0\b'

如何摆脱这些错误并在R?

中显示这些图像

编辑:

此示例文件提供错误'embed nul in string ...': http://www.barre.nom.fr/medical/samples/files/CT-MONO2-12-lomb-an2.gz

> jj = readDICOMFile( "CT-MONO2-12-lomb-an2.dcm" )
Error in rawToChar(fraw[129:132]) : embedded nul in string: '3\0\020'

1 个答案:

答案 0 :(得分:1)

此故障单中突出显示了四个不同的错误:

  1. Error in file(con, "rb") : cannot open the connection
  2. 这不是 oro.dicom 的问题,只是文件路径和/或名称被错误指定的事实。

    1. Error in readDICOMFile(filename) : DICM != DICM
    2. 该文件不是有效的DICOM文件。也就是说,DICOM标准第10部分的第7.1节(可在http://dicom.nema.org获得)指定应该有(a)长度为128字节的文件预采样和(b)四字节DICOM前缀“DICM”, DICOM文件的开头。 OT-MONO2-8-hip文件不符合此标准。可以使用debug=TRUE输入参数

      进一步调查此问题
      > dcm <- readDICOMFile("OT-MONO2-8-hip.dcm", debug=TRUE)
      # First 128 bytes of DICOM header =
        [1] 08 00 00 00 04 00 00 00 b0 00 00 00 08 00 08 00 2e 00 00 00 4f 52 49 47 49 4e 41 4c 5c 53 45
       [32] 43 4f 4e 44 41 52 59 5c 4f 54 48 45 52 5c 41 52 43 5c 44 49 43 4f 4d 5c 56 41 4c 49 44 41 54
       [63] 49 4f 4e 20 08 00 16 00 1a 00 00 00 31 2e 32 2e 38 34 30 2e 31 30 30 30 38 2e 35 2e 31 2e 34
       [94] 2e 31 2e 31 2e 37 00 08 00 18 00 1a 00 00 00 31 2e 33 2e 34 36 2e 36 37 30 35 38 39 2e 31 37
      [125] 2e 31 2e 37
      Error in readDICOMFile("OT-MONO2-8-hip.dcm", debug = TRUE) : DICM != DICM
      

      很明显,前128个字节包含信息。现在可以使用参数skipFirst128=FALSEDICM=FALSE开始从文件开头读取信息

      dcm <- readDICOMFile("OT-MONO2-8-hip.dcm", skipFirst128=FALSE, DICM=FALSE)
      image(t(dcm$img), col=grey(0:64/64), axes=FALSE, xlab="", ylab="")
      

      OT-MONO2-8-hip

        3。
        Error in parsePixelData(fraw[(132 + dcm$data.seek + 1):fsize], hdr, endian,  : 
          Number of bytes in PixelData not specified
        

        文件CT-MONO2-16-chest.dcm使用JPEG压缩编码。 R包 oro.dicom 不支持压缩。

        1. Error in rawToChar(fraw[129:132]) : embedded nul in string: '\0\0\b'
        2. 我必须推测,因为该文件不可用于直接询问。此问题与作为DICOM标准的一部分检查“DICM”字符有关。如果失败,则可以假定该文件不是有效的DICM文件。我将在 oro.dicom 的未来版本中考虑使此错误更具信息性。

          编辑:感谢您提供相应文件的链接。该文件采用“ARC-NEMA 2”格式。 R包 oro.dicom 尚未设计为读取此类文件。我修改了代码以改进错误跟踪。

相关问题