Re: read/writing tiff files [message #35629] |
Sat, 28 June 2003 14:17 |
alex_panton
Messages: 5 Registered: June 2003
|
Junior Member |
|
|
thanks for all your advice, literally straight after i posted though i
managed to get it to work.. typical!
cheers
alex
David Fanning <david@dfanning.com> wrote in message news:<MPG.19675378bd56891a989693@news.frii.com>...
> Alexandra Panton writes:
>
>> my code so far...
>>
>> stuff = ('f:\ftp_web_root\Recent\hawaii\GOES_9\all')
>> store = ('d:\goes\hawaii')
>>
>> cd, stuff
>> ...
>> outname=input+'bt' ;output file name;
>> cd, store
>> openw,1, outname ;opens a file with outname filename;
>> write_tiff,input ;writes a tiff file of input array
>> close,1
>> free_lun,1
>> x=x+1 ;loops round to next image;
>> endwhile
>> end
>>
>> When i run this it stops at the openw command with a type conversion
>> error: Unable to convert given STRING to Byte.
>
> When you get the error message, you should read it carefully
> to see what line the error occurs on. They you go to that
> line in the program and stare at it for a period of time that
> is inversely proportional to the time you have been working
> with IDL (or sometimes, in rare cases, or if you are under
> a tight deadline, a hell of a lot longer).
>
> In your case, you will probably be looking at this line:
>
> outname=input+'bt' ;output file name;
>
> What's wrong with it? Hard to say on the surface. The
> code looks good, no quotes missing or anything. Everything's
> spelled OK. But what are you trying to do? Create an output
> filename, right? A string. Are your arguments strings? Well,
> don't know. Let's see.
>
> IDL> Help, input
> INPUT BYTE = Array[360, 360]
>
> A byte array!? That's not what I thought input was!
>
> Uh, huh. And that's the problem. In fact, now the
> error message makes some sense. You are trying to
> add apples and oranges and the computer is telling you
> it doesn't know how to do that.
>
> You probably meant something like this:
>
> outname = files[x] + 'bl'
>
> Or, perhaps something more sophisticated, like this:
>
> name = StrSplit(files[x], '.', /Extract)
> outname = name[0] + 'bl.' + name[1]
> Print, files[x], outname
> picture123.tif picture123bl.tif
>
> OK, fix that, then recompile and run it again.
>
> What!? Another error! Oh, oh. This is too much like
> work. No wonder I don't write programs for a living.
> This kind of stuff drives me crazy!!!
>
> What the hell is the matter with that WRITE_TIFF line!?
> I copied that from Mike's program and *his* works!
>
> Oh, wait a minute. Maybe I copied that from his
> program that didn't work. :-(
>
> In any case, I would turn this (which surely won't work):
>
> cd, store
> openw,1, outname ;opens a file with outname filename;
> write_tiff,input ;writes a tiff file of input array
> close,1
> free_lun,1
>
> Into this:
>
> cd, store
> write_tiff, outname, input
>
> *Then* we might get somewhere! :-)
>
> Cheers,
>
> David
|
|
|
Re: read/writing tiff files [message #35630 is a reply to message #35629] |
Sat, 28 June 2003 07:26  |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
Alexandra Panton writes:
> my code so far...
>
> stuff = ('f:\ftp_web_root\Recent\hawaii\GOES_9\all')
> store = ('d:\goes\hawaii')
>
> cd, stuff
> ...
> outname=input+'bt' ;output file name;
> cd, store
> openw,1, outname ;opens a file with outname filename;
> write_tiff,input ;writes a tiff file of input array
> close,1
> free_lun,1
> x=x+1 ;loops round to next image;
> endwhile
> end
>
> When i run this it stops at the openw command with a type conversion
> error: Unable to convert given STRING to Byte.
When you get the error message, you should read it carefully
to see what line the error occurs on. They you go to that
line in the program and stare at it for a period of time that
is inversely proportional to the time you have been working
with IDL (or sometimes, in rare cases, or if you are under
a tight deadline, a hell of a lot longer).
In your case, you will probably be looking at this line:
outname=input+'bt' ;output file name;
What's wrong with it? Hard to say on the surface. The
code looks good, no quotes missing or anything. Everything's
spelled OK. But what are you trying to do? Create an output
filename, right? A string. Are your arguments strings? Well,
don't know. Let's see.
IDL> Help, input
INPUT BYTE = Array[360, 360]
A byte array!? That's not what I thought input was!
Uh, huh. And that's the problem. In fact, now the
error message makes some sense. You are trying to
add apples and oranges and the computer is telling you
it doesn't know how to do that.
You probably meant something like this:
outname = files[x] + 'bl'
Or, perhaps something more sophisticated, like this:
name = StrSplit(files[x], '.', /Extract)
outname = name[0] + 'bl.' + name[1]
Print, files[x], outname
picture123.tif picture123bl.tif
OK, fix that, then recompile and run it again.
What!? Another error! Oh, oh. This is too much like
work. No wonder I don't write programs for a living.
This kind of stuff drives me crazy!!!
What the hell is the matter with that WRITE_TIFF line!?
I copied that from Mike's program and *his* works!
Oh, wait a minute. Maybe I copied that from his
program that didn't work. :-(
In any case, I would turn this (which surely won't work):
cd, store
openw,1, outname ;opens a file with outname filename;
write_tiff,input ;writes a tiff file of input array
close,1
free_lun,1
Into this:
cd, store
write_tiff, outname, input
*Then* we might get somewhere! :-)
Cheers,
David
--
David W. Fanning, Ph.D.
Fanning Software Consulting, Inc.
Phone: 970-221-0438, E-mail: david@dfanning.com
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Toll-Free IDL Book Orders: 1-888-461-0155
|
|
|
Re: read/writing tiff files [message #35632 is a reply to message #35630] |
Sat, 28 June 2003 04:32  |
R.Bauer
Messages: 1424 Registered: November 1998
|
Senior Member |
|
|
Reimar Bauer wrote:
> Alexandra Panton wrote:
>
>> ok, this is probably a really simple question but having decided that
>> having 500+ images to process I needed to do some idl programming !
>> What i want to do is really simple - but as with all things and
>> computers simple rapidly progresses to the impossible :)
>>
>> Here's what I want to do:
>> I have a directory on my computer with all my images, - tiff files in,
>> I want to read them into an array - I can do this bit, apply my
>> processing steps (having trouble with that!), then write the output as
>> a tiff or jpg file.
>>
>> I have managed to do this to a fashion but it writes blank files -
>> very useful!
>>
>> my code so far...
>
> Dear Alexandra,
>
> there are a lot of tips available at Davids page
> www.dfanning.com
>
> Here in short how I would do this:
>
> stuff = 'f:\ftp_web_root\Recent\hawaii\GOES_9\all'
> file=file_search(stuff,'*.tif',COUNT=n)
> for i=0L,n-1 do begin
> result=query_image(file[i],info)
> print,info.dimensions
> help,info,/str
> img=read_image(files[i],red,green,blue)
> img=(330-(0.5*img))
> write_image,'d:\goes\hawaii\changed_'+files[i],'TIFF',red,gr een,blue
> endfor
typing bug, this always happens if you don't compile yourself such an
example
write_image,'d:\goes\hawaii\changed_'+file[i],'TIFF',red,gre en,blue
Reimar
>
> You should have a look at the info structure of the query function.
> I don't know in which way your images are color coded. I would suggest to
> read the tips on Davids page regarding color problems too.
>
> best regards
>
> Reimar
>
--
Forschungszentrum Juelich
email: R.Bauer@fz-juelich.de
http://www.fz-juelich.de/icg/icg-i/
============================================================ ======
a IDL library at ForschungsZentrum Juelich
http://www.fz-juelich.de/icg/icg-i/idl_icglib/idl_lib_intro. html
|
|
|
Re: read/writing tiff files [message #35633 is a reply to message #35632] |
Sat, 28 June 2003 04:28  |
R.Bauer
Messages: 1424 Registered: November 1998
|
Senior Member |
|
|
Alexandra Panton wrote:
> ok, this is probably a really simple question but having decided that
> having 500+ images to process I needed to do some idl programming !
> What i want to do is really simple - but as with all things and
> computers simple rapidly progresses to the impossible :)
>
> Here's what I want to do:
> I have a directory on my computer with all my images, - tiff files in,
> I want to read them into an array - I can do this bit, apply my
> processing steps (having trouble with that!), then write the output as
> a tiff or jpg file.
>
> I have managed to do this to a fashion but it writes blank files -
> very useful!
>
> my code so far...
Dear Alexandra,
there are a lot of tips available at Davids page
www.dfanning.com
Here in short how I would do this:
stuff = 'f:\ftp_web_root\Recent\hawaii\GOES_9\all'
file=file_search(stuff,'*.tif',COUNT=n)
for i=0L,n-1 do begin
result=query_image(file[i],info)
print,info.dimensions
help,info,/str
img=read_image(files[i],red,green,blue)
img=(330-(0.5*img))
write_image,'d:\goes\hawaii\changed_'+files[i],'TIFF',red,gr een,blue
endfor
You should have a look at the info structure of the query function.
I don't know in which way your images are color coded. I would suggest to
read the tips on Davids page regarding color problems too.
best regards
Reimar
--
Forschungszentrum Juelich
email: R.Bauer@fz-juelich.de
http://www.fz-juelich.de/icg/icg-i/
============================================================ ======
a IDL library at ForschungsZentrum Juelich
http://www.fz-juelich.de/icg/icg-i/idl_icglib/idl_lib_intro. html
|
|
|