Importing Binary Images [message #28873] |
Fri, 18 January 2002 06:38  |
rschick
Messages: 2 Registered: January 2002
|
Junior Member |
|
|
I'm new to idl, and am trying to import a binary grid that was created
on a windows machine into idl on a linux machine. It's least
significant byte first, 1561 rows, 2041 cols.
I searched the archives and found a thread that suggested used the
following syntax:
IDL> openr, 1, 'gom15dd.dat'
IDL> ms = bytarr(1561, 2041)
IDL> readu, 1, ms
IDL> tv, ms
While this 'works', the image displayed is incorrect - sort of looks
like speckled white noise. Any thoughts on what I may be doing wrong.
For a newbie, what's the difference between using readu, and
read_binary? The online help didn't help. Thanks.
|
|
|
Re: Importing Binary Images [message #28967 is a reply to message #28873] |
Fri, 18 January 2002 10:53   |
Craig Markwardt
Messages: 1869 Registered: November 1996
|
Senior Member |
|
|
rschick@neaq.org (rob schick) writes:
> I'm new to idl, and am trying to import a binary grid that was created
> on a windows machine into idl on a linux machine. It's least
> significant byte first, 1561 rows, 2041 cols.
>
> I searched the archives and found a thread that suggested used the
> following syntax:
>
> IDL> openr, 1, 'gom15dd.dat'
> IDL> ms = bytarr(1561, 2041)
> IDL> readu, 1, ms
> IDL> tv, ms
Question: If the data is formatted "least significant byte first,"
usually that means there is more than one byte per grid cell. That
implies that using a BYTARR is too small. So presumably you want to
use INTARR(1561,2041) instead? That is not clear from your note.
Second, in general, the byte ordering of the data may have to be dealt
with. This is usually easiest accomplished with one of the ENDIAN
keywords to the OPENR procedure. If you are on an Wintel machine,
then the processor is already little-endian, and so is your data
(according to you), so this should not be an issue.
> While this 'works', the image displayed is incorrect - sort of looks
> like speckled white noise. Any thoughts on what I may be doing wrong.
> For a newbie, what's the difference between using readu, and
> read_binary? The online help didn't help. Thanks.
For reading a bulk data array, READU is appropriate. READ_BINARY is
most useful when reading structures of data.
Craig
--
------------------------------------------------------------ --------------
Craig B. Markwardt, Ph.D. EMAIL: craigmnet@cow.physics.wisc.edu
Astrophysics, IDL, Finance, Derivatives | Remove "net" for better response
------------------------------------------------------------ --------------
|
|
|
Re: Importing Binary Images [message #28969 is a reply to message #28873] |
Fri, 18 January 2002 09:05   |
Martin Downing
Messages: 136 Registered: September 1998
|
Senior Member |
|
|
"rob schick" <rschick@neaq.org> wrote in message
news:240cd6d2.0201180638.46419bb3@posting.google.com...
> I'm new to idl, and am trying to import a binary grid that was created
> on a windows machine into idl on a linux machine. It's least
> significant byte first, 1561 rows, 2041 cols.
>
> I searched the archives and found a thread that suggested used the
> following syntax:
>
> IDL> openr, 1, 'gom15dd.dat'
> IDL> ms = bytarr(1561, 2041)
> IDL> readu, 1, ms
> IDL> tv, ms
>
> While this 'works', the image displayed is incorrect - sort of looks
> like speckled white noise. Any thoughts on what I may be doing wrong.
> For a newbie, what's the difference between using readu, and
> read_binary? The online help didn't help. Thanks.
Rob, I am a little confused (nothing new for a friday afternoon). Do you
mean you have BYTE data of size 1561 x 2041? If so then to my knowledge
there is no byte swapping issue. Endian-ness comes into play with data types
which are larger than one byte, eg INT, LONG, FLOAT etc. With these types
you swap the byte pairs from unix to windows, idl does this for you with the
routine:
unix_data = SWAP_ENDIAN(win_data)
If you know the file derives from windows (little endian), you can add a
keyword to the openr command:
openr, lun, filename, /SWAP_IF_LITTLE_ENDIAN
you then do not have to worry about swapping, as long as you read the data
in as the correct data type.
readu is the basic binary read for variables.
It would be a good idea to check exactly what type of data you have in this
file, start by checking its file size in bytes and seeing how many multiples
of (1561x2041) you have. If 1 then it really is bye, If 2 then its INT or
UINT, if 4 then it is LONG, ULONG or FLOAT
hope this helps
good luck
Martin
|
|
|
Re: Importing Binary Images [message #28970 is a reply to message #28873] |
Fri, 18 January 2002 08:51   |
Med Bennett
Messages: 109 Registered: April 1997
|
Senior Member |
|
|
rob schick wrote:
> I'm new to idl, and am trying to import a binary grid that was created
> on a windows machine into idl on a linux machine. It's least
> significant byte first, 1561 rows, 2041 cols.
>
> I searched the archives and found a thread that suggested used the
> following syntax:
>
> IDL> openr, 1, 'gom15dd.dat'
> IDL> ms = bytarr(1561, 2041)
> IDL> readu, 1, ms
> IDL> tv, ms
>
> While this 'works', the image displayed is incorrect - sort of looks
> like speckled white noise. Any thoughts on what I may be doing wrong.
> For a newbie, what's the difference between using readu, and
> read_binary? The online help didn't help. Thanks.
What is the image 'supposed' to look like? It could depend on whether or
not the software that created the image created it in row-major or
column-major order. Try this:
IDL> openr, 1, 'gom15dd.dat'
IDL> ms = bytarr( 2041,1561)
IDL> readu, 1, ms
IDL> ms = transpose(ms)
IDL> tv, ms
|
|
|
Re: Importing Binary Images [message #29001 is a reply to message #28873] |
Thu, 24 January 2002 09:03   |
Nigel Wade
Messages: 286 Registered: March 1998
|
Senior Member |
|
|
rob schick wrote:
> rschick@neaq.org (rob schick) wrote in message
> news:<240cd6d2.0201180638.46419bb3@posting.google.com>...
>> I'm new to idl, and am trying to import a binary grid that was created
>> on a windows machine into idl on a linux machine. It's least
>> significant byte first, 1561 rows, 2041 cols.
>>
>> I searched the archives and found a thread that suggested used the
>> following syntax:
>>
>> IDL> openr, 1, 'gom15dd.dat'
>> IDL> ms = bytarr(1561, 2041)
>> IDL> readu, 1, ms
>> IDL> tv, ms
>>
>> While this 'works', the image displayed is incorrect - sort of looks
>> like speckled white noise. Any thoughts on what I may be doing wrong.
>> For a newbie, what's the difference between using readu, and
>> read_binary? The online help didn't help. Thanks.
>
> Ok - thanks to all for the replies. The program creating the image, is
> in row-major. I created the image on an NT machine, and am using IDL
> on a linux machine (intel processor).
>
> I tried
> IDL> openr, 1, 'gom15dd.dat', /swap_if_little_endian
> IDL> ms = intarr(2041,1561)
> IDL> readu, 1, ms
> IDL> tvscl, ms
>
> and this looks better. I don't think it's quite correct, so my
> questions as related to the suggestions are:
>
> If my image is indeed not byte, do I do something different, e.g.
> -rw-r--r-- 1 robs robs 12744004 Jan 17 14:38 gom15dd.dat
> that value divided by (1561x2041) = 4 ?
With those figures it appears the data is 32bit. Try lonarr() in place of
intarr(). You should not need to do any byte swapping.
>
> Do I do anything differently to account for the row-major output?
> (specifying columns first in the openr line made the image appear more
> normal...
>
> Thanks, Rob
All you need to do is match the dimensions. Try it with (2041,1561) and
(1561,2041). One will match the vertical/horizontal size of the image. If
the row/column order is not correct I think the image will just appear
rotated - try TRANSPOSE() on the array.
--
-----------------------------------------------------------
Nigel Wade, System Administrator, Space Plasma Physics Group,
University of Leicester, Leicester, LE1 7RH, UK
E-mail : nmw@ion.le.ac.uk
Phone : +44 (0)116 2523568, Fax : +44 (0)116 2523555
|
|
|
Re: Importing Binary Images [message #29002 is a reply to message #28873] |
Thu, 24 January 2002 09:06   |
Craig Markwardt
Messages: 1869 Registered: November 1996
|
Senior Member |
|
|
rschick@neaq.org (rob schick) writes:
> Ok - thanks to all for the replies. The program creating the image, is
> in row-major. I created the image on an NT machine, and am using IDL
> on a linux machine (intel processor).
>
> I tried
> IDL> openr, 1, 'gom15dd.dat', /swap_if_little_endian
> IDL> ms = intarr(2041,1561)
> IDL> readu, 1, ms
> IDL> tvscl, ms
>
> and this looks better. I don't think it's quite correct, so my
> questions as related to the suggestions are:
>
> If my image is indeed not byte, do I do something different, e.g.
> -rw-r--r-- 1 robs robs 12744004 Jan 17 14:38 gom15dd.dat
> that value divided by (1561x2041) = 4 ?
Umm, BYTE = 1 byte, INT = 2 bytes, LONG = 4 bytes (ignoring
distinction between unsigned and signed). So, looks like you want a
LONARR, not an INTARR.
Good luck,
Craig
--
------------------------------------------------------------ --------------
Craig B. Markwardt, Ph.D. EMAIL: craigmnet@cow.physics.wisc.edu
Astrophysics, IDL, Finance, Derivatives | Remove "net" for better response
------------------------------------------------------------ --------------
|
|
|
Re: Importing Binary Images [message #29003 is a reply to message #28873] |
Thu, 24 January 2002 07:56   |
rschick
Messages: 2 Registered: January 2002
|
Junior Member |
|
|
rschick@neaq.org (rob schick) wrote in message news:<240cd6d2.0201180638.46419bb3@posting.google.com>...
> I'm new to idl, and am trying to import a binary grid that was created
> on a windows machine into idl on a linux machine. It's least
> significant byte first, 1561 rows, 2041 cols.
>
> I searched the archives and found a thread that suggested used the
> following syntax:
>
> IDL> openr, 1, 'gom15dd.dat'
> IDL> ms = bytarr(1561, 2041)
> IDL> readu, 1, ms
> IDL> tv, ms
>
> While this 'works', the image displayed is incorrect - sort of looks
> like speckled white noise. Any thoughts on what I may be doing wrong.
> For a newbie, what's the difference between using readu, and
> read_binary? The online help didn't help. Thanks.
Ok - thanks to all for the replies. The program creating the image, is
in row-major. I created the image on an NT machine, and am using IDL
on a linux machine (intel processor).
I tried
IDL> openr, 1, 'gom15dd.dat', /swap_if_little_endian
IDL> ms = intarr(2041,1561)
IDL> readu, 1, ms
IDL> tvscl, ms
and this looks better. I don't think it's quite correct, so my
questions as related to the suggestions are:
If my image is indeed not byte, do I do something different, e.g.
-rw-r--r-- 1 robs robs 12744004 Jan 17 14:38 gom15dd.dat
that value divided by (1561x2041) = 4 ?
Do I do anything differently to account for the row-major output?
(specifying columns first in the openr line made the image appear more
normal...
Thanks, Rob
|
|
|
Re: Importing Binary Images [message #29040 is a reply to message #29002] |
Tue, 29 January 2002 10:09  |
Martin Downing
Messages: 136 Registered: September 1998
|
Senior Member |
|
|
>> If my image is indeed not byte, do I do something different, e.g.
>> -rw-r--r-- 1 robs robs 12744004 Jan 17 14:38 gom15dd.dat
>> that value divided by (1561x2041) = 4 ?
>
> Umm, BYTE = 1 byte, INT = 2 bytes, LONG = 4 bytes (ignoring
> distinction between unsigned and signed). So, looks like you want a
> LONARR, not an INTARR.
As I said previously, once you have established that you have 4 bytes per
pixel (and no remainder, then your image could be of type LONG, ULONG or
FLOAT. So just try loading each of them in 1561x2041 (and try reforming to
2041x1561).
Easy test is: load as LONG. If it looks fairly good but has half the image
highlighted, then you have a ULONG type, if the image looks like a snow
storm then you have (a) an image of a snow storm (b) a float image
Martin
|
|
|