For this first example, let's try to pinpoint the moving pixels in a video by a simple subtraction of consecutive frames. By subtracting two consecutive frames of a color video, the result we will get is a three-dimensional matrix of values near zero in pixels, which remain constant, and higher values in pixels that have a big alteration in their values.
First, let's load a video that does not contain a lot of motion in its entire duration. Such a video, used in a previous chapter, showed a green ball that entered a scene from the left and exited from the right after passing through a box. The video is called
singleball.avi
. Let's load it and display its montage:>> vObj = VideoReader('singleball.avi'); >> video = read(vObj); % read in all frames from video object >> montage(video,'Size',[5 9]) % Using a 5x9 grid for 45 frames
Our next step is to subtract each frame from the previous and save the result in a new...