Page 1 of 1

Averaging a sequence 10 frames at a time

Posted: 2011-12-02T04:08:55-07:00
by BryantMoore
I have a sequence of TGA images recorded from a video game that I wish to convert to a lower frame rate by averaging adjacent images. I'm trying to do this to create temporally super-sampled motion blur.

I only need to average 10 frames into 1 frame but I'm not sure how to go about writing a command line to automate that. Also, I am using Windows.

Re: Averaging a sequence 10 frames at a time

Posted: 2011-12-02T11:09:49-07:00
by fmw42
see -evaluate sequence mean (replaces the old -average, which I think can still be used)

http://www.imagemagick.org/script/comma ... e-sequence

convert image1 image2 ... image10 -evaluate sequence mean resultimage

Re: Averaging a sequence 10 frames at a time

Posted: 2011-12-02T12:56:14-07:00
by BryantMoore
I probably should have been more clear, I have over 1000 images to work with which I need to process in separate batches.

Re: Averaging a sequence 10 frames at a time

Posted: 2011-12-02T14:38:33-07:00
by fmw42
You will have to write a script to loop over all your images and put 10 names in a command to create one 10 image average, then on the next loop, do 10 more.

Are you trying to average all 1000 images or just individual groups of 10?

You might want to see viewtopic.php?f=1&t=19855

Re: Averaging a sequence 10 frames at a time

Posted: 2011-12-02T15:03:09-07:00
by BryantMoore
I'm trying to average every 10 frames into a single frame. The idea is to convert 240fps into 24fps to achieve good motion blur.

I see in that thread you have a script but I'm not sure how to apply it to my own situation as I'm not familiar with Linux shell scripting. I have Cygwin so I should be able to execute scripts.

Re: Averaging a sequence 10 frames at a time

Posted: 2011-12-02T16:22:26-07:00
by fmw42
sumawo13 wrote:I'm trying to average every 10 frames into a single frame. The idea is to convert 240fps into 24fps to achieve good motion blur.

I see in that thread you have a script but I'm not sure how to apply it to my own situation as I'm not familiar with Linux shell scripting. I have Cygwin so I should be able to execute scripts.

That script was to process any number of images into one image. But Anthony thinks that for some large number of images that it will lose accuracy.

For your situation, you should just collect a list of your images (DOS equivalent of ls), then create a loop to take each successive ten images and just use -evaluate sequence to process 10 at a time.

Unfortunately, I am not a Windows person and cannot help in that regard other than point to http://www.imagemagick.org/Usage/windows/

Cygwin should be able to process unix scripts, though one need be careful with some tricky issues, but my script above is not quite what you want.

Re: Averaging a sequence 10 frames at a time

Posted: 2011-12-04T18:26:52-07:00
by anthony
sumawo13 wrote:I probably should have been more clear, I have over 1000 images to work with which I need to process in separate batches.
The "xargs" comamnd provides an easy why to do this...

Code: Select all

mkdir average
ls images*.jpg | xargs -n 10 sh -c 'convert "$0" "$@" -average average/"$0" ' 
The "xargs" command collects filenames from its input, and adds them as extra arguments to given command.
The -n argument groups 10 filenames at a time.
The "sh" command is only used to allow the image names to be placed at the start of the "convert" command"
when a shell is invoked in this way $0 is the first argument that follows, and the "convert" command saved the averaged results in the new sub-directory using the filename of the first image "$0" in the average.

Just change the "ls" as appropriate to list all the files in sorted order.

NOTE none of this is actually image processing, but shell scripting. There are lots of good guides, which I have thoroughly read. This is just one 'simple' way of processing 10 filenames at a time.

Re: Averaging a sequence 10 frames at a time

Posted: 2011-12-04T18:28:30-07:00
by anthony
One final point.

Average frames to generate a 'faster' video, will tend to generate very blurry movements.
Skipping frames is the more typical method of doing this.

Re: Averaging a sequence 10 frames at a time

Posted: 2011-12-05T03:16:42-07:00
by BryantMoore
I had some help from a friend to write a Bash script which I execute through Cygwin.

Here is the resultant file. http://www.mediafire.com/?xcv0k805rnrjuqx

Re: Averaging a sequence 10 frames at a time

Posted: 2011-12-05T13:29:29-07:00
by whugemann
You're obviously working under Windows (when using Cygwin). For the script processing of video, I would then rather recommend AVIsynth + VirtualDub, see http://www.imagemagick.org/Usage/windows/#auxiliary.