f



write_png help

Hi all,
      I have given below my program to create a series of frame*.png. But a=
fter doing this, s number of frames are created. But all the frames are sho=
wing same data. I think there is some problem with the code below, Can anyo=
ne please let me know what is the problem here.


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


thanks
0
sid
12/1/2016 8:56:46 AM
comp.lang.idl-pvwave 12260 articles. 4 followers. Post Follow

6 Replies
558 Views

Similar Articles

[PageSpeed] 13

"write_png,'frame'+string(i)+'.png',tvrd(/true)"  - Here you write the cont=
ent 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 s=
howing same data. I think there is some problem with the code below, Can an=
yone please let me know what is the problem here.
>=20
>=20
> restore,'negdatanew.sav',/v
> s=3Dsize(ksom.data,/dim)
> for i=3D0,s(2)-1 do begin
> write_png,'frame'+string(i)+'.png',ksom(i).data
> write_png,'frame'+string(i)+'.png',tvrd(/true)=20
> endfor
>=20
>=20
> thanks
0
Sergey
12/1/2016 9:33:55 AM
On Thursday, December 1, 2016 at 3:03:57 PM UTC+5:30, Sergey Anfinogentov w=
rote:
> "write_png,'frame'+string(i)+'.png',tvrd(/true)"  - Here you write the co=
ntent of your current direct graphics window, but you don't redraw it insid=
e the FOR loop. Therefore, all images are the same.
>=20
> > Hi all,
> >       I have given below my program to create a series of frame*.png. B=
ut 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.
> >=20
> >=20
> > restore,'negdatanew.sav',/v
> > s=3Dsize(ksom.data,/dim)
> > for i=3D0,s(2)-1 do begin
> > write_png,'frame'+string(i)+'.png',ksom(i).data
> > write_png,'frame'+string(i)+'.png',tvrd(/true)=20
> > endfor
> >=20
> >=20
> > thanks

So how do we do this in a loop, because if I dont give this write_png,'fram=
e'+string(i)+'.png',tvrd(/true) then I am getting some odd values in betwee=
n the image.
0
gunvicsin11
12/1/2016 10:07:46 AM
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 s=
howing same data. I think there is some problem with the code below, Can an=
yone please let me know what is the problem here.
>=20
>=20
> restore,'negdatanew.sav',/v
> s=3Dsize(ksom.data,/dim)
> for i=3D0,s(2)-1 do begin
> write_png,'frame'+string(i)+'.png',ksom(i).data
> write_png,'frame'+string(i)+'.png',tvrd(/true)=20
> endfor
>=20
>=20
> thanks

If you're doing this at the command line or in a batch file, the FOR loop h=
as to be
written as a single line of code. =20
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 =3D 0, s[2]-1 do begin command1 & command2 & command3 & endfor

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

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

Notice that there's only a continuation character after BEGIN.  You don't w=
ant 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 th=
e first line will
actually execute within the loop.  In your case, that would be the line tha=
t reads

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

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

You only need to express a FOR loop as a single line of code if=20
(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> @m=
ybatchfile).

All the best,

David
0
David
12/1/2016 11:24:20 AM
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


0
Markus
12/1/2016 4:36:43 PM
> 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 ins=
ide the FOR loop. Therefore, all images are the same.
> >=20
> > > 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 a=
re showing same data. I think there is some problem with the code below, Ca=
n anyone please let me know what is the problem here.
> > >=20
> > >=20
> > > restore,'negdatanew.sav',/v
> > > s=3Dsize(ksom.data,/dim)
> > > for i=3D0,s(2)-1 do begin
> > > write_png,'frame'+string(i)+'.png',ksom(i).data
> > > write_png,'frame'+string(i)+'.png',tvrd(/true)=20
> > > endfor
> > >=20
> > >=20
> > > thanks
>=20
> So how do we do this in a loop, because if I dont give this write_png,'fr=
ame'+string(i)+'.png',tvrd(/true) then I am getting some odd values in betw=
een 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 commands=
..
1) What kind of data do you have in your "ksom.data " variable? If it is no=
t 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 =3D 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',/v=20
       s=3Dsize(ksom.data,/dim)=20
       for i=3D0,s(2)-1 do begin=20
              image =3D bytscl(ksom.data[*,*,i])
              write_png, 'frame'+string(i)+'.png', image
       endfor=20
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',/v=20
       s=3Dsize(ksom.data,/dim)=20
       for i=3D0,s(2)-1 do begin=20
              tvscl, ksom.data[*,*,i] ; replace with your plotting code
               image =3D tvrd(true =3D1)
              write_png, 'frame'+string(i)+'.png', image
       endfor
0
Sergey
12/2/2016 11:09:55 AM
> 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 ins=
ide the FOR loop. Therefore, all images are the same.
> >=20
> > > 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 a=
re showing same data. I think there is some problem with the code below, Ca=
n anyone please let me know what is the problem here.
> > >=20
> > >=20
> > > restore,'negdatanew.sav',/v
> > > s=3Dsize(ksom.data,/dim)
> > > for i=3D0,s(2)-1 do begin
> > > write_png,'frame'+string(i)+'.png',ksom(i).data
> > > write_png,'frame'+string(i)+'.png',tvrd(/true)=20
> > > endfor
> > >=20
> > >=20
> > > thanks
>=20
> So how do we do this in a loop, because if I dont give this write_png,'fr=
ame'+string(i)+'.png',tvrd(/true) then I am getting some odd values in betw=
een 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=
..=20
1) What kind of data do you have in your "ksom.data " variable? If it is no=
t 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:=20
        image =3D bytscl(ksom.data[*,*,i])=20
Only after that you can save the image in  a PNG file:=20
      write_png, 'frame'+string(i)+'.png', image=20
In this case your code will be the following:=20
       =20
       restore,'negdatanew.sav'
       s=3Dsize(ksom.data,/dim)=20
       for i=3D0,s(2)-1 do begin=20
              image =3D bytscl(ksom.data[*,*,i])=20
              write_png, 'frame'+string(i)+'.png', image=20
       endfor=20
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.=20
      =20
       restore,'negdatanew.sav'
       s=3Dsize(ksom.data,/dim)=20
       for i=3D0,s(2)-1 do begin=20
              tvscl, ksom.data[*,*,i] ; replace with your plotting code=20
               image =3D tvrd(true =3D1)=20
              write_png, 'frame'+string(i)+'.png', image=20
       endfor
0
Sergey
12/2/2016 11:13:43 AM
Reply: