$$\rightleftharpoonup{xx}$$
$$\longleftharp{xx}$$,
$$\longrightharp{xx}$$,
To demonstrate the potential of this analysis pipeline, behavioral videos of head-fixed female mice — specifically mothers and virgins — were acquired while the mice were presented with auditory stimuli during functional magnetic resonance imaging (fMRI) scans. The stimuli consisted of pup calls and pure tones presented passively, thus without any instructed behavioral outputs. The pup calls were recordings of ultrasonic vocalizations emitted by 6-day-old mouse pups temporarily isolated from their nest. These pup calls typically elicit the maternal act of pup retrieval, in which the mother locates, moves toward, investigates, then picks up the pup and returns it to the safety of the nest — a behavior that virgin females typically do not exhibit11. Previous work has shown that pup calls elicit robust evoked activity in the primary auditory cortex of mothers but not virgins, while pure tone responses show no group differences12. Therefore, it was hypothesized that group differences in behavioral responses to pup calls, but not pure tones, would be identified. However, there is little literature on the specific behaviors of female mice in response to pup cues in a head-fixed environment. Therefore, no specific behavioral output was expected, making this experiment the perfect test for the proposed data-driven behavioral analyses.
Over the course of eight days, all animals were gradually habituated to experimenter handling, head fixation, and the MRI environment. Habituation to head fixation and the experimental environment is crucial for assessing behavioral responses to presented stimuli. If not properly habituated to the environment, animals may only show stress responses, washing out any stimulus-driven effects that could otherwise be parsed out via videography.
While the behavioral apparatus set-up was generally the same for every data acquisition session, it is possible that the camera field-of-view (FOV) shifted slightly each time an animal was head-fixed for fMRI scans (see example FOVs in Figure 1A). This was likely due to slight changes in the positioning of the camera mount, as well as individual variations in the head-post skull attachment for each animal. Therefore, the videos from the scans needed to be aligned with each other via linear coregistration to allow for the comparison of the spatial information they contained across the scans and animals. Coregistration was tailored to the representative data. For example, on a standard scanning day, 3–4 scans were acquired per animal, resulting in 3–4 videos per animal per day. Between each scan, there was no movement of the cradle components, including the camera and head-fixation components. Thus, once the coregistration transformation for one video per animal per day was determined, it could be applied to the other 2–3 videos of that animal on the same day. While this saved time in the coregistration step of this pipeline, spatial transformations can also be calculated for each video individually, if necessary. Three features present in each video were chosen as points for labeling and calculating spatial transformation. In the representative data shown, those three points were the center of the head-post, the frontal view of the animal’s right eye, and the profile view of the animal’s right eye (visible in a mirror placed at a 45-degree angle). Examples of video coregistration are depicted in Figure 1A,B, showing the average frame calculated from all videos taken during this experiment, both before and after coregistration, to demonstrate the effect of this step.
This pipeline relies heavily on optical flow, a computer vision method used to estimate the movement of objects in a video by estimating their apparent velocities between consecutive frames13. Optical flow was chosen because it allows for the quantification of movement — a proxy of behavioral responses — without any predetermined body parts or actions of interest. Additionally, this method was amenable to the limited image quality of the representative videos, which were acquired with the only MR-compatible camera accessible at the time of the experiment. In this pipeline, the Horn-Schunck algorithm of global, dense optical flow estimation is used; however, other algorithms, such as the Lucas-Kanade algorithm, can be easily employed with slight alterations to the provided MATLAB scripts14,15,16. Figure 2A depicts an example video frame with relative optical flow velocity vectors overlaid for each pixel. Note that the larger vectors appear in areas where one would expect movement, such as the animal’s snout and paws.
While the pipeline estimated optical flow for all videos across the full FOV, the remaining analysis steps were made much more manageable in terms of computational load and data storage needs by selecting a region of interest (ROI) within the FOV. The ROI can be selected according to the experiment and predetermined behaviors of interest or through a more data-driven approach. Given that the representative data included no specific behavioral output to track a priori, a data-driven approach was pursued. The standard deviation of optical flow magnitude was calculated across all videos at each pixel, as visualized in Figure 2B. Areas of highest standard deviation included contours of the animal, such as around the eye and snout, which instill confidence that the optical flow fluctuations observed were guided by animal movement and not noise in the videos. Areas of lesser standard deviation included the contours of the cradle, which could be the result of small vibrations in the camera and cradle that occurred during scanning. The MRI environment is inevitably ridden with vibrations during data acquisition due to the switching of gradients, which may manifest in optical flow fluctuations observed in reflective components of the cradle. Fortunately, these vibrations are constant throughout data acquisition, thus independent of stimulus condition and not expected to affect the results of behavioral analysis. Particularly heightened optical flow standard deviations were observed in the pixels of the mirror, corresponding to the profile view of the animal's face, which guided the selection of the ROI for the representative data. This was also a region where behavioral responses, such as whisking and sniffing, might be expected as part of the typical behavioral repertoire of female mice seeking an isolated pup emitting pup calls17.
After choosing an ROI and extracting the average framewise magnitude of optical flow for all videos, the optical flow during epochs of interest could be compared across groups and conditions. Note that the first 20 seconds (s) of each video's optical flow vector was masked for brightness stabilization; however, this can be adjusted to fit experimental needs. For each video, the framewise optical flow vector for the chosen ROI was Z-scored, then, following prior work in facial expression classification, it was lowpass filtered at 5 hertz (Hz) to account for the camera’s 30 Hz framerate being faster than any expected behavioral fluctuations2. Finally, the Z-scored and filtered vectors were chunked into stimulus presentation epochs to assess the effect of stimulus presentation on optical flow. For each epoch, the mean pre-stimulus baseline signal was subtracted to normalize optical flow to the pre-stimulus period. Figure 3A shows exemplary optical flow time series for two videos, one mother and one virgin, with summary group data in Figure 3B-E. Figure 3B and Figure 3D show the cumulative optical flow over time during stimulus presentation relative to baseline, while Figure 3C and Figure 3E summarize the cumulative optical flow 2.5 s after stimulus onset. Cumulative optical flow was calculated to capture overall movement over time without assuming that spontaneous behavioral responses would occur in a time-locked manner. Overall, these representative results demonstrate that pup calls, but not pure tones, evoked significantly different behavioral responses from maternal versus virgin female mice, as predicted (between-group Mann-Whitney U test: pup calls: p = 0.026; pure tones: p = 0.093). However, this stimulus effect did not survive a 2-way ANOVA, while the group effect did (stimulus: F(1,10) = 0.19, p = 0.67; group: F(1,10) = 8.61, p = 0.015). Overall, these results suggest that mothers showed higher stimulus-evoked movement compared to virgins, with the maternal response to pup calls being more consistent than to pure tones. This may reflect heightened attentiveness or stress in mothers, as well as the behavioral relevance of pup calls, which, unlike pure tones, evoke the response of pup retrieval in mothers in naturalistic settings. Taken together, these representative results suggest that optical flow estimation during external stimulus presentation can extract information regarding nuanced, spontaneous behavioral responses.
Finally, a more exploratory analysis was conducted to uncover the spatial characteristics of the behavior captured in the representative data. To investigate which pixels in the ROI fluctuated in a coordinated way during stimulus presentation, principal component analysis (PCA) was conducted on the spatial optical flow information over time. This analysis revealed pixels that contributed most to the first PC, as well as pixels that showed group differences for each stimulus condition, as depicted in Figure 4. The rightmost panels of Figure 4A,B suggest that mothers showed more movement in the nose compared to virgins during the presentation of both stimulus types. Across the two groups and two stimulus conditions, the first PC explained 5.41% ± 0.59% of the total variance in the optical flow analysis. While the mirror ROI was maintained for this part of our analysis, future analyses could expand to a broader portion of the FOV to characterize coordinated movements beyond the face in response to stimuli. For example, comparing paw movement may reveal more significant group differences, given that pup calls typically initiate pup retrieval in mothers but not virgins, and that the paws could move more freely than the head of the animal.
While the representative results thus far suggested that this pipeline can assess uninstructed behavioral responses to external stimuli in constrained videography environments, a question remained as to whether the observed fluctuations in optical flow truly reflected meaningful animal behavior. To answer this question, a separate validation dataset was analyzed using the same pipeline. In a separate experiment, water-restricted male mice were trained to associate a light cue with the delivery of either a 6 μL ("high reward") or 1 μL ("low reward") water reward. Notably, unlike the auditory stimulation experiment, this experiment had an a priori behavioral readout: lick rate. A lickometer was established via video-based detection of licks, facilitated by the analysis of pixel brightness close to the water spout. The behavioral readout supplied by the lickometer could thus be used to compare this pipeline’s behavioral readout supplied by optical flow estimation, supporting its validity in detecting spontaneous behaviors. Following video coregistration, optical flow estimation, ROI selection (once again containing the mirror FOV), and optical flow quantification, comparing optical flow magnitude revealed a significant difference between the behavioral responses to high versus low rewards. The results of this analysis are shown in Figure 5A,B, where Figure 5A shows the group averaged time series, and Figure 5B summarizes the cumulative optical flow 2.5 s after stimulus onset (between-condition paired Wilcoxon signed-rank test: p = 0.031). Note that optical flow values were larger compared to the spontaneous behavior recorded in the representative data, further emphasizing the challenge of evaluating uninstructed, nuanced behavioral responses. Figure 5C depicts the actual lick rate recorded by the lickometer for each of the two reward conditions, while Figure 5D shows that more licks are recorded during the high reward condition compared to the low reward condition within 2.5 s following reward delivery (between-condition paired Wilcoxon signed-rank test: p = 0.031). Altogether, both analyses revealed a similar trend in the comparison of high versus low reward responses, validating the presented video analysis pipeline for capturing meaningful differences in animal behavior across conditions.
Taken together, the representative results shown here suggest that the presentation of pup calls evoked significantly different responses in maternal versus virgin female mice, while pure tones did not. The analysis of a validation dataset confers confidence that the observed differences in optical flow reflect meaningful differences in behavioral responses to external stimuli.

