Re: Byte to Real conversion [message #14334] |
Fri, 19 February 1999 00:00 |
David Foster
Messages: 341 Registered: January 1996
|
Senior Member |
|
|
Michael A. Wirth wrote:
>
> Hi,
>
> I am reading some data in from an Magnetic Resonance image which stores
> information about the image in
> a 14336 byte header. I want to extract some of the data from this header
> and am having a problem
> with converting data to integers and reals. The integers are 2-bytes and
> the reals 4-bytes in length. How does
> one convert 4 bytes into a real number?
>
> many thanks,
>
> Michael
Michael -
For some reason our nameserver can't find your host, so my email
bounced. If you want the C code for a MR_HEADER program, you can
get it from:
ftp://bial1.ucsd.edu/pub/mr_header.tar.gz
Dave
--
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~
David S. Foster Univ. of California, San Diego
Programmer/Analyst Brain Image Analysis Laboratory
foster@bial1.ucsd.edu Department of Psychiatry
(619) 622-5892 8950 Via La Jolla Drive, Suite 2240
La Jolla, CA 92037
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~
|
|
|
Re: Byte to Real conversion [message #14335 is a reply to message #14334] |
Fri, 19 February 1999 00:00  |
David Foster
Messages: 341 Registered: January 1996
|
Senior Member |
|
|
Michael A. Wirth wrote:
>
> Hi,
>
> I am reading some data in from an Magnetic Resonance image which stores
> information about the image in
> a 14336 byte header. I want to extract some of the data from this header
> and am having a problem
> with converting data to integers and reals. The integers are 2-bytes and
> the reals 4-bytes in length. How does
> one convert 4 bytes into a real number?
Michael -
Hmm, that number 14336 sure looks familiar! Are you working with
GE Signa images by any chance? I have C code that has routines to
pull out integer, byte, and float information from the header. The
main routine prints out a listing of important information from
the header. There is also a .h file that lists the offsets for
every entry in the file.
The conversion of floats does *not* look straightforward!
I'll send you an email with this code attached. I haven't had time
to port the code to IDL, so I wrote a short wrapper that spawns
the C program and returns the info in a structure. Let me know
if you're interested in this.
Hope this helps.
Dave
--
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~
David S. Foster Univ. of California, San Diego
Programmer/Analyst Brain Image Analysis Laboratory
foster@bial1.ucsd.edu Department of Psychiatry
(619) 622-5892 8950 Via La Jolla Drive, Suite 2240
La Jolla, CA 92037
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~
|
|
|
Re: Byte to Real conversion [message #14339 is a reply to message #14334] |
Fri, 19 February 1999 00:00  |
Liam Gumley
Messages: 473 Registered: November 1994
|
Senior Member |
|
|
Michael A. Wirth wrote:
> I am reading some data in from an Magnetic Resonance image which stores
> information about the image in
> a 14336 byte header. I want to extract some of the data from this header
> and am having a problem
> with converting data to integers and reals. The integers are 2-bytes and
> the reals 4-bytes in length. How does
> one convert 4 bytes into a real number?
An easy way is to use a structure. For example, let's say the header
format is:
Bytes 0:9 are junk
Bytes 10:11 are a signed 16 bit integer
Bytes 12:15 are a 32 bit float
Bytes 16:14335 are junk
To read the header:
header = { junk1 : bytarr( 10 ), $ ; array of 10 bytes
word1 : 0, $ ; short integer
word2 : 0L, $ ; long integer
junk2 : bytarr( 14320 ) } ; array of 14320 bytes
openr, lun, 'mri.dat', /free_lun
readu, lun, header
free_lun, lun
help, header.word1, header.word2
Cheers,
Liam.
---
Liam E. Gumley
http://cimss.ssec.wisc.edu/~gumley
|
|
|