Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
876db5d0ce
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
executable file 76 lines (69 sloc) 4.14 KB
%% 1. Load tracking
%Open FreezingAnalysis folder
addpath(genpath('.'));
% Load video and tracking
g = mbvid.mbVideoReader('wt80_test_1-10-14.mp4');
load 'wt80_test_1-10-14_tracking.mat'
tracking.video = g;
%(you can ignore the following error message: "Warning: While loading an
%object of class 'VideoReader': The filename specified was not found in the
%MATLAB path." - the following steps should still work!)
%% 2. Check tracking parameters
% This is to check that the mouse was successfully tracked (ensure that the mouse is in each of the frames displayed). The montage
% displays every 500th frame between frame 1 and frame 27000.
gpatch = mbvid.patchReader(g,'track',tracking);
gpatch.patchWidth = 128;
gpatch.patchHeight = 128;
gpatch.montage('frames',1:500:27000);
%% 3. Compute and plot pixel changes between frames
% Compute pixel changes between frames. 'compareWith' parameter corresponds
% to the number of frames between the two frames that are being compared
% (i.e. it should be 30 when video is 30 frames per second).
magnitudes = blobTrackMotionVector(tracking.getArray,'compareWith',30);
trackMagnitudes = mbvid.videotrack.scalar('video',g,'data',magnitudes);
% Make interactive plot of pixels changed (y axis) x frame number (x axis).
trackMagnitudes.plot();
%The plot displays pixel changes relative to the frame 30 frames beforehand
%on the y axis and frame number on the x axis. That is, low plateaus
%correspond to little pixel change (= little movement of the mouse).
%It is possible to double click anywhere on the plot, and this will display
%the frame corresponding to the location on which you clicked
%% 4. Find and plot freezing episodes and stimulus trials
% Find all freezing episodes
r = mbvid.freezing.findRegions('videotrack',trackMagnitudes,'addDelay',30,'maxScore',5,'minimumLength',30);
% Plot freezing episodes. Freezing episodes can be inspected (double clicking on the region) and are
% displayed at the frame rate defined by 'r.depictionIntervalInFrames'
r.depictionIntervalInFrames = 10;
% Freezing episodes are classified as a maximum of 5 pixels ('maxScore')
% changing over 30 consecutive frames compared to the preceding 30 consecutive
%frames (since our frame rate is 30 frames per second, this corresponds to
%a period of 2 seconds - hence when freezing is defined as the absence of
%movement for minimum of 2 seconds, the 'minimumLength' should be equal to the frame
%rate, and the 'compareWith' value and the section above)
% to a frame 30 frames [1 second] beforehand, 30 consecutive frames
% corresponds to a period of 2 seconds.
% Plot freezing episodes, displayed as red bars. Freezing episodes can be inspected by double clicking on the red bars and are
% displayed at the frame rate defined by 'r.depictionIntervalInFrames'. In
% this way one can check whether the mouse is actually freezing during the
% detected freezing episodes.
% Plot freezing episodes alongside trials
rtrials = mbvid.videotrack.fragmentSet('video',g,'fragmentsAsPartitionInSeconds','trialmatrix_test_basic.dlm');
rtrials.depictionIntervalInFrames = 15;
mbvid.videotrack.fragmentSet.comparePlotFragments({rtrials,r},'colors',{'g','r'},'nfig',2);
% Plot freezing episodes alongside trials. Trial times are obtained from
% the 'trialmatrix_test_basic.dlm' file. Trials are displayed as the green
% bars. In this case, the first four green bars are four 30 second baseline
% periods, the next four green bars are the CS- trials, and the last four
% green bars are the CS+ trials. If changes are made to the fear
% conditioning test protocol (e.g. the inter-trial intervals, number of
% trials, then a new trialmatrix.dlm file must be generated to be able to
% calculate the freezing percentages. It is also possible to double click on the
%green bars, and this displays every 15th frame
%(rtrials.depictionIntervalInFrames = 15). This can be done to check
%whether any potential freezing episodes could have been missed (e.g. if
%the pixel change threshold was too stringent).
%% 5. Obtain freezing percentages
o = trialPercentages(r,rtrials);
bar(o.percentage);
%Gives the percentage of time spent freezing in each trial ("fraction of active frames"), also plots a
%rudimentary bar graph.