# Average image over $N$ frames with one frame buffer

Can you give some filter that is averaging an image over $$N$$ samples in a recursive way that only needs one frame buffer?

$$\frac{1}{N} \sum_{k=1}^{N} y_{k}(m,n)$$

I can only imagine filters that need $$N-1$$ frame buffers.

1. Take the first frame into your framebuffer
2. For every pixel of the second frame, add it to pixel at the same position in the frame buffer.
3. Repeat 2. for the rest of your frames.
4. Multiply every pixel of the resulting frame by $$\frac1N$$.

Done!

(Note: depending on the data type, might be advantageous to multiply every pixel with $$\frac1N$$ before addition/move to the framebuffer pixel)

• If u draw that in a z transform you would need N-1 frame buffers? What u describe is a typical moving average filter? I asked for a recursive one frame buffer solution. :) – user674907 May 17 at 21:28
• A moving-average filter can have a recursive implementation @user674907 – Ben Jul 21 at 13:27

This is a form the recursive averaging filter: say $$v_k = \frac{1}{N}\sum_{n=k-N+1}^{k} y_n$$ is the average at $$k$$ over the $$N$$ passed frames (the notation applies to every pixel value $$y$$, independantly). Then:

$$v_{k+1} = \frac{1}{N}\sum_{n=k-N}^{k+1} y_n = \frac{1}{N}(y_{k+1}-y_{k-N+1})+v_{k}$$

so you can bufferize the pixel ($$y_{k-N+1}$$) that leaves the $$N$$-length frame only. If b is a single buffer of the past $$N$$th input, then the output o could be written as:

o += (i-b)/N


The following diagram comes from Implementing a moving average (boxcar) filter, which provides full details about the algorithm. • Thank u! I need some time to think about this and draw it. – user674907 May 17 at 21:40
• Did you have time enough to think about it? – Laurent Duval Jun 21 at 11:33