Figure 1: Video coregistration. (A) Examples of video coregistration depicting predetermined features (center of the head-post, frontal view of the right eye, profile view of the right eye) labeled in three frames, each taken from different videos of different animals. Note in the overlay how the three points were not aligned, demonstrating how the behavioral set-up changed slightly between data acquisition sessions. (B) The average frame across the last 10 s of each video before (left) and after (right) performing video coregistration. Please click here to view a larger version of this figure.

Figure 2: Optical flow estimation. (A) Example frame with relative optical flow vectors overlaid in blue. (B) The average pixel-wise standard deviation of optical flow across all videos. The chosen ROI around the profile view of the animal's face via the mirror is outlined in magenta. The color bar corresponds to the standard deviation. Please click here to view a larger version of this figure.

Figure 3: Visualization and comparison of optical flow across groups and conditions. (A) Exemplary Z-scored and 5 Hz lowpass filtered time series of optical flow for one video of a mother and one video of a virgin. (B) and (D) Cumulative optical flow measured during the stimulus period of pup calls (B) and pure tones (D). Shading represents the standard error of the mean (SEM). (C) and (E) Cumulative optical flow during the first 2.5 s of stimulus presentation for pup calls (C) and pure tones (E). * Indicates p < 0.05, between-group Mann-Whitney U test (pup calls: p = 0.026; pure tones: p = 0.093), N = 6 per group. Please click here to view a larger version of this figure.

