1
votes

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]
> 
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. I don't have many dcm files lying around on my computer, nor am I sure which library you are using readDICOMFile from. - MrFlick
@MrFlick is correct. Try rasterImage instead, which happily grabs all three layers of an image array. - Carl Witthoft
Thanks for your interest. A simple small dicom image (chest x-ray) is available at: 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
readDICOMFile is from oro.dicom library (I have added this in code above). - rnso
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

1 Answers

1
votes

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.