Averaging a sequence 10 frames at a time

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
BryantMoore
Posts: 56
Joined: 2011-04-23T22:21:52-07:00
Authentication code: 8675308

Averaging a sequence 10 frames at a time

Post by BryantMoore » 2011-12-02T04:08:55-07:00

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.

User avatar
fmw42
Posts: 22486
Joined: 2007-07-02T17:14:51-07:00
Location: Sunnyvale, California, USA

Re: Averaging a sequence 10 frames at a time

Post by fmw42 » 2011-12-02T11:09:49-07:00

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

BryantMoore
Posts: 56
Joined: 2011-04-23T22:21:52-07:00
Authentication code: 8675308

Re: Averaging a sequence 10 frames at a time

Post by BryantMoore » 2011-12-02T12:56:14-07:00

I probably should have been more clear, I have over 1000 images to work with which I need to process in separate batches.

User avatar
fmw42
Posts: 22486
Joined: 2007-07-02T17:14:51-07:00
Location: Sunnyvale, California, USA

Re: Averaging a sequence 10 frames at a time

Post by fmw42 » 2011-12-02T14:38:33-07:00

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

BryantMoore
Posts: 56
Joined: 2011-04-23T22:21:52-07:00
Authentication code: 8675308

Re: Averaging a sequence 10 frames at a time

Post by BryantMoore » 2011-12-02T15:03:09-07:00

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.

User avatar
fmw42
Posts: 22486
Joined: 2007-07-02T17:14:51-07:00
Location: Sunnyvale, California, USA

Re: Averaging a sequence 10 frames at a time

Post by fmw42 » 2011-12-02T16:22:26-07:00

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.

User avatar
anthony
Posts: 8878
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Averaging a sequence 10 frames at a time

Post by anthony » 2011-12-04T18:26:52-07:00

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.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
http://www.imagemagick.org/Usage/

User avatar
anthony
Posts: 8878
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Averaging a sequence 10 frames at a time

Post by anthony » 2011-12-04T18:28:30-07:00

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.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
http://www.imagemagick.org/Usage/

BryantMoore
Posts: 56
Joined: 2011-04-23T22:21:52-07:00
Authentication code: 8675308

Re: Averaging a sequence 10 frames at a time

Post by BryantMoore » 2011-12-05T03:16:42-07:00

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

User avatar
whugemann
Posts: 257
Joined: 2011-03-28T07:11:31-07:00
Authentication code: 8675308
Location: Münster, Germany 52°N,7.6°E

Re: Averaging a sequence 10 frames at a time

Post by whugemann » 2011-12-05T13:29:29-07:00

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.
Wolfgang Hugemann

Post Reply