Byte to Real conversion [message #14340] |
Fri, 19 February 1999 00:00  |
Michael A. Wirth
Messages: 5 Registered: April 1997
|
Junior Member |
|
|
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
|
|
|
|
Re: Byte to Real conversion [message #14408 is a reply to message #14340] |
Tue, 23 February 1999 00:00  |
Larry Busse
Messages: 7 Registered: February 1999
|
Junior 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
This is less elegant than structures, but it works...
If you've read the header into a byte array, then you can convert as
follows assuming you know the location (offsets) of the bytes of
interest:
var1 = fix(header,10)
var2 = long(header,12)
var3 = float(header,16)
var1 will be a short integer consisting of the 2 bytes header(10) and
header(11).
var2 will be a long integer consisting of the 4 bytes header(12:15).
var3 will be a float consisting of the 4 bytes header(16:19).
Depending on the archetecture of your machine and the MRI scanner you
might also need to use swap_endian; e.g.,
var3 = swap_endian(float(header,16))
will be needed if you are using a PC version if IDL (Linux or Win) to
analyze data from a GE or Bruker imager.
Good Luck
--
Larry Busse Phone: (606)344-9433
L.J.B. Development Fax: (606)341-8486
3384 Madison Pike mailto:larry@ljbdev.com
Fort Wright, KY 41017 http://www.ljbdev.com
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~
|
|
|