> 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
|