Error in Reading DICOM File: Number of bytes in PixelData not specified

本秂侑毒 提交于 2020-01-17 04:41:07

问题


I am using readDICOMFile in R to read DICOM file as following:

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

However, I get following error:

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

If I put pixelData=FALSE, it is successful in reading only the header. But I also want the Image part. I am using standard dicom files from here. (I am trying "BREBIX" database now but other databases give same error.)

What is the problem? I cannot find any reference for this error.

Full output with 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

EDIT:

I looked at the source code. Turns out error is coming from the function parsePixelData that is used by readDICOMFile. Error is due to following lines:

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))
        }

Specifically, following result gives "-1" as the answer, which is causing the problem:

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

Now, how do I deal with it? Since I am using the standard files (link given above), it shouldn't cause the problem, right?


回答1:


According to the transfer syntax of your DICOM dump, image is encapsulated and compression used for the image is JPEG 2000 reversible (Tag 0002:0010 - TransferSyntaxUID - 1.2.840.10008.1.2.4.91). The encapsulated pixel stream (JPEG 2000 bit stream in this case) of encoded pixel data is segmented into one or more Fragments (ITEM Element- FFFE: E000). Each ITEM element conveys its own explicit length and the sequence of ITEM of the encapsulated pixel stream is terminated by a delimiter (ITEM Delimiter - FFFE: E00D).

The first ITEM in the encapsulated format is used for the Basic Offset Table and it may be empty. The second ITEM element will contain the encapsulated pixel stream of first frame. You can detect fragmentation of frames by comparing the number of fragments (the number of Items minus one for the Basic Offset Table) with the number of frames for multi-frame encapsulated encoding.




回答2:


Unfortunately the oro.dicom R package does not have the ability to uncompress DICOM files. There are other tools that can perform this task; for example, DCMTK. I was able to uncompress a DICOM file using the dcmdjpeg command and then successfully read it in 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))

In the future the oro.dicom package may be extended to include this functionality.



来源:https://stackoverflow.com/questions/38061167/error-in-reading-dicom-file-number-of-bytes-in-pixeldata-not-specified

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!