Skip to content
Prev 301416 / 398503 Next

Linking to C type short?

On 7/26/2012 4:51 PM, Duncan Murdoch wrote:
I have DICOM (.dcm) files from Computed Tomography (CT scans).  
It sounds like readDICOMFile{oro.dicom} should be able to read this.  
Unfortunately, it won't, because my particular DICOM files have images 
stored as lossless JPEG, which is not readable by the current version of 
oro.dicom.  I'm working to fix this deficiency with Brandon Whichter, 
project admin for oro.dicom and related packages.


       An example of such an image file is available from the R-Forge 
version of oro.dicom:


install.packages("oro.dicom", repos= c("http://R-Forge.R-project.org", 
getOption("repos")))
library(oro.dicom)
jpgIn.dcmFile <- system.file('jpeg/cervicalKyphosis.dcm',
                             package='oro.dicom')
str(dcm <- readDICOMFile(jpgIn.dcmFile))


       dcm$hdr provides information needed to decode the data in the 
rest of the file, returned as dcm$img in this developmental version of 
oro.dicom.  Row 39 tells us the data type:


 > dcm$hdr[39,]
    group element                  name code length
39  0008    2111 DerivationDescription   ST     36
                                   value sequence
39 2:1 JPEGLOSSLESSPROCFIRSTORDERREDICT


       Brandon Whichter said that the information required to decode 
this type of dcm file is available in Kongji Huang and Brian Smith 
(1994) "Lossless JPEG Codec", v. 1.0 <URL: 
ftp://ftp.cs.cornell.edu/pub/multimed/ljpg.tar.Z>.  One way to use this 
might be to install this software so it is accessible from a commands 
prompt as "ljpgtopnm foo.ljpg foo.ppm", where "foo.ljpg" is an image 
file in lossless JPEG format and foo.ppm is a name for the desired 
decompressed output file.


       However, rather than try to invoke a systems command from within 
R, I though it might be better to study the algorithm more carefully.  
This identified a function DecodeImage in C++ or C, which takes an 
argument of class DecompressInfo.  I thought I would try to create this 
DecompressInfo argument from the information available in dcm$hdr, then 
call DecodeImage (compiled C++ or C) from R.


       I don't know if it's better to use .Call or .C.


       Thanks,
       Spencer