rnso
rnso

Reputation: 24555

Errors while opening dicom files in R

I am trying to open dicom files in R using following code:

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

Some files open properly and I can display them. However, some files give errors of different types:

First error: For some, I get the error:

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

Second error: In others, I get following error with dicom file: http://www.barre.nom.fr/medical/samples/files/OT-MONO2-8-hip.gz :

Error in readDICOMFile(filename) : DICM != DICM

Third error: This file gives following error: 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

Fourth error: One dicom file gives following error:

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

How can I get rid of these errors and display these images in R?

EDIT:

This sample file gives the error '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'

Upvotes: 1

Views: 2455

Answers (1)

B. Whitcher
B. Whitcher

Reputation: 366

There are four different errors highlighted in this ticket:

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

This is not a problem with oro.dicom, it is simply the fact that the file path and/or name has been mis-specified.

  1. Error in readDICOMFile(filename) : DICM != DICM

The file is not a valid DICOM file. That is, section 7.1 in Part 10 of the DICOM Standard (available at http://dicom.nema.org) specifies that there should be (a) the File Preample of length 128 bytes and (b) the four-byte DICOM Prefix "DICM" at the beginning of a DICOM file. The file OT-MONO2-8-hip does not follow this standard. One can investigate this problem further using the debug=TRUE input parameter

> 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

It is apparent that the first 128 bytes contain information. One can now use the parameters skipFirst128=FALSE and DICM=FALSE to start reading information from the beginning of the file

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

The file CT-MONO2-16-chest.dcm is encoded using JPEG compression. The R package oro.dicom does not support compression.

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

I have to speculate, since the file is not available for direct interrogation. This problem is related to the check for "DICM" characters as part of the DICOM standard. If it failed, then one can assume the file is not a valid DICM file. I will look into making this error more informative in future versions of oro.dicom.

EDIT: Thank-you for providing a link to the appropriate file. The file is in "ARC-NEMA 2" format. The R package oro.dicom has not been designed to read such a file. I have modified the code to improve the error tracking.

Upvotes: 1

Related Questions