Click here to Download the animations in a Powerpoint presentation (15.9 Mb). This may allow the animations to run better on slower computers.
Click here to Download the Matlab source code.
Installation Instructions:
Unzip, and place the included .m files and the two .dll files into your Matlab work directory. Run the motion detector by typing, "motiondetector" into the command line.
You can also place the entire unzipped folder into your work directory (or any other place on your computer) and simply navigate to the folder so that it is your current directory in Matlab.
Requirements:
The programs were written using Matlab 7.0 from 2005-2007. The Image Processing Toolbox is required to use the programs as written (imshow, imfilter).
Windows with Windows Media Player is required for mmread.m which is used to convert movies into Matlab arrays.
Basic Tutorial (for motiondetector.m, the GUI)
Some Calculations in Matlab:
The movie clip to be analyzed is imported into Matlab as an a x b x 3 x f matrix, with a and b the length and width of the clip and f the number of frames in the movie. The third dimension stores the separate RGB layers.
Next the movie matrix is converted into an a x b x f matrix of intensities, using the rgb2gray() matlab function and spatially filtered with a difference of Gaussian filter using the imfilter() function. A separate copy of the matrix is then temporally filtered using the filter() function along the f axis, with a filter described by the vectors [0,1]/T and [1, -(T-1)/T], where T is greater than or equal to 1 to produce a low pass filter. T is the time constant for the filter and one of the key parameters of the detector.
For the motion analysis, we will be comparing points in the matrix with a point one or more pixels away, in each direction, as defined by the spacing parameter, in the temporally filtered matrix.
For clarity, let us look at a single unit of the 2DMD. Call x1 the original point before it has been temporally filtered, and x2 the same point after filtering. Call y1 the second point prior to filtering, and y2 the same point after. Then, we calculate the output for this EMD to be: x2*y1-x1*y2.
For the calculation in all directions using matrices, we call the original matrix before temporal filtering x1 and the same matrix after temporal filtering x2. Our y1 and y2 from the above example need to be broken down into x and y components, since we must compare in both directions. Instead of comparing individual points, we shift the matrices over a number of points defined by the spacing parameter in either the x or y direction, leaving rows of columns of zeros. In this way, we can accomplish the calculations in a single point-wise calculation. Thus we have y1x and y1y, which are the matrices shifted in the x and y directions, prior to temporal filtering, and y2x and y2y, the same matrices after temporal filtering. We then apply a similar formula as used in the single point example: Mx = x2.*y1x-x1.*y2x
and
My = x2.*y1y-x1.*y2y
Note that the calculations here are point-wise on a x b x f matrices, so Mx and My are also three-dimensional matrices representing the motion output in the x and y directions, respectively, over the course of the entire clip.
The next step is to calculate the direction and intensity of motion. We do this by treating Mx and My as component vectors. Thus,
Mxy = sqrt(Mx.^2+My.^2)
indicates the magnitude of motion at each point, and
Mq = atan2(My, Mx)
indicates the direction of motion at each point.
