comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » write_png help
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
write_png help [message #93931] Thu, 01 December 2016 00:56 Go to next message
gunvicsin11 is currently offline  gunvicsin11
Messages: 93
Registered: November 2012
Member
Hi all,
I have given below my program to create a series of frame*.png. But after doing this, s number of frames are created. But all the frames are showing same data. I think there is some problem with the code below, Can anyone please let me know what is the problem here.


restore,'negdatanew.sav',/v
s=size(ksom.data,/dim)
for i=0,s(2)-1 do begin
write_png,'frame'+string(i)+'.png',ksom(i).data
write_png,'frame'+string(i)+'.png',tvrd(/true)
endfor


thanks
Re: write_png help [message #93932 is a reply to message #93931] Thu, 01 December 2016 01:33 Go to previous messageGo to next message
Sergey Anfinogentov is currently offline  Sergey Anfinogentov
Messages: 11
Registered: September 2012
Junior Member
"write_png,'frame'+string(i)+'.png',tvrd(/true)" - Here you write the content of your current direct graphics window, but you don't redraw it inside the FOR loop. Therefore, all images are the same.

> Hi all,
> I have given below my program to create a series of frame*.png. But after doing this, s number of frames are created. But all the frames are showing same data. I think there is some problem with the code below, Can anyone please let me know what is the problem here.
>
>
> restore,'negdatanew.sav',/v
> s=size(ksom.data,/dim)
> for i=0,s(2)-1 do begin
> write_png,'frame'+string(i)+'.png',ksom(i).data
> write_png,'frame'+string(i)+'.png',tvrd(/true)
> endfor
>
>
> thanks
Re: write_png help [message #93933 is a reply to message #93932] Thu, 01 December 2016 02:07 Go to previous messageGo to next message
gunvicsin11 is currently offline  gunvicsin11
Messages: 93
Registered: November 2012
Member
On Thursday, December 1, 2016 at 3:03:57 PM UTC+5:30, Sergey Anfinogentov wrote:
> "write_png,'frame'+string(i)+'.png',tvrd(/true)" - Here you write the content of your current direct graphics window, but you don't redraw it inside the FOR loop. Therefore, all images are the same.
>
>> Hi all,
>> I have given below my program to create a series of frame*.png. But after doing this, s number of frames are created. But all the frames are showing same data. I think there is some problem with the code below, Can anyone please let me know what is the problem here.
>>
>>
>> restore,'negdatanew.sav',/v
>> s=size(ksom.data,/dim)
>> for i=0,s(2)-1 do begin
>> write_png,'frame'+string(i)+'.png',ksom(i).data
>> write_png,'frame'+string(i)+'.png',tvrd(/true)
>> endfor
>>
>>
>> thanks

So how do we do this in a loop, because if I dont give this write_png,'frame'+string(i)+'.png',tvrd(/true) then I am getting some odd values in between the image.
Re: write_png help [message #93934 is a reply to message #93931] Thu, 01 December 2016 03:24 Go to previous messageGo to next message
dg86 is currently offline  dg86
Messages: 118
Registered: September 2012
Senior Member
On Thursday, December 1, 2016 at 3:56:48 AM UTC-5, sid wrote:
> Hi all,
> I have given below my program to create a series of frame*.png. But after doing this, s number of frames are created. But all the frames are showing same data. I think there is some problem with the code below, Can anyone please let me know what is the problem here.
>
>
> restore,'negdatanew.sav',/v
> s=size(ksom.data,/dim)
> for i=0,s(2)-1 do begin
> write_png,'frame'+string(i)+'.png',ksom(i).data
> write_png,'frame'+string(i)+'.png',tvrd(/true)
> endfor
>
>
> thanks

If you're doing this at the command line or in a batch file, the FOR loop has to be
written as a single line of code.
Each of the commands within the FOR loop, furthermore, has to end with
the "command termination" character, '&'. A loop that loops over three
commands could be written on a single line as

for i = 0, s[2]-1 do begin command1 & command2 & command3 & endfor

You can avoid having a long ugly line of code by using the "line continuation" character, '$'.
In that case, my example could be formatted as

for i = 0, s[2]-1 do begin $
command1 & $
command2 & $
command3 & $
endfor

Notice that there's only a continuation character after BEGIN. You don't want to
end the FOR loop before any of the commands are executed!

If you don't express the FOR loop as a single logical line of code, only the first line will
actually execute within the loop. In your case, that would be the line that reads

for i = 0, s[0]-1 do begin

The loop will increase the variable i from 0 to s[0]-1, without doing anything else.
Once that's done, the script will execute the next line (write_png ...) and write one
image for the particular case, i = s[0]-1, which is the value of i at the end of the loop.

You only need to express a FOR loop as a single line of code if
(1) you're at the command line or (2) you're creating a batch file
(e.g. mybatchfile.pro) and running it using the '@' directive (e.g. IDL> @mybatchfile).

All the best,

David
Re: write_png help [message #93936 is a reply to message #93934] Thu, 01 December 2016 08:36 Go to previous messageGo to next message
Markus Schmassmann is currently offline  Markus Schmassmann
Messages: 129
Registered: April 2016
Senior Member
On 12/01/2016 12:24 PM, David Grier wrote:
> for i = 0, s[0]-1 do begin
>
> The loop will increase the variable i from 0 to s[0]-1, without doing anything else.
> Once that's done, the script will execute the next line (write_png ...) and write one
> image for the particular case, i = s[0]-1, which is the value of i at the end of the loop.
actually, at the end of the last loop i is incremented once more:
IDL> for i=0,9 do begin
IDL> print, i
10
Re: write_png help [message #93938 is a reply to message #93933] Fri, 02 December 2016 03:13 Go to previous message
Sergey Anfinogentov is currently offline  Sergey Anfinogentov
Messages: 11
Registered: September 2012
Junior Member
> On Thursday, December 1, 2016 at 3:03:57 PM UTC+5:30, Sergey Anfinogentov wrote:
>> "write_png,'frame'+string(i)+'.png',tvrd(/true)" - Here you write the content of your current direct graphics window, but you don't redraw it inside the FOR loop. Therefore, all images are the same.
>>
>>> Hi all,
>>> I have given below my program to create a series of frame*.png. But after doing this, s number of frames are created. But all the frames are showing same data. I think there is some problem with the code below, Can anyone please let me know what is the problem here.
>>>
>>>
>>> restore,'negdatanew.sav',/v
>>> s=size(ksom.data,/dim)
>>> for i=0,s(2)-1 do begin
>>> write_png,'frame'+string(i)+'.png',ksom(i).data
>>> write_png,'frame'+string(i)+'.png',tvrd(/true)
>>> endfor
>>>
>>>
>>> thanks
>
> So how do we do this in a loop, because if I dont give this write_png,'frame'+string(i)+'.png',tvrd(/true) then I am getting some odd values in between the image.

I assume that you you run a normal IDL program (not a batch file) and don't type all lines directly to the command line. Otherwise, see other comments.
1) What kind of data do you have in your "ksom.data " variable? If it is not a byte array, you can't pass it directly to write_png routine. First, you need to rescale it and convert to array of bytes:
image = bytscl(ksom.data[*,*,i])
Only after that you can save the image in a PNG file:
write_png, 'frame'+string(i)+'.png', image
In this case your code will be the following:

restore,'negdatanew.sav'
s=size(ksom.data,/dim)
for i=0,s(2)-1 do begin
image = bytscl(ksom.data[*,*,i])
write_png, 'frame'+string(i)+'.png', image
endfor
2) If your want to produce nice images with axes and in colour, you need to plot it first in a direct graphics window, than read the result and write it to a png file.

restore,'negdatanew.sav'
s=size(ksom.data,/dim)
for i=0,s(2)-1 do begin
tvscl, ksom.data[*,*,i] ; replace with your plotting code
image = tvrd(true =1)
write_png, 'frame'+string(i)+'.png', image
endfor
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Transpose of string along with float variable??
Next Topic: MosaicRaster results in "Unable to Export"

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 11:41:05 PDT 2025

Total time taken to generate the page: 0.00597 seconds