Tutorial

 

This simple tutorial should bring you through the basics of using the motion detector program.

Load Movies

The first step to analyzing motion is to select a short sequence of motion (30-60 frames) that you wish to analyze.  The limit to the size of the clip you will be able to analyze is determined by your computer hardware and setup.  Increasing your random access memory (RAM) and virtual memory will allow you to load and analyze larger and longer movies.  Experiment to see what sized movies your computer can handle.  Although this program can crop movies and select specific frames, you should use a video editing program (such as Adobe Premiere) to bring your movies to manageable size.

Once you have identified the movie that you wish to analyze, run the motion detection program (by typing “motiondetector” into the Matlab command line) which will bring up a new window with buttons and a menu.  Select “Load” then “Load Movie” from the menu and locate the movie you wish to analyze on your hard drive.  Follow the onscreen instructions to select which frames of your selected movie will be loaded for analysis.  Note that during preview, the frame number is indicated at the top menu bar.

Resize and Crop Movies

Once you have your movie loaded, you have the option to crop out a selected portion of the movie, or resize the entire movie.  This will be useful when you wish to analyze smaller portions of a large clip that your computer cannot analyze all at once.  From the Image menu, select “Crop Movie” or “Resize Movie” and follow the instructions.  You can watch your newly edited movie by clicking the button labeled “Play Movie” located at the bottom left of the window.  If you are not happy with the result, even after affirming your choice, you may select “Undo Last Change” from the image menu.  Unfortunately, because storing multiple versions of your movies takes up valuable space on your computer, you will only be able to undo one change at a time.  However, you can always reload the original movie and begin again.

Set Parameters

Now that your clip is loaded and you are satisfied with the size and selection that you made in the last step, you should now set the parameters that you wish to use during motion detection.  Through the various edit boxes and slider bars, you will be able to edit “T”, the time constant for the temporal filtering, “Spacing”, the distance between each pair of detectors, “Size of Filter”, the size in pixels of the spatial filter and the two values indicating the standard deviations of the spatial filters.  The default values for these fields is 0.5 and 0.8 times the spacing parameter and is automatically updated when you change the value of “spacing.”

Detect Motion

With the parameters set, you are ready to begin analyzing the motion.  At the bottom of the window, just above the button labled “Play Movie” you will find one labled “Detect Motion.”  Clicking this will begin the motion detection algorithm.  While it is being analyzed, a box in the middle of the window will be displayed that says, “Processing…”  It may take anywhere from less than a second to a minute or more, depending on your computer speed and the size of the movie you are attempting to analyze.  If you receive and error saying that your movie is too large, try using the options available to resize or crop your movie.

Display 3d and Polar Plots

Once the algorithm has finished, you will want to view your results.  From the “Plot” menu, select “Plot 3d” to view a surface graph, with height indicating strength of the output.  You can use the default Matlab features to rotate or zoom in or out.  Press Ctrl or Shift to advance through the frames of your movie.  If you wish to end the display before viewing all of the frames, simply click on the original motion detector window.

Selecting one of the options from the “Polar” menu will give you more ways to view your data.  “Plot All” from the “Polar” menu displays all frames of the movie at the same time on the same axes.  “Frame by Frame” will instead show polar plots for each frame in sequence, similar to the 3d plot, and the “Fit Ellipse” function will attempt to place a best fit ellipse around the data.

Calculate Direction

None of the previous methods of displaying the data provided any information about the direction of the motion, but that information is available to you.  Once the detect motion algorithm has finished, you will find a third button at the bottom left portion of the window labeled “Detect Color.”  This function will assign each pixel a color based on the angle of motion detected.  The color wheel that is the default background for the motion detector window indicates which colors correspond to which directions.  For example, something traveling directly up and then directly down will appear yellow while traveling up, and then magenta while traveling down.  The processing indicator will appear again while this is being calculated.  Once it is finished, select the new, “Play Color” button that appears.  In this plot, the color indicates direction, and the intensity indicates the strength of output.  Areas where little or no motion is detect will appear black.

Note that this function requires more available RAM than the other methods of displaying data, so you may not be able to use it if you are analyzing clips that are nearly at the limits of your computer’s abilities.

With these few instructions, you should be able to load and analyze motion of all types.  If unexpected errors being showing up, try restarting your Matlab program to ensure that there are no hidden variables taking up valuable memory space.

Save and Load Results

At some point, you will likely wish to save some of your results to make the results available on their own.  The “Save” menu allows several ways to accomplish this.  The first and simplest  is the “Save Motion” command, which simply saves the color plot as an uncompressed AVI movie.  This will only be available if you have used the “Detect Color” button previously.  There is also the option to “Save Movie,” which will save the edited version of the movie clip you are working with.  This is useful if you used the crop or resize features so you can save your work for another time.

The “Save 3d plot as AVI movie” and “Save polar plot as AVI movie” options both work as indicated, but will display the frames on the screen prior to saving.  Do not interfere with these windows or begin working in another window as it is saving as this will interfere with the saving process.  “Save frame maxima in Excel spreadsheet” also works as indicated, but Windows and Excel are required.  This function gives you just one way of comparing data from different clips.  With the next saving option, you will be able to create your own methods.

The “Save as Matlab structure” command is not as simple to use as the other options, but it will give you access to the data and allow you to create your own functions to analyze it.  Once the data is saved, it will appear as a MAT file.  To facilitate loading this file into Matlab, we have included the file “loaddata.m,” which will provide a graphical interface to locate the file and load it, or alert you that the selected file is not in the right format (only MAT files created by the motiondetector program will work with loaddata.m).
To access your saved data with loaddata.m, return to the Matlab command window and enter the command, “mydata= loaddata” to load the data into the variable mydata.  You can use any name you choose in place of “mydata.”  The data can then be accessed using the matlab dot notation for variables.  “mydata.mov” is the original movie, “mydata.mx” and “mydata.my” are the individual x and y components, “mydata.radi” is the calculated magnitude from the components, and “mydata.thet” is the calculated direction in radians.  “mydata.movm” is the RGB movie with color indicating direction, and intensity indicating direction (mydata.thet and mydata.radi, respectively).  If you did not calculate this in the motiondetector program prior to saving, this will be a placeholder matrix of zeroes instead.

The included “playmovie.m” function will allow you to view the results as in the motion detector function.  Use “playmovie(mydata.mov)” to play the original movie.  The “play3d.m” function is similar, but displays results as a 3d surface plot.

If you are interested in loading clips into the Matlab workspace without using the graphical user interface, try “loadclip.m” and “loadclipcolor.m” to locate and convert movie files into Matlab matrices.  See “detectmotion2.m” for the proper parameters to obtain motion detector results.

Skip to toolbar