1

I am trying to read and see a dicom file. I installed package 'oro.dicom' and was able to read the file with:

library(oro.dicom)
abdo <- readDICOMFile("image0.dcm")

extractHeader(abdo$hdr, "Rows")
[1] 2014

extractHeader(abdo$hdr, "Columns")
[1] 2014

extractHeader(abdo$hdr, "Manufacturer", numeric=FALSE)
[1] "...IT Radiology"

However, I am not able to see the image:

image(t(abdo$img), col=grey(0:64/64), axes=FALSE, xlab="", ylab="")
Error in t.default(abdo$img) : argument is not a matrix

The structure command shows following:

str(abdo$img)
int [1:2014, 1:2014, 1:3] 110 51 99 113 52 101 111 53 102 110 ...

Following works and a graphic box is displayed but it is only an empty box without any x-ray image:

image(t(abdo$img[[1]]), col=grey(0:64/64), axes=FALSE, xlab="", ylab="")

Why is it not working and how can I correct it? Thanks for your help.

EDIT: with CR-MONO1-10-chest.dcm (http://www.barre.nom.fr/medical/samples/files/CR-MONO1-10-chest.gz) I get following error even while reading it:

abdo <- readDICOMFile("CR-MONO1-10-chest.dcm")
Error in readDICOMFile("CR-MONO1-10-chest.dcm") : DICM != DICM

With rasterImage following is the error:

rasterImage(as.raster(matrix(abdo[[1:3]])))
Error in rasterImage(as.raster(matrix(abdo[[1:3]]))) : 
  argument "xleft" is missing, with no default

Following is closer but still does not work:

>      rasterImage(abdo$img, 100, 400, 150, 450)
Error in rgb(t(x[, , 1]), t(x[, , 2]), t(x[, , 3]), maxColorValue = max) : 
  color intensity -30, not in [0,1]

>      rasterImage(abdo$img, 100, 400, 150, 450, interpolate=F)
Error in rgb(t(x[, , 1]), t(x[, , 2]), t(x[, , 3]), maxColorValue = max) : 
  color intensity -30, not in [0,1]
> 
rnso
  • 23,686
  • 25
  • 112
  • 234
  • 1
    Looks like you have a 3D array there and `image()` expects a 2D array. It's like they third dimension has data for the RGB layers separately. You can collapse across the third dimension with `rgb`. But this would be much easier to help with if you provided a [reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example). I don't have many `dcm` files lying around on my computer, nor am I sure which library you are using `readDICOMFile` from. – MrFlick Sep 05 '14 at 13:19
  • @MrFlick is correct. Try `rasterImage` instead, which happily grabs all three layers of an image array. – Carl Witthoft Sep 05 '14 at 13:20
  • Thanks for your interest. A simple small dicom image (chest x-ray) is available at: http://www.barre.nom.fr/medical/samples/files/CR-MONO1-10-chest.gz . I will also test this image and post the errors with this image. The code is all that I have posted above. With same image it will become like a reproducible example. – rnso Sep 05 '14 at 13:26
  • readDICOMFile is from oro.dicom library (I have added this in code above). – rnso Sep 05 '14 at 14:17
  • Try `?rasterimage` to see how to use it. I also don't think you can do `foo[[1:3]]` as the `[[` operator doesn't allow that. – Carl Witthoft Sep 05 '14 at 16:44
  • @ Carl Witthoft: rasterImage code is also not working (see EDIT in the question above. – rnso Sep 05 '14 at 16:53
  • Can you please provide the image0.dcm file? This will help me try to reproduce, and hopefully fix, the problem. – B. Whitcher Sep 16 '14 at 21:27
  • Which version of **oro.dicom** are you using? The current version is 0.4.1 on http://cran.r-project.org. – B. Whitcher Sep 17 '14 at 00:08
  • I have the latest version only: > packageVersion('oro.dicom') [1] ‘0.4.1’ – rnso Sep 17 '14 at 02:02

1 Answers1

1

This answer is only valid for the open-source file CR-MONO1-10-chest.dcm (http://www.barre.nom.fr/medical/samples/files/CR-MONO1-10-chest.gz). I believe that this file is not a valid DICOM file. According to section 7.1 in Part 10 of the DICOM Standard (available at http://dicom.nema.org) there should be (a) the File Preample of length 128 bytes and (b) the four-byte DICOM Prefix "DICM". The CR-MONO1-10-chest.dcm starts providing information in the first pair of bytes.

I have added the parameter skipFirst128 = TRUE to readDICOMFile() and this will be available in the next release of oro.dicom. Thus, one could read the file by using

abdo <- readDICOMFile("CR-MONO1-10-chest.dcm", skipFirst128=FALSE, DICM=FALSE)
image(t(abdo$img), col=grey(0:64/64), axes=FALSE, xlab="", ylab="")

Please note that the file was created almost 20 years ago, I hope that files produced in the recent past will not have this problem. Thank-you for bringing this error to my attention. I am always looking for DICOM files that break my code in order to improve it.

B. Whitcher
  • 366
  • 2
  • 5
  • Thanks for your answer. Please also see this link where some more information is there: http://stackoverflow.com/questions/25819617/what-could-be-the-reason-for-bad-dicom-image-plot – rnso Sep 17 '14 at 02:07
  • Yes, I am aware of the two additional questions in stackoverflow. I plan to work through them in the next few days. – B. Whitcher Sep 17 '14 at 19:21