File Exchange

image thumbnail

Background frame extraction

version (1.79 KB) by Alexander Farley
Calculate background frame from video by averaging a subset of frames across entire video.


Updated 01 Apr 2013

View License

The video is downsampled and averaged from beginning to end. This yields a background image which can be subtracted from each frame of the video to yield a movement frame.

Cite As

Alexander Farley (2019). Background frame extraction (, MATLAB Central File Exchange. Retrieved .

Comments and Ratings (11)

Ho to use this script in order to remove background and extract the foreground only from the video. Thanks.

Huan Tran

Marjan: I'm not sure why you're seeing NaN. Can you send me the video you're using?

Also, forget about the background_fram2 stuff, it's not very useful. background_frame is the one you want.

first, great work.
second, what the method did you use in this implementation?
third, how to play the video? what function did you use? (movie(...) or release(video))

marjan ss


Can you please explain what are those NAN values in the background_frame2 matrix? I need to know which pixels are fixed among all video frames. thanks

marjan ss

I need to extract the background for each frame in the video. Can you please explain a bit about the background_frame2 matrix? I think that's background of the whole video. Therefore, by subtracting it from each frame I can get the motion parts. what about background of each frame?How can I get the background pixels index? Thank you.

marjan ss

What are those NAN in the background_frame2 matrix?

thank you


MATLAB Release Compatibility
Created with R2011a
Compatible with any release
Platform Compatibility
Windows macOS Linux