Log in

View Full Version : Image panning


Atamido
11th December 2003, 04:24
Since I couldn't find it anywhere else, I thought I might post it here as it took so long to figure out.

This script has you input an image and the number of pixels to pan. It then creates video of a panning image.

function panning(clip c, int frame, int pan)
{
a = (pan - frame)
c = crop(c, frame, 0, -a, 0)
c = AddBorders(c, pan, 0, 0, 0)
return c
}


#The image you want to pan.
image = "test.bmp"

#How many pixels you want to pan through.
pansize = 3275

#The frames per second you want playback to occur at.
fps = 60


b = ImageReader(image, 0, pansize, fps)

e = ScriptClip(b, "panning(b, current_frame, pansize)")

f = crop(e, pansize, 0, 0, 0)

f Yes, I realize that you could do this with less copying, but I wanted to keep them all seperate to make it easier for me to do stuff with them.

Also, it should be pretty easy to add in a few line that would allow you to specify the total number of frames that you want to pan over. I just don't need to and I'm to lazy.

Search words: framenumber frame number scriptclip pan panoramic image panning

Atamido
11th December 2003, 06:16
Okay, I ended up needing it. Here is a version of the script that lets you enter a total number of frames so that you can do more or less than 1 pixel shift per frame.
function panning(clip c, int frame, int pan, float ppf)
{
a = (pan - Int(frame*ppf))
c = crop(c, Int(frame*ppf), 0, -a, 0)
c = AddBorders(c, pan, 0, 0, 0)
return c
}


#The image you want to pan.
image = "messyroom4.bmp"

#How many pixels you want to pan through.
pansize = 3275

#It looks best with one frame per pixel shift,
#but if you want a different ratio, then change this
totalframes = pansize

#The frames per second you want playback to occur at.
fps = 60

pixelsperframe = pansize/totalframes


b = ImageReader(image, 0, totalframes, fps)

e = ScriptClip(b, "panning(b, current_frame, pansize, pixelsperframe)")

f = crop(e, pansize, 0, 0, 0)

f

Atamido
11th December 2003, 08:17
DO NOT USE THIS IF YOU WANT TO HAVE LESS THAN ONE FRAME PER PIXEL SHIFT.

Here is another version of the above script. This makes it so that if you want to have more than one frame per pixel shift(IE, really really slow pan), it will be smoothed out. I'm pretty surprised by how well it works.

If you are using a 1/1 ratio, the first one would be fastest. While this filter could also be altered to make things more smooth when doing less than one frame per pixel shift, that is more work than I want to do on it. Anyone else is welcome to do it.

I picked LanczosResize, but you could do whatever you like. If you are doing even numbers for frames/pixelshift like 2/1, 3/1, etc then changing the first resize to PointResize would be fastest and most accurate. However in all other cases it would be least accurate.
function panning(clip c, int frame, int pan, float ppf)
{
a = Int((pan - (frame*ppf))/ppf)
m = Int(pan/ppf) - a
c = crop(c, m, 0, -a, 0)
c = AddBorders(c, int(pan/ppf), 0, 0, 0)
return c
}


#The image you want to pan.
image = "test.bmp"

#How many pixels you want to pan through.
pansize = 500

#If you set a total number of frames instead of the pansize,
#it MUST be a higher number than pansize.
totalframes = pansize

#The frames per second you want playback to occur at.
fps = 60


pixelsperframe = (float(pansize)/float(totalframes))

b = ImageReader(image, 0, totalframes, fps)

w = b.width

h = b.height

newwidth = int(w*(1/pixelsperframe))

#Resize method is whatever your prefered is below.
#BicubicResize BilinearResize LanczosResize PointResize
g = LanczosResize(b, newwidth, h)

e = ScriptClip(g, "panning(g, current_frame, pansize, pixelsperframe)")

f = crop(e, int(pansize/pixelsperframe), 0, 0, 0)

#Risize method is whatever your prefered is below.
#BicubicResize BilinearResize LanczosResize PointResize
z = LanczosResize(f, (w-pansize), h)

z

Edit: Fixed a rounding error in the function that occured with some ppf/pan combinations.

