I am trying to read a simple dicom file named "CR-MONO1-10-chest" from http://www.barre.nom.fr/medical/samples/ which is a 440x440 sized image.
As expained on http://www.dclunie.com/medical-image-faq/html/part1.html , the image data is at the end of the file:
In other words, if an image is 256 by 256, uncompressed, and 12-16 bits deep (and hence usually, though not always, stored as two bytes per pixel), then we all know that the file is going to contain 256*256*2=131072 bytes of pixel data at the end of the file. If the file is say 145408 bytes long, as all GE Signa 3X/4X files are for example, then you need to skip 14336 bytes of header before you get to the data. Presume row by row starting with top left hand corner raster order, try both alternatives for byte order, deal with the 16 to 8 bit windowing problem, and very soon you have your image on the screen of your workstation.
A figure on http://people.cas.sc.edu/rorden/dicom/index.html also shows that the image data is located at the end of the file.
I am using following code to read and display image in this file:
(define in (open-input-file "CR-MONO1-10-chest" #:mode 'binary))
(define size (* 2 440 440)) ; width and ht are 440
(define ignore (read-bytes (- 387976 size) in)) ; size of file is 387976
(define imgdata (read-bytes size in))
(close-input-port in)
(define img (make-object bitmap% imgdata 440 440))
img
However, it only shows a random mix of black and white pixels:
Using 440*440 instead of 2*440*440 also does not work.
Following code also does not read the image:
(define img (make-object bitmap% in 'unknown))
This does not display any image at all.
Where is the problem and how can I solve it?