help with cgDrawVectors in write_gif procedure [message #91079] |
Tue, 02 June 2015 08:03  |
g.nacarts
Messages: 148 Registered: November 2013
|
Senior Member |
|
|
Hi
I created the following procedure to overplot vectors on the images.
PRO vectors_overlaid, Image, VX, VY, name
dims_i_need = Size(Dindgen(20,20), /Dimensions)
pos_x = Rebin(Findgen(dims_i_need[0]), dims_i_need[0], dims_i_need[1])
pos_y = Rebin(Reform(Findgen(dims_i_need[1]), 1, dims_i_need[1]), dims_i_need[0], dims_i_need[1])
cgDisplay, 500, 550
cgimage, image
cgDrawVectors, Vx, Vy, pos_x, pos_y,VECCOLORS='yellow', /ORDERED, overplot = 1
Then looping over the time point:
for i=0L,N-1 do begin
vecotrs_overlaid, Reform(Image[i,*,*]), reform(VX[i,*,*]),reform(VY[i,*,*]),('+strtrim(i)+').jpeg')
endfor
Instead of exporting jpegs I want to export gif format instead. I used the write_gif before but I used only images. Now I want to overplot the vectors on the images. Does anyone knows how to use the cgDrawVectors in write_gif procedure?
Many Thanks
|
|
|
Re: help with cgDrawVectors in write_gif procedure [message #91080 is a reply to message #91079] |
Tue, 02 June 2015 08:26   |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
g.nacarts@gmail.com writes:
>
> Hi
>
> I created the following procedure to overplot vectors on the images.
>
> PRO vectors_overlaid, Image, VX, VY, name
>
> dims_i_need = Size(Dindgen(20,20), /Dimensions)
> pos_x = Rebin(Findgen(dims_i_need[0]), dims_i_need[0], dims_i_need[1])
> pos_y = Rebin(Reform(Findgen(dims_i_need[1]), 1, dims_i_need[1]), dims_i_need[0], dims_i_need[1])
>
>
> cgDisplay, 500, 550
> cgimage, image
> cgDrawVectors, Vx, Vy, pos_x, pos_y,VECCOLORS='yellow', /ORDERED, overplot = 1
>
> Then looping over the time point:
>
> for i=0L,N-1 do begin
> vecotrs_overlaid, Reform(Image[i,*,*]), reform(VX[i,*,*]),reform(VY[i,*,*]),('+strtrim(i)+').jpeg')
> endfor
>
>
> Instead of exporting jpegs I want to export gif format instead. I used the write_gif before but I used only images. Now I want to overplot the vectors on the images. Does anyone knows how to use the cgDrawVectors in write_gif procedure?
>
> Many Thanks
void = cgSnapshot(/GIF, Filename='whateverYouLike', /NoDialog)
On-line help here:
http://www.idlcoyote.com/idldoc/cg/index.html
Cheers,
David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.idlcoyote.com/
Sepore ma de ni thue. ("Perhaps thou speakest truth.")
|
|
|
|
|
Re: help with cgDrawVectors in write_gif procedure [message #91088 is a reply to message #91084] |
Wed, 03 June 2015 02:55   |
g.nacarts
Messages: 148 Registered: November 2013
|
Senior Member |
|
|
Well, I typed the following and I ended up with 100 different gif files (i.e. each image in a separate gif). What I want is to play as a movie in one gif file.
for i=0L,N-1 do begin
cgDisplay, 500, 550
cgimage, Reform(Reform(Image[i,*,*])[i,*,*])
cgDrawVectors, reform(VX[i,*,*]),reform(VY[i,*,*]), pos_x, pos_y,VECCOLORS='yellow', /ORDERED, overplot = 1
void = cgSnapshot(/GIF, Filename='C:\Users\Desktop\Vectors('+string(i,format='(i3.3) ')+','+string(level)+','+strtrim(iter)+')', /NoDialog)
endfor
I added the level and iter because is looping over those two loops as well.
|
|
|
Re: help with cgDrawVectors in write_gif procedure [message #91090 is a reply to message #91088] |
Wed, 03 June 2015 03:17   |
Helder Marchetto
Messages: 520 Registered: November 2011
|
Senior Member |
|
|
On Wednesday, June 3, 2015 at 11:55:35 AM UTC+2, g.na...@gmail.com wrote:
> Well, I typed the following and I ended up with 100 different gif files (i.e. each image in a separate gif). What I want is to play as a movie in one gif file.
>
> for i=0L,N-1 do begin
> cgDisplay, 500, 550
> cgimage, Reform(Reform(Image[i,*,*])[i,*,*])
> cgDrawVectors, reform(VX[i,*,*]),reform(VY[i,*,*]), pos_x, pos_y,VECCOLORS='yellow', /ORDERED, overplot = 1
> void = cgSnapshot(/GIF, Filename='C:\Users\Desktop\Vectors('+string(i,format='(i3.3) ')+','+string(level)+','+strtrim(iter)+')', /NoDialog)
> endfor
>
> I added the level and iter because is looping over those two loops as well.
Did you look at the /MULTIPLE option in write_gif?
http://www.exelisvis.com/docs/WRITE_GIF.html
This should do what you're looking for.
cheers,
Helder
|
|
|
|
Re: help with cgDrawVectors in write_gif procedure [message #91093 is a reply to message #91092] |
Wed, 03 June 2015 03:57   |
Helder Marchetto
Messages: 520 Registered: November 2011
|
Senior Member |
|
|
On Wednesday, June 3, 2015 at 12:26:34 PM UTC+2, g.na...@gmail.com wrote:
> Actually I used write_gif before. But I had only one image. Now I need to overplot the vectors on top of the image that's why I didn't manage to do that.
It's a bit tricky, but all the info is out there. Below is a working solution to make a series of gifs with rotating arrow arrow:
pro testGifOut
xSize = 400
ySize = 400
window, xsize=xSize, ysize=ySize, /free
tvscl, bytscl(sin(dist(xSize)))
xPos = cos(!pi*2.0*findgen(11)/10.0)
yPos = sin(!pi*2.0*findgen(11)/10.0)
cgArrow, 0.5, 0.5, 0.3*xPos[0]+0.5, 0.3*yPos[0]+0.5, /Solid, /normal, thick=4, color='red'
inImg = tvrd(0, 0, xSize, ySize, /True)
image2D = color_quan(inImg, 1, r, g, b, Colors=256)
write_gif, 'testGif.gif', image2D, r, g, b, /multiple, repeat_count=0, delay_time=20
for i=1,10 do begin
tvscl, bytscl(sin(dist(xSize)*i*0.1))
cgArrow, 0.5, 0.5, 0.3*xPos[i]+0.5, 0.3*yPos[i]+0.5, /Solid, /normal, thick=4, color='red'
inImg = tvrd(0, 0, xSize, ySize, /True)
image2D = color_quan(inImg, 1, r, g, b, Colors=256)
write_gif, 'testGif.gif', image2D, r, g, b, /multiple, repeat_count=0, delay_time=20
endfor
write_gif, 'testGif.gif', image2D, /close
end
Hope it helps,
Helder
|
|
|
Re: help with cgDrawVectors in write_gif procedure [message #91094 is a reply to message #91093] |
Wed, 03 June 2015 05:39   |
g.nacarts
Messages: 148 Registered: November 2013
|
Senior Member |
|
|
I tried the following but I always get the same error: OPENW: Filename argument must be a scalar string: FILE.
for i=0L, n-1 do begin
cgDisplay, 500, 550
Image = BYTSCL(Image, min=0.,max=160.)
cgimage,Reform(Image[i,*,*])
cgDrawVectors, REFORM(VX[i,*,*]), REFORM(VY[i,*,*]), pos_x, pos_y,VECCOLORS='yellow', /ORDERED, overplot = 1
write_gif,file, Reform(Image[i,*,*]), /multiple
endfor
write_gif, file, /close
|
|
|
Re: help with cgDrawVectors in write_gif procedure [message #91095 is a reply to message #91094] |
Wed, 03 June 2015 05:42   |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
g.nacarts@gmail.com writes:
> I tried the following but I always get the same error: OPENW: Filename argument must be a scalar string: FILE.
>
> for i=0L, n-1 do begin
> cgDisplay, 500, 550
> Image = BYTSCL(Image, min=0.,max=160.)
> cgimage,Reform(Image[i,*,*])
> cgDrawVectors, REFORM(VX[i,*,*]), REFORM(VY[i,*,*]), pos_x, pos_y,VECCOLORS='yellow', /ORDERED, overplot = 1
> write_gif,file, Reform(Image[i,*,*]), /multiple
> endfor
>
> write_gif, file, /close
Perhaps it is easier to just download or use one of the multitude of
free apps that create an animated GIF from individual files.
Cheers,
David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.idlcoyote.com/
Sepore ma de ni thue. ("Perhaps thou speakest truth.")
|
|
|
Re: help with cgDrawVectors in write_gif procedure [message #91096 is a reply to message #91094] |
Wed, 03 June 2015 05:45   |
Helder Marchetto
Messages: 520 Registered: November 2011
|
Senior Member |
|
|
On Wednesday, June 3, 2015 at 2:39:27 PM UTC+2, g.na...@gmail.com wrote:
> I tried the following but I always get the same error: OPENW: Filename argument must be a scalar string: FILE.
>
> for i=0L, n-1 do begin
> cgDisplay, 500, 550
> Image = BYTSCL(Image, min=0.,max=160.)
> cgimage,Reform(Image[i,*,*])
> cgDrawVectors, REFORM(VX[i,*,*]), REFORM(VY[i,*,*]), pos_x, pos_y,VECCOLORS='yellow', /ORDERED, overplot = 1
> write_gif,file, Reform(Image[i,*,*]), /multiple
> endfor
>
> write_gif, file, /close
Hi,
when you get an error that says:
"OPENW: Filename argument must be a scalar string: FILE."
you should check if your variable file is a string or a scalar. In case you're doubting... it has to be a scalar.
Maybe use file[i]?
Cheers,
Helder
|
|
|
|
|
Re: help with cgDrawVectors in write_gif procedure [message #91100 is a reply to message #91096] |
Wed, 03 June 2015 08:39   |
g.nacarts
Messages: 148 Registered: November 2013
|
Senior Member |
|
|
> "OPENW: Filename argument must be a scalar string: FILE."
> you should check if your variable file is a string or a scalar.
I used
help, file
to check whether is a string or a scalar and I got the following
FILE UNDEFINED = <Undefined>
OPENW: Filename argument must be a scalar string: FILE.
I will share my code because maybe I did a mistake somewhere else and I am not able to find it. I have the following procedure. (Image,VX,VY are 3D arrays.)
PRO vectors_overlaid, Image, VX, VY, name
dims_i_need = Size(Dindgen(20,20), /Dimensions)
pos_x = Rebin(Findgen(dims_i_need[0]), dims_i_need[0], dims_i_need[1])
pos_y = Rebin(Reform(Findgen(dims_i_need[1]), 1, dims_i_need[1]), dims_i_need[0], dims_i_need[1])
for i=0L, n-1 do begin
cgDisplay, 500, 550
Image = BYTSCL(Image, min=0.,max=160.)
cgimage,Reform(Image[i,*,*])
cgDrawVectors, REFORM(VX[i,*,*]), REFORM(VY[i,*,*]), pos_x, pos_y,VECCOLORS='yellow', /ORDERED, overplot = 1
write_gif,file, Reform(Image[i,*,*]), /multiple
endfor
write_gif, file, /close
END
Then I called the vectors_overlaid in my main program like this
vectors_overlaid, Image, VX,VY, 'C:\Users\Desktop\Vectors('+string(i,format='(i3.3)')+','+st ring(level)+','+strtrim(iter)+')'.gif'
Why the file is undefined?
|
|
|
Re: help with cgDrawVectors in write_gif procedure [message #91101 is a reply to message #91100] |
Wed, 03 June 2015 08:47   |
Helder Marchetto
Messages: 520 Registered: November 2011
|
Senior Member |
|
|
On Wednesday, June 3, 2015 at 5:39:15 PM UTC+2, g.na...@gmail.com wrote:
>> "OPENW: Filename argument must be a scalar string: FILE."
>> you should check if your variable file is a string or a scalar.
>
> I used
> help, file
> to check whether is a string or a scalar and I got the following
>
> FILE UNDEFINED = <Undefined>
> OPENW: Filename argument must be a scalar string: FILE.
>
> I will share my code because maybe I did a mistake somewhere else and I am not able to find it. I have the following procedure. (Image,VX,VY are 3D arrays.)
>
>
> PRO vectors_overlaid, Image, VX, VY, name
>
> dims_i_need = Size(Dindgen(20,20), /Dimensions)
>
> pos_x = Rebin(Findgen(dims_i_need[0]), dims_i_need[0], dims_i_need[1])
> pos_y = Rebin(Reform(Findgen(dims_i_need[1]), 1, dims_i_need[1]), dims_i_need[0], dims_i_need[1])
>
> for i=0L, n-1 do begin
> cgDisplay, 500, 550
> Image = BYTSCL(Image, min=0.,max=160.)
> cgimage,Reform(Image[i,*,*])
> cgDrawVectors, REFORM(VX[i,*,*]), REFORM(VY[i,*,*]), pos_x, pos_y,VECCOLORS='yellow', /ORDERED, overplot = 1
> write_gif,file, Reform(Image[i,*,*]), /multiple
> endfor
>
> write_gif, file, /close
> END
>
> Then I called the vectors_overlaid in my main program like this
>
> vectors_overlaid, Image, VX,VY, 'C:\Users\Desktop\Vectors('+string(i,format='(i3.3)')+','+st ring(level)+','+strtrim(iter)+')'.gif'
>
> Why the file is undefined?
Ok, this is something you should be able to solve by looking at what the error messages tell you and what the help, file told you (file is undefined!).
In your procedure declaration you use:
PRO vectors_overlaid, Image, VX, VY, name
These variable names have to be used in the procedure. This means that when you call:
vectors_overlaid, Image, VX,VY, 'C:\Users\Desktop\Vectors('+string(i,format='(i3.3)')+','+st ring(level)+','+strtrim(iter)+')'.gif'
the variable "name" assumes the value 'C:\Users\Desktop\Vectors('+string(i,format='(i3.3)')+','+st ring(level)+','+strtrim(iter)+')'.gif'
so in *all* your write_gif commands you should substitute "file" with "name".
That should bring you a step further.
Cheers,
Helder
|
|
|
Re: help with cgDrawVectors in write_gif procedure [message #91102 is a reply to message #91101] |
Wed, 03 June 2015 09:33   |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
Helder writes:
>
> On Wednesday, June 3, 2015 at 5:39:15 PM UTC+2, g.na...@gmail.com wrote:
>>> "OPENW: Filename argument must be a scalar string: FILE."
>>> you should check if your variable file is a string or a scalar.
>>
>> I used
>> help, file
>> to check whether is a string or a scalar and I got the following
>>
>> FILE UNDEFINED = <Undefined>
>> OPENW: Filename argument must be a scalar string: FILE.
>>
>> I will share my code because maybe I did a mistake somewhere else and I am not able to find it. I have the following procedure. (Image,VX,VY are 3D arrays.)
>>
>>
>> PRO vectors_overlaid, Image, VX, VY, name
>>
>> dims_i_need = Size(Dindgen(20,20), /Dimensions)
>>
>> pos_x = Rebin(Findgen(dims_i_need[0]), dims_i_need[0], dims_i_need[1])
>> pos_y = Rebin(Reform(Findgen(dims_i_need[1]), 1, dims_i_need[1]), dims_i_need[0], dims_i_need[1])
>>
>> for i=0L, n-1 do begin
>> cgDisplay, 500, 550
>> Image = BYTSCL(Image, min=0.,max=160.)
>> cgimage,Reform(Image[i,*,*])
>> cgDrawVectors, REFORM(VX[i,*,*]), REFORM(VY[i,*,*]), pos_x, pos_y,VECCOLORS='yellow', /ORDERED, overplot = 1
>> write_gif,file, Reform(Image[i,*,*]), /multiple
>> endfor
>>
>> write_gif, file, /close
>> END
>>
>> Then I called the vectors_overlaid in my main program like this
>>
>> vectors_overlaid, Image, VX,VY, 'C:\Users\Desktop\Vectors('+string(i,format='(i3.3)')+','+st ring(level)+','+strtrim(iter)+')'.gif'
>>
>> Why the file is undefined?
>
> Ok, this is something you should be able to solve by looking at what the error messages tell you and what the help, file told you (file is undefined!).
>
> In your procedure declaration you use:
> PRO vectors_overlaid, Image, VX, VY, name
>
> These variable names have to be used in the procedure. This means that when you call:
> vectors_overlaid, Image, VX,VY, 'C:\Users\Desktop\Vectors('+string(i,format='(i3.3)')+','+st ring(level)+','+strtrim(iter)+')'.gif'
>
> the variable "name" assumes the value 'C:\Users\Desktop\Vectors('+string(i,format='(i3.3)')+','+st ring(level)+','+strtrim(iter)+')'.gif'
>
> so in *all* your write_gif commands you should substitute "file" with "name".
>
> That should bring you a step further.
It should, but it still feels like an unfathomable long way to the
finish line.
Since the images you want to animate already exist in individual files,
if you insist on doing this completely in IDL (not my recommendation),
you should think about opening each file in succession, reading the
image data, and storing that in a new, multiple frame GIF file.
That should be a simple, concise loop to write. The algorithm looks like
this:
1. Open a GIF file, set up for multiple images.
2. Start a loop.
a. Read the image from one of the image files.
b. Store the image in the open GIF file as a "frame"
3. End the loop.
4. Close the open GIF file.
Cheers,
David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.idlcoyote.com/
Sepore ma de ni thue. ("Perhaps thou speakest truth.")
|
|
|
Re: help with cgDrawVectors in write_gif procedure [message #91116 is a reply to message #91102] |
Fri, 05 June 2015 07:34   |
g.nacarts
Messages: 148 Registered: November 2013
|
Senior Member |
|
|
I will use an app to create an animated gif is much easier at the end.
I have a problem with the cgSnapshot. I wanted to create different folders each time for different level and iteration. At first I saved everything in one folder but it was too messy (Vectors(i,level,iter)).
for i=0L, n-1 do begin
cgDisplay, 500, 550
Image = BYTSCL(Image, min=0.,max=160.)
cgimage,Reform(Image[i,*,*])
cgDrawVectors, REFORM(VX[i,*,*]), REFORM(VY[i,*,*]), pos_x, pos_y,VECCOLORS='yellow', /ORDERED, overplot = 1
void = cgSnapshot(/tif, Filename = 'C:\Users\Desktop\FOLDER\Vectors('+string(i)+','+string(leve l)+','+strtrim(iter)+')', /NoDialog)
endfor
I wanted to save all the time points (i) for each level and iter respectively in a separate folder.
void = cgSnapshot(/JPEG, Filename='C:\Users\Desktop\FOLDER\Vector_Folder('+string(lev el)+','+strtrim(iter)+')\Vectors('+string(i)+')', /NoDialog)
I got this error:"Error opening file".
Is that necessary to create the folders in advanced? They cannot be create during the process?
Because before I did something like that but not with the cgsnapshot
|
|
|
Re: help with cgDrawVectors in write_gif procedure [message #91117 is a reply to message #91116] |
Fri, 05 June 2015 07:45   |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
g.nacarts@gmail.com writes:
>
> I will use an app to create an animated gif is much easier at the end.
>
> I have a problem with the cgSnapshot. I wanted to create different folders each time for different level and iteration. At first I saved everything in one folder but it was too messy (Vectors(i,level,iter)).
>
> for i=0L, n-1 do begin
> cgDisplay, 500, 550
> Image = BYTSCL(Image, min=0.,max=160.)
> cgimage,Reform(Image[i,*,*])
> cgDrawVectors, REFORM(VX[i,*,*]), REFORM(VY[i,*,*]), pos_x, pos_y,VECCOLORS='yellow', /ORDERED, overplot = 1
> void = cgSnapshot(/tif, Filename = 'C:\Users\Desktop\FOLDER\Vectors('+string(i)+','+string(leve l)+','+strtrim(iter)+')', /NoDialog)
> endfor
>
> I wanted to save all the time points (i) for each level and iter respectively in a separate folder.
>
> void = cgSnapshot(/JPEG, Filename='C:\Users\Desktop\FOLDER\Vector_Folder('+string(lev el)+','+strtrim(iter)+')\Vectors('+string(i)+')', /NoDialog)
>
> I got this error:"Error opening file".
> Is that necessary to create the folders in advanced? They cannot be create during the process?
>
> Because before I did something like that but not with the cgsnapshot
Given the history of this discussion, I think I might suspect programmer
error before I blamed cgSnapshot. I've never tried to tell it to open a
file in a location that didn't exist, so I'm not sure what it would do.
I'm pretty sure if someone asked me to do the same, I would complain.
:-)
Cheers,
David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.idlcoyote.com/
Sepore ma de ni thue. ("Perhaps thou speakest truth.")
|
|
|
|