Page 1 of 1

Mean Average Cumulative (~5800 frames)

Posted: 2013-11-26T12:54:23-07:00
by patdavid
Hi all!

I've been doing some mean averaging of different stuff for a while now using IM, and I had a question I hoped some guru could help me solve.

I have a few music videos that I've dumped all of the frames for, then batch mean averaged all of the frames to produce a final mean average output of all of the video frames:

http://blog.patdavid.net/2013/09/mean-a ... ideos.html

In playing with it, I had another idea, but am not sure of the best way to implement it. I'd like to have a running cumulative result of all of the frames from a video as well.

For example, for any given frame, say 250, I'd like to create a new frame 250 that is the cumulative mean averaging of all of the frames that came before it. Then for 251, 252, etc...

I can't seem to find a good way to do this without crushing IM (when creating just a single image from all the frames, I could chunk the script up to do it in factor batches of the total number of frames, which helped speed things up a bit).

I had thought about using dissolve and a variable opacity for the overlying image, but that doesn't seem to quite do what I want (and I don't think the math works out without having to go back and re-average all of the previous frames with an adjusted opacity).

Anyone have any thoughts?

Re: Mean Average Cumulative (~5800 frames)

Posted: 2013-11-26T13:15:36-07:00
by patdavid
After looking at a newer version of IM, it appears that -poly may be what I'm looking for?

So if I have a frame 4, that is the mean average of all frames up to (and including 4), I can then add frame 5 to the cumulative average through the coefficient weighting in -poly? (ie: upto4.png 5.png -poly "0.8,1 0.2,1" output.png)?

Re: Mean Average Cumulative (~5800 frames)

Posted: 2013-11-26T13:31:35-07:00
by fmw42
In unix, try this (untested)


i=1
firstframe=1
lastframe=10
numframes=$((lastframe-firstframe+1))
frame=$firstframe
convert yourimage.png[$firstframe] previousresult.miff
while [ $i -le $numframes ]
do
j=$((i + 1))
frame=$((frame+1))
echo "iteration=$i frame=$frame"
#compute running average percentages
new=`convert xc: -format "%[fx:100/$j]" info:`
old=`convert xc: -format "%[fx:100-$new]" info:`
convert yourimage.png[$frame] previousresult.miff -gravity center -define compose:args=$old%x$new% \
-compose blend -composite previousresult.miff
fi
i=$((i + 1))
done
convert previousresult.miff finaloutput.png


It assumes images are frames. If you just have numbered images, you can modify as needed to replace frames with image numbers.