Re: 8 bit binary images [message #9617 is a reply to message #9548] |
Wed, 23 July 1997 00:00  |
David Foster
Messages: 341 Registered: January 1996
|
Senior Member |
|
|
Mike Black wrote:
>
> I've just written a Fortran 77 program that was supposed to generate
> a 8 bit binary data file for PV-Wave.
>
> The file format consists of 800 rows of 1000-character-long strings, each
> character in the string meaning to represent individual pixels in an image
> as you move from left to right.
>
> I used the CHAR command to write CHAR(0) for a 'white' pixel and
> CHAR(255) for a 'black' pixel. Each row consists of 1000 of these
> CHAR(0/255) characters concatenated together with no space in between > them.
> Does anyone have any suggestions, or an explicit description of the
> necessary format required to encode the 8-bit format?
I would suggest saving the image as a BYTARR(800,1000). You could
define the array as:
CHARACTER*1 ARRAY(800,1000)
in your fortran program, define the individual pixels and then save
the array using binary I/O:
OPEN(11, FILE=FNAME, FORM='BINARY')
WRITE(11) ARRAY
CLOSE(11)
Then read the array into IDL using:
ARRAY = BYTARR(800,1000)
OPENR, UNIT, FNAME, /GET_LUN
READU, ARRAY
If you try to write the 800 rows as strings in your Fortran program
then you are bound to run into problems with new-line characters
and the like.
Also, be aware that if you are using something like:
OPEN(11, FILE=FNAME, FORM='UNFORMATTED')
to write the file in the fortran program, then you must use the
/F77_UNFORMATTED keyword in your IDL OPENR() statement. I believe
that specifying FORM='BINARY' implies direct access and makes this
keyword unnecessary.
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 2200
La Jolla, CA 92037
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~
"I have this theory that if we're told we're bad,
then that's the only idea we'll ever have.
But maybe if we are surrounded in beauty,
someday we will become what we see." - Jewel Kilcher
|
|
|