读取DICOM文件时出错:未指定PixelData中的字节数

时间:2016-06-27 18:50:17

标签: r dicom

我在readDICOMFile中使用R来阅读DICOM文件如下:

dcmImages <- readDICOMFile("/home/darshil/Downloads/BREBIX/CT10 ponction foie/DEF. VEINEUX - 107205/IM-0001-0001.dcm",debug = TRUE, pixelData = FALSE)

但是,我收到以下错误:

  

parsePixelData出错(fraw [(bstart + dcm $ data.seek):fsize],hdr,endian,:
  未指定PixelData中的字节数; guess = 1

如果我放pixelData=FALSE,则只能读取标题。但我也想要Image部分。我正在使用here中的标准dicom文件。 (我现在正在尝试“BREBIX”数据库,但其他数据库也会出现同样的错误。)

有什么问题?我找不到任何关于此错误的参考。

debug=TRUE的完整输出:

# First 128 bytes of DICOM header =
  [1] 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
 [27] 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
 [53] 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
 [79] 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
[105] 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
# DICM = TRUE
#   0002    0000    GroupLength UL  UL  4   190 
#   0002    0001    FileMetaInformationVersion  OB  OB  2       
#   0002    0002    MediaStorageSOPClassUID UI  UI  26  1.2.840.10008.5.1.4.1.1.2   
#   0002    0003    MediaStorageSOPInstanceUID  UI  UI  42  1.2.840.113704.1.111.2864.1161868417.2891   
#   0002    0010    TransferSyntaxUID   UI  UI  22  1.2.840.10008.1.2.4.91  
#   0002    0012    ImplementationClassUID  UI  UI  22  1.3.6.1.4.1.19291.2.1   
#   0002    0013    ImplementationVersionName   SH  SH  10  OSIRIX001   
#   0002    0016    SourceApplicationEntityTitle    AE  AE  6   OsiriX  
#   0008    0005    SpecificCharacterSet    CS  CS  10  ISO_IR 100  
#   0008    0008    ImageType   CS  CS  28  ORIGINAL PRIMARY AXIAL HELIX    
#   0008    0012    InstanceCreationDate    DA  DA  8   20061026    
#   0008    0013    InstanceCreationTime    TM  TM  14  151337.000000   
#   0008    0016    SOPClassUID UI  UI  26  1.2.840.10008.5.1.4.1.1.2   
#   0008    0018    SOPInstanceUID  UI  UI  42  1.2.840.113704.1.111.2864.1161868417.2891   
#   0008    0020    StudyDate   DA  DA  8   20061026    
#   0008    0022    AcquisitionDate DA  DA  8   20061026    
#   0008    0023    ContentDate DA  DA  8   20061026    
#   0008    0030    StudyTime   TM  TM  14  141819.000000   
#   0008    0032    AcquisitionTime TM  TM  14  140519.000000   
#   0008    0033    ContentTime TM  TM  14  140519.583000   
#   0008    0050    AccessionNumber SH  SH  2   0   
#   0008    0060    Modality    CS  CS  2   CT  
#   0008    0070    Manufacturer    LO  LO  8   Philips 
#   0008    0080    InstitutionName LO  LO  4   hY9 
#   0008    0090    ReferringPhysiciansName PN  PN  10  9D2n76uYj   
#   0008    1010    StationName SH  SH  6   ctrad   
#   0008    1030    StudyDescription    LO  LO  18  CT10 ponction foie  
#   0008    1032    ProcedureCodeSequence   SQ  SQ  64  Sequence    
#   FFFE    E000    Item    UN  UN  0        (0008,1032)
#   0008    0100    CodeValue   SH  SH  8   CTPFOIE  (0008,1032)
#   0008    0102    CodingSchemeDesignator  SH  SH  6   XPLORE   (0008,1032)
#   0008    0104    CodeMeaning LO  LO  18  CT10 ponction foie   (0008,1032)
#   0008    103E    SeriesDescription   LO  LO  12  DEF. VEINEUX    
#   0008    1040    InstitutionalDepartmentName LO  LO  10  Radiologie  
#   0008    1090    ManufacturersModelName  LO  LO  14  Mx8000 IDT 16   
#   0008    1111    ReferencedPerformedProcedureStepSequence    SQ  SQ  88  Sequence    
#   FFFE    E000    Item    UN  UN  0        (0008,1111)
#   0008    1150    ReferencedSOPClassUID   UI  UI  24  1.2.840.10008.3.1.2.3.3  (0008,1111)
#   0008    1155    ReferencedSOPInstanceUID    UI  UI  40  1.2.840.113704.1.111.2656.1161865075.16  (0008,1111)
#   0010    0010    PatientsName    PN  PN  6   BREBIX  
#   0010    0020    PatientID   LO  LO  6   XsaDYa  
#   0010    1010    PatientsAge AS  AS  4   000Y    
#   0018    0010    ContrastBolusAgent  LO  LO  8   CONTRAST    
#   0018    0022    ScanOptions CS  CS  6   HELIX   
#   0018    0050    SliceThickness  DS  DS  4   2.0 
#   0018    0060    kVp DS  DS  4   120 
#   0018    0088    SpacingBetweenSlices    DS  DS  4   1.0 
#   0018    0090    DataCollectionDiameter  DS  DS  4   340 
#   0018    1020    SoftwareVersions    LO  LO  6   3.2.0   
#   0018    1030    ProtocolName    LO  LO  24  THORAX-ABD 3 4 Thorax Hx    
#   0018    1100    ReconstructionDiameter  DS  DS  4   340 
#   0018    1120    GantryDetectorTilt  DS  DS  2   0   
#   0018    1130    TableHeight DS  DS  4   137 
#   0018    1140    RotationDirection   CS  CS  2   CW  
#   0018    1151    XrayTubeCurrent IS  IS  4   360 
#   0018    1152    Exposure    IS  IS  4   200 
#   0018    1160    FilterType  SH  SH  2   B   
#   0018    1210    ConvolutionKernel   SH  SH  2   B   
#   0018    5100    PatientPosition CS  CS  4   FFS 
#   0020    000D    StudyInstanceUID    UI  UI  42  2.16.840.1.113669.632.20.1211.10000330985   
#   0020    000E    SeriesInstanceUID   UI  UI  38  1.2.840.113704.1.111.4848.1161868385.1  
#   0020    0010    StudyID SH  SH  4   8369    
#   0020    0011    SeriesNumber    IS  IS  6   107205  
#   0020    0013    InstanceNumber  IS  IS  2   1   
#   0020    0032    ImagePositionPatient    DS  DS  14  -180 -52 1479   
#   0020    0037    ImageOrientationPatient DS  DS  12  1 0 0 0 1 0 
#   0020    0052    FrameOfReferenceUID UI  UI  38  1.2.840.113704.1.111.4492.1161865106.3  
#   0020    1041    SliceLocation   DS  DS  8   -493.50 
#   0020    4000    ImageComments   LT  LT  58  JPEG 2000 lossless - Version 4.0.2 (c) Image Devices GmbH   
#   0028    0002    SamplesperPixel US  US  2   1   
#   0028    0004    PhotometricInterpretation   CS  CS  12  MONOCHROME2 
#   0028    0010    Rows    US  US  2   512 
#   0028    0011    Columns US  US  2   512 
#   0028    0030    PixelSpacing    DS  DS  20  0.6640625 0.6640625 
#   0028    0100    BitsAllocated   US  US  2   16  
#   0028    0101    BitsStored  US  US  2   12  
#   0028    0102    HighBit US  US  2   11  
#   0028    0103    PixelRepresentation US  US  2   0   
#   0028    1050    WindowCenter    DS  DS  12  00050 00050 
#   0028    1051    WindowWidth DS  DS  12  00350 00350 
#   0028    1052    RescaleIntercept    DS  DS  6   -1000   
#   0028    1053    RescaleSlope    DS  DS  2   1   
#   0028    2110    LossyImageCompression   CS  CS  2   01  
#   0028    2112    LossyImageCompressionRatio  DS  DS  8   5.896176    
#   0032    1032    RequestingPhysician PN  PN  16  MOSIMANN Pascal 
#   0032    1060    RequestedProcedureDescription   LO  LO  18  CT10 ponction foie  
#   0040    0007    ScheduledProcedureStepDescription   LO  LO  18  CT10 ponction foie  
#   0040    0008    ScheduledProtocolCodeSequence   SQ  SQ  64  Sequence    
#   FFFE    E000    Item    UN  UN  0        (0040,0008)
#   0008    0100    CodeValue   SH  SH  8   CTPFOIE  (0040,0008)
#   0008    0102    CodingSchemeDesignator  SH  SH  6   XPLORE   (0040,0008)
#   0008    0104    CodeMeaning LO  LO  18  CT10 ponction foie   (0040,0008)
#   0040    0009    ScheduledProcedureStepID    SH  SH  12  A10026674234    
#   0040    0254    PerformedProcedureStepDescription   LO  LO  18  CT10 ponction foie  
#   0040    0260    PerformedProtocolCodeSequence   SQ  SQ  64  Sequence    
#   FFFE    E000    Item    UN  UN  0        (0040,0260)
#   0008    0100    CodeValue   SH  SH  8   CTPFOIE  (0040,0260)
#   0008    0102    CodingSchemeDesignator  SH  SH  6   XPLORE   (0040,0260)
#   0008    0104    CodeMeaning LO  LO  18  CT10 ponction foie   (0040,0260)
#   0040    0275    RequestAttributesSequence   SQ  SQ  150 Sequence    
#   FFFE    E000    Item    UN  UN  0        (0040,0275)
#   0040    0007    ScheduledProcedureStepDescription   LO  LO  18  CT10 ponction foie   (0040,0275)
#   0040    0008    ScheduledProtocolCodeSequence   SQ  SQ  64  Sequence     (0040,0275)
#   FFFE    E000    Item    UN  UN  0        (0040,0275) (0040,0008)
#   0008    0100    CodeValue   SH  SH  8   CTPFOIE  (0040,0275) (0040,0008)
#   0008    0102    CodingSchemeDesignator  SH  SH  6   XPLORE   (0040,0275) (0040,0008)
#   0008    0104    CodeMeaning LO  LO  18  CT10 ponction foie   (0040,0275) (0040,0008)
#   0040    0009    ScheduledProcedureStepID    SH  SH  12  A10026674234     (0040,0275)
#   0040    1001    RequestedProcedureID    SH  SH  12  A10026674233     (0040,0275)
#   0040    1001    RequestedProcedureID    SH  SH  12  A10026674233    
#   7FE0    0010    PixelData   OB  OW  -1  PixelData   
##### Reading PixelData (7FE0,0010) #####
Error in parsePixelData(fraw[(bstart + dcm$data.seek):fsize], hdr, endian,  : 
  Number of bytes in PixelData not specified; guess = 1

修改

我查看了源代码。结果错误来自parsePixelData使用的函数readDICOMFile。错误是由于以下几行:

length <- as.numeric(with(hdr, length[name == "PixelData" & 
            sequence == ""]))
        if (length <= 0) {
            guess <- 1
            stop(paste("Number of bytes in PixelData not specified; guess =", 
                guess))
        }

具体来说,以下结果给出了“-1”作为答案,这导致了问题:

> with(dcmImages$hdr, length[name == "PixelData"])
[1] "-1"

现在,我该如何处理它?由于我使用的是标准文件(上面给出的链接),它不应该导致问题,对吗?

2 个答案:

答案 0 :(得分:3)

根据DICOM转储的传输语法,图像被封装,用于图像的压缩是JPEG 2000可逆的(标签0002:0010- TransferSyntaxUID - 1.2.840.10008.1.2.4.91)。经编码的像素数据的经封装的像素流(在此情况下为JPEG 2000位流)被分段为一个或多个片段(ITEM元素-FFFE:E000)。每个ITEM元素传达其自己的显式长度,并且封装像素流的ITEM序列由分隔符(ITEM分隔符 - FFFE:E00D)终止。 enter image description here

封装格式的第一个ITEM用于基本偏移表,它可能为空。第二个ITEM元素将包含第一帧的封装像素流。您可以通过比较片段数(项目数减去基​​本偏移表的一个)和多帧封装编码的帧数来检测帧的碎片。

答案 1 :(得分:0)

不幸的是, oro.dicom R软件包无法解压缩DICOM文件。还有其他工具可以执行此任务。例如DCMTK。我能够使用dcmdjpeg命令解压缩DICOM文件,然后在R中成功读取它。

library(oro.dicom)

dcmFile <- "images/file.dcm"
dcm <- readDICOMFile(file.path("~/data", dcmFile), debug = TRUE)

# system("brew install dcmtk")
cmd <- paste("dcmdjpeg", 
             file.path("~/data", dcmFile), 
             file.path("~/data", sub("images", "images_uncompressed", dcmFile)))
system(cmd)
dcmFile <- "images_uncompressed/file.dcm"
dcm <- readDICOMFile(file.path("~/data", dcmFile))

将来, oro.dicom 软件包可能会扩展为包含此功能。