View Full Version : Loading Image Sequence
Blue_MiSfit
9th June 2008, 08:42
Hey folks,
I have a series of still images taken with my digital camera. They're sequential, and I'm playing with using MVTools to interpolate to 25fps, assuming a 2fps input. It looks pretty cool, but I'm running into difficulty with ImageReader/ImageSource.
1) How do I load images of any arbitrary size into a sequence together? I want to basically have AviSynth look at each image, select a clip size that matches the largest image, and matte in all the others - ideally scaling up with correct aspect ratio if needed. Most of my images have similar resolution, but have different orientation.
2) I'm unclear on the sprintf syntax necessary. Say I have the following sequence:
img001.jpg img002.jpg, img003.jpg... img080.jpg
How do I load all those? Using:
ImageSource("c:\img%d.jpg", 001, 080, 2) fails.
Help! :)
MVFlowFPS does some really interesting things!
~MiSfit
smok3
9th June 2008, 09:06
1. no way (i think).
2. try
ImageSource("c:\img%03d.jpg", 001, 080, 2)
Blue_MiSfit
9th June 2008, 21:25
does the %03d syntax imply 3 digits?
~MiSfit
gzarkadas
9th June 2008, 21:28
...How do I load images of any arbitrary size into a sequence together? I want to basically have AviSynth look at each image, select a clip size that matches the largest image, and matte in all the others - ideally scaling up with correct aspect ratio if needed. Most of my images have similar resolution, but have different orientation. ...
This will scale images by stretching (I now you want zoom instead, but be patient and read up to the end :)), if you put in the right values for the filenames and index numbers (you will need my lib, of course :p):
LoadPackage("avslib", "array")
function ImportImage(int n, string prefix, int fieldwidth, string extension, int "setfps") {
setfps = Default(setfps, 24)
filename = prefix + String(n, "%0" + String(fieldwidth) +".0f") + "." + extension
return ImageSource(filename, 0, 0, fps=setfps)
}
# enter the number of images here (assumes a range 0..num_img-1)
# if a range k..n is wanted modify args to ArrayRange or hard-code it
# such as idx = "12,23,24,25,28,31"
num_img = 4
# put prefix, fieldwidth, extension in a 3-quoted string
# I have used the values in your post just to show the way to do it
extra_args = """ "img", 3, "jpg", 2 """
idx = ArrayRange(0, num_img - 1)
images = idx.ArrayOpFunc("ImportImage", extra_args)
max_w = images.ArrayOpFunc("Width").ArrayMax()
max_h = images.ArrayOpFunc("Height").ArrayMax()
#an example; other resizers can be chosen; 2nd arg is a string as extra_args above
resized = images.ArrayOpFunc("LanczosResize", String(max_w) + "," + String(max_h))
clip = resized.ArraySum() # this joins all images in a single clip; modify it as wished
return clip # here we are just returning it (its an example)
For scaling up with correct aspect ratio you can use any custom resize function instead of the LanczosResize that I have used here as an example.
You can use AVSLib's ResizeToFit filter for this purpose, but you will have to download the latest revision from CVS (http://avslib.cvs.sourceforge.net/*checkout*/avslib/avslib/filters/resize.avsi?revision=1.8) - it contains a necessary bug-fix in order for zoom mode (the default) to work - and replace the installed resize.avsi file (inside avslib/filters subfolder) with this one.
Then make the following modifications to the script above:
#add this line at the top:
LoadPackage("avslib", "filters")
...
# replace resized = ... line with this two lines:
SetDefaultResizer("LanczosResize")
resized = images.ArrayOpFunc("ResizeToFit", String(max_w) + "," + String(max_h))
I don't know how many images can be processed at one batch with this script, since I made the test with relatively few. You may run out of memory if images are many and with large size. If you hit on this, reduce the number of images loaded per script. If breaking on multiple scripts, you can append the largest width & height image(s) in each image set so that all clips have the same dimensions and trim them off at the end, after the resize.
Have fun :).
mikeytown2
9th June 2008, 22:48
2) I'm unclear on the sprintf syntax necessary.
If you didn't have arbitrary sizes, ImageSequence could have been an option.
http://forum.doom9.org/showthread.php?t=109997
I recently updated the source filters wiki (http://avisynth.org/mediawiki/External_filters#Source_Filters), thats how i found out about wild card support in ImageSequence.
@gzarkadas Nice example! If i wanted to could i could use ZoomBox in that example, because you use ArrayOpFunc() to resize all the images. Taking this one step further, you could run a filter/function on each image and then do the resize at the end, for higher speed/quality if using a filter.
Blue_MiSfit
9th June 2008, 23:23
Yowza!
Thanks!
I will have try this all out when i get home!
~MiSfit
gzarkadas
9th June 2008, 23:45
...If i wanted to could i could use ZoomBox in that example, because you use ArrayOpFunc() to resize all the images. Taking this one step further, you could run a filter/function on each image and then do the resize at the end, for higher speed/quality if using a filter.
Yes, all the possibilities are open :); you just have to feed the right function and arguments to array operators (http://avslib.sourceforge.net/tutorials/operators.html) (ArrayOpFunc and ArraySum are two cases of them).
vBulletin® v3.8.11, Copyright ©2000-2026, vBulletin Solutions Inc.