Die*wrek*show
12th January 2010, 23:19
ok, after all but giving up on my animate script(still doesn't work, it just shows a static picture with no movement), i decided to bump this thread

stat=ImageSource("C:\mypath\image.png").loop().trim(0,225).AssumeFPS(24000/1001)
return stat
animate(0,200,"spline36resize",stat,320,176,0,0,172,176,clip,320,176,0,0,172,176)


here is a link to the full image (http://i47.tinypic.com/fk4ev6.png), and the crop (http://i46.tinypic.com/331nmsl.png). i tried animating the full image, then i tried switching it to what you see here. after spending all night on it, neither worked in the end.

all i'm trying to do, is create a video where the cloud moves from where it is now, to the left, about 2/3 of the way towards the other side. i'm not trying to scroll the cloud from the edge of the screen. just move it over to the left. low fps jerkiness is welcome.

Now, I saw the script the OP posted. To my amazement, it worked with only two minor changes. But the pan size is so small, it doesn't cover enough distance. So tried splicing a bunch of them together end to end to get the full distance, and that's not working. Help?

function panning(clip c, int frame, int pan)
{
a = (pan - frame)
c = crop(c, frame, 0, -a, 0)
c = AddBorders(c, pan, 0, 0, 0)
return c
}


#The image you want to pan.
image = "C:\mypath\image.png"

#How many pixels you want to pan through.
pansize = 4

#The frames per second you want playback to occur at.
fps = 8


b = ImageReader(image, 0, pansize, fps)

e = ScriptClip(b, "panning(b, current_frame, pansize)")

f = crop(e, pansize, 0, 0, 0)

f

a=f
b=f
c=f
d=f
e=f
f=f
g=f

a++b++c++d++e++f++g

Atamido
13th January 2010, 01:52
Well, I'm not entirely sure what you're trying to accomplish, but my script was designed to pan through an entire image, from left to right. The width of the video is determined by the image size minus the number of pixels panned.

If I am understanding you correctly, you want the cloud to move from the left to the right, so you will need more space on the sides for panning. Also, since the script pans from left to right, the cloud will move from right to left. The easiest way to fix this is to play the video in reverse. So using this image:
http://i49.tinypic.com/1183rc6.png

and the second script I posted, here is what I would do:
function panning(clip c, int frame, int pan, float ppf)
{
a = (pan - Int(frame*ppf))
c = crop(c, Int(frame*ppf), 0, -a, 0)
c = AddBorders(c, pan, 0, 0, 0)
return c
}


#The image you want to pan.
image = "1183rc6.png"

#How many pixels you want to pan through.
pansize = 150

#It looks best with one frame per pixel shift,
#but if you want a different ratio, then change this
totalframes = pansize

#The frames per second you want playback to occur at.
fps = 60

pixelsperframe = pansize/totalframes


b = ImageReader(image, 0, totalframes, fps)

e = ScriptClip(b, "panning(b, current_frame, pansize, pixelsperframe)")

f = crop(e, pansize, 0, 0, 0)

g = Reverse(f)

g I added 150 pixels of black on the right side of the image, set the pan size to 150, and said to play the video in reverse at the end.

Die*wrek*show
13th January 2010, 06:06
hey thanks that worked.

i tweaked it slightly to slow it down, to take out reverse, and to introduce some jerkiness. final script.

function panning(clip c, int frame, int pan, float ppf)
{
a = (pan - Int(frame*ppf))
c = crop(c, Int(frame*ppf), 0, -a, 0)
c = AddBorders(c, pan, 0, 0, 0)
return c
}


#The image you want to pan.
image = "C:\mypath\cloud.png"

#How many pixels you want to pan through.
pansize = 130

#It looks best with one frame per pixel shift,
#but if you want a different ratio, then change this
totalframes = pansize

#The frames per second you want playback to occur at.
fps = 10

pixelsperframe = pansize/totalframes


b = ImageReader(image, 0, totalframes, fps)

e = ScriptClip(b, "panning(b, current_frame, pansize, pixelsperframe)")

f = crop(e, pansize, 0, 0, 0)

g = selectodd(f)

g




well, actually that's not the final script because as most of you may have guessed this is just a segment, this script will get imported into another script to make the final .swf.

i never did figure out how the floats work(float src_left, float src_width, ect...), if i could have gotten that i'm sure i could have just used animate instead. but, that's definitely a lesson for another day. i'm exhausted.

thanks again for your help.

Gavino
13th January 2010, 13:37
i never did figure out how the floats work(float src_left, float src_width, ect...), if i could have gotten that i'm sure i could have just used animate instead.
stat=ImageSource("C:\mypath\image.png").loop().trim(0,225).AssumeFPS(24000/1001)
animate(stat, 0,200,"spline36resize",172,176,0.0,0,172,176,172,176,130.0,0,172,176)
This varies src_left from 0.0 to 130.0, making the image move to the left.