dambach
dambach

Reputation: 89

Error with oro.dicom readDICOMFile in R

I am trying to read a dicom file exported from an ultrasound device:

library(oro.dicom)
readDICOMFile('testdcm.dcm')

I get following error:

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

The full output with readDICOMFile('testdcm.dcm', debug = TRUE) is as follows:

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 00 00 00
 [30] 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 00 00 00
 [59] 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 00 00 00
 [88] 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 00 00 00
 [117] 00 00 00 00 00 00 00 00 00 00 00 00
# DICM = TRUE
#   0002    0000    GroupLength UL  UL  4   218 
#   0002    0001    FileMetaInformationVersion  OB  OB  2       
#   0002    0002    MediaStorageSOPClassUID UI  UI  28  1.2.840.10008.5.1.4.1.1.6.1 
#   0002    0003    MediaStorageSOPInstanceUID  UI  UI  48  1.2.250.1.204.5.8373721313.2016112214594330207.0    
#   0002    0010    TransferSyntaxUID   UI  UI  22  1.2.840.10008.1.2.4.70  
#   0002    0012    ImplementationClassUID  UI  UI  34  1.2.250.1.204.0.1.20120820.0.3.6.1  
#   0002    0013    ImplementationVersionName   SH  SH  14  SSI_DCMTK_361   
#   0002    0016    SourceApplicationEntityTitle    AE  AE  10  XXXXXX  
#   0008    0005    SpecificCharacterSet    CS  CS  10  ISO_IR 100  
#   0008    0008    ImageType   CS  CS  16  ORIGINAL PRIMARY    
#   0008    0012    InstanceCreationDate    DA  DA  8   20161122    
#   0008    0013    InstanceCreationTime    TM  TM  6   155942  
#   0008    0014    InstanceCreatorUID  UI  UI  30  1.2.250.1.204.5.8373721313.13   
#   0008    0016    SOPClassUID UI  UI  28  1.2.840.10008.5.1.4.1.1.6.1 
#   0008    0018    SOPInstanceUID  UI  UI  48  1.2.250.1.204.5.8373721313.2016112214594330207.0    
#   0008    0020    StudyDate   DA  DA  8   20161122    
#   0008    0021    SeriesDate  DA  DA  8   20161122    
#   0008    0022    AcquisitionDate DA  DA  8   20161122    
#   0008    0023    ContentDate DA  DA  8   20161122    
#   0008    002A    AcquisitionDatetime DT  DT  14  20161122155943  
#   0008    0030    StudyTime   TM  TM  6   155942  
#   0008    0031    SeriesTime  TM  TM  6   155943  
#   0008    0032    AcquisitionTime TM  TM  6   155943  
#   0008    0033    ContentTime TM  TM  6   155942  
#   0008    0050    AccessionNumber SH  SH  0       
#   0008    0060    Modality    CS  CS  2   US  
#   0008    0070    Manufacturer    LO  LO  22  XXXXX
#   0008    0080    InstitutionName LO  LO  20  XXXXX
#   0008    0081    InstitutionAddress  ST  ST  0       
#   0008    0090    ReferringPhysiciansName PN  PN  0       
#   0008    1010    StationName SH  SH  10  aixplorer   
#   0008    1030    StudyDescription    LO  LO  0       
#   0008    103E    SeriesDescription   LO  LO  6   Muscle  
#   0008    1040    InstitutionalDepartmentName LO  LO  58  XXXXX
#   0008    1048    PhysiciansOfRecord  PN  PN  0       
#   0008    1050    PerformingPhysiciansName    PN  PN  0       
#   0008    1070    OperatorsName   PN  PN  0       
#   0008    1090    ManufacturersModelName  LO  LO  10  Aixplorer   
#   0008    1111    ReferencedPerformedProcedureStepSequence    SQ  SQ  94  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  46  1.2.250.1.204.5.8373721313.2016112214594323292   (0008,1111)
#   0008    2111    DerivationDescription   ST  ST  90  Lossless JPEG compression, selection value 1, point transform 0, compression ratio 4.13087  
#   0008    2112    SourceImageSequence SQ  SQ  176 Sequence    
#   FFFE    E000    Item    UN  UN  0        (0008,2112)
#   0008    1150    ReferencedSOPClassUID   UI  UI  28  1.2.840.10008.5.1.4.1.1.6.1  (0008,2112)
#   0008    1155    ReferencedSOPInstanceUID    UI  UI  46  1.2.250.1.204.5.8373721313.2016112214594330207   (0008,2112)
#   0040    A170    PurposeOfReferenceCodeSequence  SQ  SQ  66  Sequence     (0008,2112)
#   FFFE    E000    Item    UN  UN  0        (0008,2112) (0040,A170)
#   0008    0100    CodeValue   SH  SH  6   121320   (0008,2112) (0040,A170)
#   0008    0102    CodingSchemeDesignator  SH  SH  4   DCM  (0008,2112) (0040,A170)
#   0008    0104    CodeMeaning LO  LO  24  Uncompressed predecessor     (0008,2112) (0040,A170)
#   0010    0010    PatientsName    PN  PN  6   20WFV8  
#   0010    0020    PatientID   LO  LO  20  Aixplorer_217522782 
#   0010    0021    IssuerOfPatientID   LO  LO  0       
#   0010    0030    PatientsBirthDate   DA  DA  0       
#   0010    0032    PatientsBirthTime   TM  TM  0       
#   0010    0040    PatientsSex CS  CS  0       
#   0010    1010    PatientsAge AS  AS  0       
#   0010    1020    PatientsSize    DS  DS  0       
#   0010    1030    PatientsWeight  DS  DS  0       
#   0010    2160    EthnicGroup SH  SH  0       
#   0010    21B0    AdditionalPatientHistory    LT  LT  0       
#   0010    4000    PatientComments LT  LT  0       
#   0012    0062    PatientIdentityRemoved  CS  CS  2   NO  
#   0018    1000    DeviceSerialNumber  LO  LO  8   SIH1313 
#   0018    1020    SoftwareVersions    LO  LO  12  11.1.1.1404 
#   0018    1030    ProtocolName    LO  LO  10  Free Form   
#   0018    5010    TransducerData  LO  LO  18  SL15-4 MSK Muscle   
#   0018    5100    PatientPosition CS  CS  0       
#   0018    6011    SequenceOfUltrasoundRegions SQ  SQ  140 Sequence    
#   FFFE    E000    Item    UN  UN  0        (0018,6011)
#   0018    6012    RegionSpatialFormat US  US  2   1    (0018,6011)
#   0018    6014    RegionDataType  US  US  2   1    (0018,6011)
#   0018    6016    RegionFlags UL  UL  4   2    (0018,6011)
#   0018    6018    RegionLocationMInX0 UL  UL  4   336  (0018,6011)
#   0018    601A    RegionLocationMInY0 UL  UL  4   151  (0018,6011)
#   0018    601C    RegionLocationMaxX1 UL  UL  4   1064     (0018,6011)
#   0018    601E    RegionLocationMaxY1 UL  UL  4   959  (0018,6011)
#   0018    6024    PhysicalUnitsXDirection US  US  2   3    (0018,6011)
#   0018    6026    PhysicalUnitsYDirection US  US  2   3    (0018,6011)
#   0018    602C    PhysicalDeltaX  FD  FD  8   0.00703188   (0018,6011)
#   0018    602E    PhysicalDeltaY  FD  FD  8   0.00703188   (0018,6011)
#   0020    000D    StudyInstanceUID    UI  UI  46  1.2.250.1.204.5.8373721313.2016112214594315435  
#   0020    000E    SeriesInstanceUID   UI  UI  48  1.2.250.1.204.5.8373721313.2016112214594331065.1    
#   0020    0010    StudyID SH  SH  14  20161122155942  
#   0020    0011    SeriesNumber    IS  IS  2   1   
#   0020    0012    AcquisitionNumber   IS  IS  2   1   
#   0020    0013    InstanceNumber  IS  IS  2   1   
#   0020    0020    PatientOrientation  CS  CS  0       
#   0020    0060    Laterality  CS  CS  0       
#   0028    0002    SamplesperPixel US  US  2   3   
#   0028    0004    PhotometricInterpretation   CS  CS  4   RGB 
#   0028    0006    PlanarConfiguration US  US  2   0   
#   0028    0010    Rows    US  US  2   1080    
#   0028    0011    Columns US  US  2   1440    
#   0028    0014    UltrasoundColorDataPresent  US  US  2   1   
#   0028    0100    BitsAllocated   US  US  2   8   
#   0028    0101    BitsStored  US  US  2   8   
#   0028    0102    HighBit US  US  2   7   
#   0028    0103    PixelRepresentation US  US  2   0   
#   0028    0301    BurnedInAnnotation  CS  CS  4   YES 
#   0028    2110    LossyImageCompression   CS  CS  2   00  
#   0038    0010    AdmissionID LO  LO  0       
#   0040    0243    PerformedLocation   SH  SH  6   echo1   
#   0040    0244    PerformedProcedureStepStartDate DA  DA  8   20161122    
#   0040    0245    PerformedProcedureStepStartTime TM  TM  6   155942  
#   0040    0253    PerformedProcedureStepID    SH  SH  14  20161122145943  
#   0040    0254    PerformedProcedureStepDescription   LO  LO  0       
#   0040    0275    RequestAttributesSequence   SQ  SQ  86  Sequence    
#   FFFE    E000    Item    UN  UN  0        (0040,0275)
#   0008    0050    AccessionNumber SH  SH  0        (0040,0275)
#   0020    000D    StudyInstanceUID    UI  UI  46  1.2.250.1.204.5.8373721313.2016112214594315435   (0040,0275)
#   0032    1060    RequestedProcedureDescription   LO  LO  0        (0040,0275)
#   0040    0007    ScheduledProcedureStepDescription   LO  LO  0        (0040,0275)
#   7FE0    0010    PixelData   OB  OB  -1  PixelData   
##### Reading PixelData (7FE0,0010) #####

A similar issue has been previously reported here Error in Reading DICOM File: Number of bytes in PixelData not specified but no validated answer was provided.

The .dcm file is downloadable here : https://github.com/dambach/stackoverflowfiles/blob/master/testdcm.dcm

Any ideas ?

Upvotes: 0

Views: 634

Answers (1)

Manabu Tokunaga
Manabu Tokunaga

Reputation: 1104

Many JPEG type images do not have the length of pixels indicated in the DICOM Element. Instead, they are sequenced with sequence delimiters. This is especially true for Ultrasound JPEG encapsulated image datasets.

I believe that your library may not have been coded to handle this situation.

I would personally recommend trying other libraries and they can all be used in "industrial strength", way in PACS, VNA, Viewing Workstations etc.

  • Java (works with Scala too): dcm4che
  • C/C++: dcmtk
  • C#: fo-dicom
  • JavaScript: Cornerstone

I cannot advise you on Python, PHP or Ruby. But dcmtk and dcm4che provide a good set of command line tools to extract pixels into JPEG files tec. I would wrap those into a system call and call them directly if performance is not much of issue.

I have used all of them, and pixel formats are well supported. You should be able to Google for above and be able to find the respective home pages.

Upvotes: 1

Related Questions