Figure 4: PC1 comparison across groups. (A,B) Maps depicting the loadings of the first principal component (PC1) of optical flow during pup calls (A) and pure tones (B) across groups, statistically thresholded at p < 0.05 without correction for multiple comparisons. Heat map indicates the degree to which the optical flow fluctuation of each pixel contributed to PC1, relative to other pixels. Small black text indicates the percent of variance explained by PC1 (mothers pup calls: 4.95% ± 0.72%; virgins pup calls: 4.44% ± 0.59%; mothers pure tones: 4.95% ± 0.39%; virgins pure tones: 4.72% ± 1.24% (mean ± standard deviation)). Please click here to view a larger version of this figure.

Figure 5: Validation of the behavioral analysis pipeline. (A) Average Z-scored, pre-stimulus baseline subtracted, and 5 Hz lowpass filtered time series of optical flow during high and low reward delivery. Shading represents the SEM, the white vertical line indicates reward delivery, and the red asterisks indicate temporary optical flow artifacts due to the onset and offset of the light cue. (B) Summary of cumulative optical flow during the first 2.5 s after reward delivery. * Indicates p < 0.05, between-condition paired Wilcoxon signed-rank test (p = 0.031). (C) Average lick rate, obtained by lickometer, during high and low reward delivery. Shading represents SEM, and the white vertical line indicates reward delivery. (D) Number of licks recorded during the first 2.5 s after reward delivery. * Indicates p < 0.05, between-condition paired Wilcoxon signed-rank test (p = 0.031), N = 6. Please click here to view a larger version of this figure.
Video 1: Example video 1. PCR_Br011_20231015_1842_output.avi. Please click here to download this Video.
Video 2: Example video 2. PCR_Br014_20231015_1722_output.avi. Please click here to download this Video.
Supplementary File 1: Event timing file for Video 1. PCR_Br011_20231015_1842_output_videoTimestamps.mat. Please click here to download this File.
Supplementary File 2: Event timing file for Video 2. PCR_Br014_20231015_1722_output_videoTimestamps.mat. Please click here to download this File.
Supplementary Coding File 1: script1_videocoreg.m. This script spatially aligns all videos to each other via coregistration. Please click here to download this File.
Supplementary Coding File 2: script2_optflow_roiselect.m. This script estimates optical flow for the full FOV of each transformed video and allows for the selection of an ROI for the rest of the pipeline. Please click here to download this File.
Supplementary Coding File 3: script3_optflow_analysis.m. This script compares optical flow magnitude across different groups/conditions for the chosen ROI. Please click here to download this File.
Supplementary Coding File 4: script4_optflow_pca.m. This script performs PCA on the estimated optical flow of the chosen ROI. Please click here to download this File.
Supplementary Coding File 5: script5_optflow_pca_analysis.m. This script compares PCA results across groups/conditions for the chosen ROI. Please click here to download this File.