Journal of Neurophysiology

Tracking Whisker and Head Movements in Unrestrained Behaving Rodents

Per Magne Knutsen, Dori Derdikman, Ehud Ahissar


Due to recent advances that enable real-time electrophysiological recordings in brains of awake behaving rodents, effective methods for analyzing the large amount of behavioral data thus generated, at millisecond resolution, are required. We describe a semiautomated, efficient method for accurate tracking of head and mystacial vibrissae (whisker) movements in freely moving rodents using high-speed video. By tracking the entire length of individual whiskers, we show how both location and shape of whiskers are relevant when describing the kinematics of whisker movements and whisker interactions with objects during a whisker-dependent task and exploratory behavior.


The rodent vibrissae system is an extensively studied experimental model of sensorimotor processing. Despite the stereotypical patterns of behavior exhibited by whisking rodents, the majority of electrophysiological studies in this system have been performed on anesthetized animals. As such, much is known about responses to passively applied stimuli, but comparably little of neural responses during awake, behaving states. Several recent technological advances have enabled recordings of neural activity from awake and freely moving rodents, with minimal discomfort and obstruction of the natural behavior of the animal ( Fee and Leonardo 2001; Fee et al. 1997; Jog et al. 2002; Kralik et al. 2001; O'Connor et al. 2002; Prigg et al. 2002). However, during unobstructed free ranging, events that produce sensory responses, such as self-generated whisking and object touch ( Fanselow et al. 2001; Krupa et al. 2004; Prigg et al. 2002; Szwed et al. 2003), need to be accurately monitored.

Existing methods for monitoring movements of whiskers in unrestrained rodents employ techniques that involve considerable manual data collection, occasionally with the aid of customized software ( Berg and Kleinfeld 2003a; Brecht et al. 2004; Carvell and Simons 1990, 1995; Hartmann et al. 2003; Sachdev et al. 2003; Sachdev et al. 2002; Welker 1964; Wineski 1983). Automation has been limited to conditions in which whiskers were tagged with glass-beads or other reflective materials. However, since the mass of whiskers is small, any material chosen to tag them is likely to influence their dynamical properties, such as resonant frequencies or center-of-mass position ( Hartmann et al. 2003; Neimark et al. 2003). With a less intrusive method ( Bermejo et al. 1998), an array of light sensitive elements is illuminated by a collimated light source, and the shadow of a whisker is detected as a drop in voltage at a location along the array. However, this method is limited to head-restrained animals and requires additional tagging when tracking individual whiskers in an intact whisker field. Recordings of EMGs of whisker pad muscles have been used in unrestrained rats ( Berg and Kleinfeld 2003a, b; Carvell et al. 1991). EMG is a good predictor of whisking timing, but cannot provide information about the exact trajectory of the whisker in space or its elastic behavior. Thus methods available for accurate measurements of whisker movements are either too labor intensive or too restrictive to be of general use in freely moving paradigms. Furthermore, none of these methods allow efficient tracking of the entire whisker length and may thus potentially miss important kinematic parameters.

For accurate measurement of whisker movements, we chose high-speed video, since it allows a large area to be covered simultaneously at high spatial (>5 pixels/mm) and temporal (>500 frames/s) resolution. High spatial resolution allows accurate determination of whisker shape and location. High temporal resolution allows visible changes in whisker shape and location to be correlated with neuronal events. Furthermore, correlation between successive images will be high since head and whiskers will not move much from frame to frame. Here, we take advantage of this fact to track the movements of the whiskers. Although high-speed video is easy to use, it generates enormous amounts of data (typically hundreds of megabytes for a few seconds of raw, uncompressed bitmaps) and therefore requires efficient tools for analysis.

We present an improved videographic technique for measuring whisker movements, efficient and general enough to be used in most freely moving paradigms involving rodents (rats, mice, hamsters) that require accurate determination of whisker movements. Using high-speed video, we acquired movies of rodents whisking at high spatial and temporal resolution. With relatively simple and fast image processing techniques, we completely automated tracking of head movements and partially automated tracking of individual whiskers without applying markers of any sort to the head or whiskers. Since we tracked the entire length of whiskers, we were able to approximate the true angle of a whisker at its base, its curvature, and the distance of any point along the whisker shaft from fixed environmental features at 1- to 2-ms resolution. This method and some results have been presented in abstract form ( Knutsen et al. 2004).


Behavioral task

Our method for tracking whisker and head movements was applied to video movies of freely moving rats, mice restrained by the means of a nylon bag, and videos of artificially whisking anesthetized rats. Three adult male albino rats were trained in a freely moving object localization task (see Fig. 1 for experimental setup). Briefly, water-deprived rats were trained to poke their head through a hole in the wall of an enclosure and to approach a nosepoke about 8 cm from the wall. Two vertical objects were positioned 2–3 cm from either side of the face at randomly selected anterior-posterior locations. Rats were rewarded with fruit juice for correctly judging the relative locations of the objects. Although task specifics and performance are not reported on here, whisking was present in both naïve and successfully trained rats. One rat, in addition to the three above, was trained (with nosepoke and objects removed) to poke its head through the hole in the wall and wait for a water reward presented through a sipper approaching from the left or right side. This task typically evoked more exploratory whisking type behavior (data generated for Fig. 5) than did the localization task (data generated for Figs. 610). One mouse was restrained in a nylon bag, allowing it to move its head only. The mouse was placed inside a small plastic tube for added support and placed beneath the camera at an ∼30° upright angle. Whisker movements occurred spontaneously or were elicited by occasional tactile stimulation of the face or whiskers. In addition, whisker movements were acquired of a urethane anesthetized rat induced to move its whiskers by electrical stimulation of the facial motor nerve (see Szwed et al. 2003). Animal maintenance and experimental procedures were conducted in accordance with National Institutes of Health and Institute guidelines.

FIG. 1.

Experimental setup for object localization by freely moving rats. A rat (R) was placed in a 25 × 40-cm enclosure in which it was trained to poke its head through a hole in one of the walls, place its snout against a touch sensor (NP), and discriminate the relative location of 2 vertical poles (P) to receive a reward. The task was performed with infrared illumination only (L and B). A fast video camera was placed 50 cm above the rat and covered ∼40 cm2 of the discrimination site (not shown). Strong backlighting (B) enhanced whisker visibility. Two overhead LED spotlights (L) illuminated the head and eyes.

Imaging system

The imaging system consisted of an integrated high-speed video system (MotionScope PCI, Redlake, San Diego, CA) and personal computer (Pentium 4, 2 GHz). Whisker movements of behaving rats and mice were captured at 500 frames/s at 320 × 280 pixels, and those of anesthetized rats ( Szwed et al. 2003) at 1,000 frames/s at 320 × 156 pixels. The camera was equipped with a high-speed lens (DO-1795, Navitar, Rochester, NY). The MotionScope system is by standard fitted with an IR blocking filter. This filter was removed, yielding a sensitivity of ∼3 V/μJ/cm2 at the peak illumination wavelength (940 nm) of the LEDs. Exposure time at 500 fps was limited one-half or one-third duty-cycle, corresponding to 1 or 0.665 ms exposure per frame, respectively. The lens had a focal length of 17 mm, with a focal ratio between f/3 and f/5. The camera was placed at 0.5-m viewing distance and had a depth of field suitable for tracking whiskers of ∼10 cm.

Whisker visibility was enhanced by illuminating from below and placing the camera above the head of the animal (see Fig. 1). With anesthetized rats, we used a fiber optic light source emitting visible light (FL6000, Micro-Lite, Three Rivers, MA) and a fiber-optic backlight (PANELite, Schott Fostec, Auburn, NY) covered with one layer of diffusing glass (F02149, Edmund Industrial Optics, Barrington, NJ). For the behavioral task experiments, we used a custom-made 10 × 10 array of infrared (940 nm) light-emitting diodes (L940-04AU, Epitex, Kyoto, Japan), each outputting ∼20 mW/sr, covered with two layers of diffusing glass.

Synchronization with neurophysiological data was achieved in several ways. Run-time commands to the camera were logged with timestamps on the controlling PC. Second, two black-and-white squares in the top left corner of the video frame were toggled during recording to mark specific events, such as the interruption of an infrared beam, which indicated entry of the rat into the frame, and a signal from a touch sensor, indicating contact with the nosepoke. Third, the signal controlling the camera shutter itself was digitized in real-time.

Implementation of tracking algorithms

Tracking of head and whisker movements was implemented by code written in MATLAB (v6.5, MathWorks, Natick, MA) and the C programming language. The algorithms are described below and supplied as supplementary material.

Tracking of head movements

Head movements were tracked by following the eye reflections made by two overhead infrared (880 nm) LED spotlights (F54845, Edmund Industrial Optics) 10–15 cm above the rats (Figs. 1 and 3). The reflections in both eyes were manually located in the first frame of every movie. In the next and subsequent frames, a small region (usually 2 × 2 mm) centered on the location of the eye in the previous frame was smoothed with a low-pass filter constructed from the difference of two Gaussians. Since movement of each eye from frame to frame was small, the location of the peak luminance indicated the new position of the eye. This procedure was repeated for all frames of the same trial until either eye disappeared out of the camera's view. If the eye reflection disappeared out of sight momentarily for a few frames (e.g., during an eye-blink or when the head was tilting), this procedure generally managed to relocate the eye. When this was not the case, manual intervention was required. Location of the nose was estimated as the vertex of an isosceles triangle with the base between the eyes. The base-nose angle was kept straight, and its distance constant, for all frames in each movie.

Tracking of whisker movements

Movements of individual whiskers were tracked frame-by-frame as follows: 1) stationary features were removed, 2) a region of interest parallel to the face was extracted and rotated, 3) the image was filtered according to the anticipated whisker position, 4) the region of interest was filtered according to the local angle of the whisker in the previous frame, and 5) piecewise polynomials (splines) were fitted to whisker-like features in the transformed image. Briefly, a whisker was located manually in the first frame of every trial by selecting three or more points along the shaft and interpolating the shape of the whisker with a piecewise polynomial function. The algorithm determined the shape of the whisker in subsequent frames by moving these points to new locations (within a predetermined range) and interpolating a new spline for all their possible permutations. The interpolated spline overlaying the largest cumulative sum of pixel values was selected as the new location and shape of the whisker. The various steps involved in the algorithm are shown in Fig. 2. Pseudo-code outlining the algorithm is available as supplementary material1 .

FIG. 2.

Stages of the algorithm used for tracking the entire length of the whisker. A: head movements were first tracked and a rectangular segment aligned on the eye and nose was extracted from the original video frame and rotated. R, rat; P, pole/object; NP, nosepoke. Arrow indicates whisker of interest. B: frame after subtracting an average of frames where the rat was not present. C: filter generated using as parameters the velocity and shape, in the preceding frame, of the whisker. D: image after convolution with the filter generated in C, emphasizing the whisker of interest and attenuating the visibility of other whiskers. E: local angle of the whisker in the previous frame was used to create an array of aligned filters (bottom). Image was convolved with these filters on a local scale, thus emphasizing features of similar orientation as the whisker in the preceding frame. F: a nonstochastic algorithm was used to localize the whisker of interest in the current frame (solid line) within a region of interest (dotted lines).

Stationary objects were filtered from individual frames by subtracting an average of many frames where the rat was absent. In movies of anesthetized rats, where whiskers but not the head moved, all frames were averaged together and subtracted from each individual frame (Fig. 2, A and B).

A rectangular region adjacent and parallel to a line intersecting the ipsilateral eye and nose was extracted and rotated. The cutout was rotated such that the axis parallel to the whisker pad was vertical. Thus anterior/posterior whisker movements are represented by up and down movements in the cutout. A rotated segment without and with the background removed from the image is depicted in Fig. 2, A and B, respectively.

New locations of each point along the whisker shaft were linearly extrapolated from the trajectory of locations in preceding frames. A Gaussian-profile filter (Fig. 2C), aligned along the expected location of the whisker, reduced the visibility of other nearby whiskers, while enhancing the whisker of interest (Fig. 2D). The width of the Gaussian was always broad (approximately one-half of the anterior-posterior width of the entire whisker field), such as to just introduce a slight bias in the estimation of whisker location.

Discriminability of the whisker was enhanced by convolving the image in the radial direction with a set of oriented edge-filters co-aligned to the local angle of the whisker in the preceding frame. The local angle of the whisker was computed for each 1-mm segment of the whisker shaft. The cross-section of the filter was a vector of ones in the center, flanked by zeros on both sides (Fig. 2E). The width of the on center should be approximately the same as the typical width of whiskers in the image. In general, it is sufficient to configure the imaging system such that the thinnest whisker of interest can be subjectively separated from the background. In our experience, a whisker width of one or two pixels is sufficient for reliable tracking with a static background. The edge filter was 1–2 mm long and convolved with the image in 1 × 1-mm blocks along the dimension of the whisker shaft. This operation attenuated other whiskers in the image with local orientations differing from that of the whisker of interest.

After applying the filters above, whiskers appear bright against a dark background. Thus the cumulative sum of pixel values of a spline that best overlaps the whisker shaft would be higher than those of partially overlapping splines. Coordinates that defined the interpolated spline in the preceding frame were repositioned within a predetermined range, and a set of new splines was interpolated from all possible permutations of new coordinates. The spline with the largest cumulative sum of pixel values was selected as the new location of the whisker. Points were repositioned only to whole pixels and within a range that corresponded to the maximal anticipated frame-to-frame whisk displacement. Assuming whisker lengths upward to 7 cm ( Brecht et al. 1997) and a maximal whisker displacement upwards to 3,000 deg/s (Fig. 6), the maximal anticipated velocity of the distal tip of the whisker is ∼3.5 mm/ms. Typically, however, whiskers are shorter and movements are slower, thus bringing down the anticipated range of whisker displacement and velocity. Since the algorithm needs to evaluate fewer possible whisker locations when the range is reduced, working with the smallest possible range effectively makes the algorithm run faster. The algorithm works with a separate range for each of the spline points, since the speed of the tip is higher than that of the base of the whisker. We solved this in part by adding to the individual range of each spline point the sum of ranges of all proximal points. For example, if the first, second, and third spline points were assigned ranges of one, two, and three pixels, respectively, the net range (and thus its maximal displacement) of the third point was 1 + 2 + 3 = 6 pixels (see Fig. 2F). These ranges are typically hand-tuned once per movie, although parameters are generally transferable to similar cases such as movies of the same rat across different trials, assuming the position of the camera has not changed significantly. The spline-fitting step can accept splines with more than three interpolation points, although this reduces the speed of the algorithm (see pseudo-code in supplementary material).

Data analysis

Whisker angle was computed at base (the most proximal point of the tracked whisker) from the coefficients of the most proximal polynomial of the spline representation of the whisker Math(1) for the polynomial Ax3 + Bx2 + Cx + D. Angle is expressed such that 0° of angle parallels the line that intersects the ipsilateral eye and nose while pointing posterior, and 90° is perpendicular to this line. Our definition of whisker angle is similar to that of others ( Carvell and Simons 1990; Hartmann et al. 2003) but differs from that of Bermejo et al. (1998) who computed whisker angle between a fixed reference point and a location about 1 cm out on the whisker shaft. We maintain that this difference is crucial, since the pivot point of the whisker moves during whisking ( Berg and Kleinfeld 2003a), and thus assuming a fixed reference would distort the angle between the whisker and the face. Furthermore, whiskers often continue to protract when obstacles are encountered. If whisker angle is calculated on the flexible portion of the whisker, the angle may appear to decrease (due to bending), whereas the angle of the whisker at base is actually increasing.

A full-length spline representation of whiskers allows direct measurement of the bending of the whisker both during whisking and on object touch. We computed bending (curvature) as the inverse of the maximal radius of the whisker. Whisker curvature can also be estimated at its base from the coefficients of the first polynomial of the whisker spline Math(2) for the polynomial Ax3 + Bx2 + Cx + D.


Head and whisker tracking

We applied our method to tracking of whisker movements in unrestrained rats, restrained mice, and artificially whisking anesthetized rats (Fig. 3). In unrestrained animals, head movements were also tracked so that the effect of head rotation and translation on whisker movements could be isolated. This allowed us to express whisker location both in a head-centered and world-centered frame of reference. We tracked head movements by following the reflections of two overhead spotlights in the eyes of the animal. Such tracking was completely automated and allowed accurate localization of both eyes. Tracked head movement and orientation in one trial is depicted in Fig. 4. In anesthetized rats, where whisking can be induced by stimulation of the facial motor nerve ( Szwed et al. 2003), tracking of whisker movements does not require tracking of the head as the head is immobilized.

FIG. 3.

Examples of whisker tracking. Tracked whiskers are indicated by arrows. A: anesthetized rat induced to whisk by electrical stimulation of the facial motor nerve. B: unrestrained rat with dark background and top-down illumination. Whiskers B2, C2, and D2 were left intact, and the remaining whiskers were cut prior to imaging. Contrast of the image was reversed before applying the whisker tracking algorithm. C: mouse restrained in a nylon bag but free to move its head in all directions. Whiskers C1, C2, C3, C4, and C5 were left intact on both sides of the face, and the remaining whiskers were cut prior to tracking. D: unrestrained rat. Movie was imaged at 500 fps and downsampled to 125 fps by dropping 3 of 4 consecutive frames. Only a single whisker (C2) was left intact on each side of the face.

FIG. 4.

Automated tracking of ocular reflections. A: head position across frames in a 2-s video movie. Location of the head in each frame is represented by an isosceles triangle where the base (defined by 2 black dots indicated in the last frame) represents tracked position of the eyes and the vertex represents estimated location of the nose. The 2 vertical lines represent horizontal-anterior/posterior location of 2 objects. In this example, the rat enters the frame, goes straight ahead, turns right, goes back to the center, touches the nosepoke, and backs out. B: 3 selected frames from the video in A.

A tracked whisker within an intact field of whiskers and its instantaneous velocity, angle, and curvature are depicted in Fig. 5. The tracking algorithm automatically detected head position and extracted a rectangular area parallel to the eye-nose axis within which the movement of the whisker was followed. Five frames selected from one whisking cycle are shown (Fig. 5A) along with the output of the whisker-tracking algorithm (Fig. 5, A and B). Angular velocities were higher during retraction compared with protraction, in agreement with Bermejo et al. (1998). Furthermore, a clear correlation was seen between whisk phase and curvature of the whisker. Curvature was most positive (convex anterior) at whisk onset and most negative (concave anterior) during retraction (Fig. 5, B and D). This observation is clearly seen within single whisks (Fig. 5, B and C), as well as in the average trace of curvature in all whisks (Fig. 5D). A movie demonstration of simultaneous tracking of head movements and four whiskers is provided as supplementary material.

FIG. 5.

Tracking the full length of an individual whisker in an intact whisker field. A: frames of a full whisking cycle, from the onset of protraction (0), through protraction (P), peak angle (π), retraction (R), and until end of cycle (2π). B: relative location and shape of the tracked whisker in frames in A. The whisker is labeled light gray at protraction onset (0), black at the end of retraction (2π), and intermediate gray-tones for remaining phases (P, R, π) of the whisking cycle shown in the video frames. Whisker shape at protraction onset and peak protraction was rotated such that both ends were aligned horizontally and are shown at the bottom. Note the difference in curvature at protraction onset and peak. Negative curvature signifies concave and positive values for curvature a convex shape of the whisker. C: traces of (top to bottom) angular velocity, angle, and curvature (1/maximal radius) during a whisking bout at about 8.5 Hz with varying amplitudes spanning 20–40°. All traces were tracked at 500 fps. All traces were low-passed filtered at 60 Hz. D: onset and ends of individual whisks were identified, and traces of angle, velocity, and curvature were normalized to unit length and averaged. Scale bars apply to C and D and denote (top to bottom) 1,000 deg/s (angular velocity), 50° (angle), and 0.005 mm−1 (curvature).

Performance of tracking algorithm

The performance of tracking was dependent on illumination conditions and spatial resolution. Optimal visibility of the large whiskers (macrovibrissae) during rapid movement was achieved using strong and evenly distributed backlight illumination to enhance whisker-background contrast and an appropriate choice of a bright, high-speed lens. Tracking of individual whiskers within an intact whisker array was semiautomatic, requiring occasional intervention by an operator. The frequency of interventions depended mainly on video quality and the discriminability of individual whiskers. Manual intervention was only required if whiskers completely overlapped when video quality was optimal. Automated tracking was resumed after adjustments to compensate for errors were made manually. Most errors, however, were small, restricted to a few frames and were corrected only after tracking of the entire movie was complete.

In addition to testing our algorithm on whiskers within an intact whisker field, we also tracked whisker movements after clipping all but a single whisker (C2) an arc of whiskers (arc 2) or a row of whiskers (row C). Under such simplified conditions, tracking was almost completely automatic. Of the few manual interventions required, the most typical was to change the maximal range the spline was allowed to traverse from frame to frame (see methods). During large-amplitude, high-velocity whisking, this range typically had to be increased since the range was deliberately kept as low as possible for the algorithm to run as fast as possible.

We found that the method described here significantly increases the efficiency of tracking planar movements of head and whiskers. The method is optimal when high temporal resolution is called for, as in electrophysiological experiments and detailed studies of whisker kinematics, where a large number of frames need to be tracked. The efficiency of the method compared with manual data collection is easily shown numerically. Tracking a single whisker for 1 s at 1,000 fps involves collecting a total of 3,000 data points (with 3 spline points). Assuming each data point takes 1 s to acquire manually, 50 min are needed to track 1 s of movement of a single whisker. In comparison, Table 1 shows the typical durations involved in tracking with the semiautomatic method. Depending on the experimental condition (e.g., how many whiskers are left intact) and the number of whiskers that can be tracked simultaneously, the method improves the efficiency of data point acquisition by ≤20 times (Table 1).

View this table:

Typical durations involved in tracking with the semi-automatic method (4 s at 500 fps with a 2 GHz PC)

Kinematics of whisker protraction and retraction

The high yield achieved with our high-speed video and simple image processing analysis, as well as the reproducibility of the method, is shown in Fig. 6. After tracking the head and whisker movements of three rats, we identified 2,521 individual whisks with amplitudes >5° of angle collected from 800 experimental trials (1–4 s each). The correlation between whisk amplitude and peak velocity, particularly during retraction, was high, as previously reported by others ( Bermejo et al. 1998; Carvell and Simons 1990).

FIG. 6.

Correlation between whisk amplitude and peak velocity. Individual whisks (n = 2,521) were automatically detected in traces of whisker angle low-pass filtered at 40 Hz. These raw traces were low-pass filtered again at 60 Hz, and whisking amplitudes and peak velocities during protraction and retraction of individual whisks were estimated. Amplitudes of individual protractions and retractions are plotted against their respective peak velocities.

Whisker oscillations

Recent work by Hartmann et al. (2003) has suggested that resonant oscillations of whiskers may be important during behavior. Our method of tracking enables tracking of both first- and higher-order oscillations with one or more radii. Figure 7 shows tracking of the C2 whisker with a single radius (3 spline interpolation points) as it hits and passes a vertical bar at three separate instances. The whisker oscillates for two to three cycles at ∼66 Hz. Higher-order vibrations can also be detected using splines with two or more radii.

FIG. 7.

Tracking of whisker oscillations with 3 spline interpolation points. C2 whisker of a rat performing an object localization task was tracked in 3 different trials as it hit and passed a vertical bar during retraction. Right: whisker while (A) pushing against the object, (B) moving past it, and (C) responding with a rebound oscillation. Left: trace of whisker angle in the 3 trials.

Comparison of full-length and single-point whisker tracking

The method we describe accurately estimates the position and shape of the entire visible portion of the whisker shaft. In contrast, tracking of a single point along the whisker shaft yields no information on whisker shape and probably inaccurate information on important kinematic parameters, such as whisker angle at its base (base angle). Estimation of base angle from a single tracked point on the whisker assumes a static, nonmoving reference point (or pivot) and rigidity of the whisker shaft. That the shape of the whisker changes during free-air whisking is shown in Fig. 5. Actions of the muscles that drive whisking may also move the pivot point ( Berg and Kleinfeld 2003a).

To estimate the errors produced by tracking a single point along the whisker, we compared whisker angle computed using the full whisker-representation (Eq. 1; Fig. 8A) with an angle computed between a fixed reference and a particular radial location on the whisker shaft (Fig. 8B). The first estimate, which we will refer to as the moving-reference estimate, is influenced both by movements of the whisker shaft base and by whisker bending. For the fixed-reference estimate, we used as fixed reference the intersection of two lines drawn through the base of the whisker at onset of protraction and at peak protraction; the distal end of the line was varied between 10 and 30 mm from base. The two estimates of angle calculation were compared separately for whisks in free-air and those that brought the whisker in contact with an object between protraction onset and half-way to maximal protraction (0 to π/2). The averaged whisk trajectories of angle and angular velocity are depicted in Fig. 9. For nontouch whisks, the moving-reference estimate of whisk amplitude (maximum angle -minimum angle; Fig. 9, A and B) was significantly different from the fixed-reference estimate only when the latter was computed 30 mm out on the whisker shaft (z = 11.0518, P < 0.001; Wilcoxon rank-sum test). However, estimates of whisk amplitudes during touch were significantly different even when the fixed-reference estimate was computed just 10 mm from the whisker base (z = 6.59, P < 0.001). Estimations of angular velocity (Fig. 9, C and D) were more sensitive to the calculation method used and differed significantly even at 10 mm from base both during nontouch (z = 12.50, P < 0.001) and touch (z = 13.12, P < 0.001) whisks. Thus when an angle is calculated between a particular location on the whisker shaft and a fixed reference point, the estimate can deviate significantly from a direct measure of the whisker angle at a moving base, both during nontouch whisking and touch whisking (see absolute magnitudes of deviations in Fig. 10). Deviations in angle and angular velocity estimates are larger during touch than nontouch, but can also be significant during nontouching whisking.

FIG. 8.

Estimation of whisker angle. Panels show a rat with one of its whiskers in the retracted and protracted state. Two angle estimates were applied: (A) whisker angle (θ) was estimated as the tangent of the curvature at base (see Eq. 1), and (B) whisker angle was estimated as the angle of a line connecting a point somewhere along the whisker (10–30 mm from base) and a fixed reference. The fixed reference was taken as the intersection between 2 lines drawn through the base of the whisker at onset of protraction and at peak protraction.

FIG. 9.

Moving- and fixed reference estimates of whisker angle. Whisker angle at base was approximated from the piecewise polynomial spline estimation of whisker shape and location (see Eq. 1) and compared with whisker angles computed as the angle between a fixed reference point and the whisker location 10–30 mm from whisker base (0 mm from base refers to the moving-reference estimate of whisker angle). Significance was determined by Wilcoxon rank-sum tests. Traces were normalized to unit length and averaged. A: estimated angles of whisks that did not touch any object (n = 788). Only amplitudes of whisks measured 30 mm from the whisker base were significantly different from whisk amplitudes computed with a moving reference (z = 11.05, P < 0.001) B: estimated angles of whisks that touched an object between onset and protraction half-peak (0 to π/2 of the spatial phase of whisking; n = 561). Amplitudes estimated with a moving reference were significantly different from amplitudes measured 10 (z = 5.82), 20 (z = 4.73), and 30 mm (z = 11.99; P < 0.001 for all comparisons) from base with a fixed reference. C and D: whisk velocity of nontouching (C) and touching (D) whisks. Peak angular velocity during protraction estimated with a fixed reference differed significantly from the velocity estimate obtained from angle at base (moving reference) both for nontouch (10 mm: z = 10.37; 20 mm: z = 7.53; 30 mm, z = 17.73) and touch whisks (10 mm: z = 12.09; 20 mm: z = 9.79; 30 mm, z = 15.25; P < 0.001 for all comparisons).

FIG. 10.

Differences between fixed and moving reference angle estimation. Angle and angular velocities were estimated with either a moving reference or a fixed reference (10–30 mm from base). A and B: average difference in percent of the maximal angle estimated with a fixed reference, for nontouch (A) and touch (B) whisks. The object touched the whisker ∼20 mm from whisker base. Thus, due to effects of bending, error is reduced somewhat when the reference point on the whisker is placed further than 20 mm out on the whisker shaft. C and D: average difference in percent of maximal angular velocity for nontouch (C) and touch (D) whisks.


Due to recent methodological advances, the rodent vibrissal system, which has been extensively studied in restrained and anesthetized animals, can now be studied in awake and unrestrained animals. However, in paradigms with freely moving animals, lack of stimulus control is a major concern. When the behavior of an animal is not limited, both the actions of the animal and the effects of environmental features on those actions must be accurately monitored.

Here, we describe how head and whisker movements can be tracked semiautomatically in both immobilized and unrestrained rodents, using high-speed video and image processing, at high spatial (>5 pixels/mm) and temporal (125–1,000 frames/s) resolution. The method allows tracking under different experimental conditions and illumination settings (Fig. 3). When spatial resolution is such that individual whiskers can be resolved, multiple whiskers can be tracked separately in the same movie. Thus the entire whisker array can be left intact throughout an experiment. Manual intervention is occasionally called for when tracking individual whiskers in a crowd of whiskers or when a whisker of interest overlaps completely with other whiskers. With good spatial resolution, however, or under simplified conditions (e.g., by trimming whiskers not of interest) most tracking is automatic. Our algorithm achieves accurate and fast determination of the updated whisker position by matching a limited number of splines to whisker-like features in the image. The method significantly increases the efficiency of data collection compared with previously described methods. When we applied our method to freely moving rats engaged in a tactile discrimination task, as well as an unstructured task, we achieved high yield of data with kinematic properties similar to those observed by others (e.g., Bermejo et al. 1998; Carvell and Simons 1980).

Whereas other reported methods track a single parameter (such as location of a particular point on the whisker shaft or time-varying EMG of muscles that move the whiskers), our method tracks both the shape and location of a whisker over time. We found significant differences between whisker angles measured directly at the whisker base from its piecewise polynomial representation and those measured between a fixed reference and a particular location on the whisker shaft, both when whiskers moved freely or against obstacles (Figs. 9 and 10). Previous studies have indicated that bending affects whisker angle at base and is important during exploratory behavior ( Carvell and Simons 1990; Hartmann et al. 2003; Krupa et al. 2001). It is therefore necessary, as we show here quantitatively, to track both the base of the whisker as well as its full length. The importance of the latter point has long been recognized, and we introduce here a flexible and efficient method of tracking whiskers that provides such information, previously unavailable using other automated techniques.

Full-length whisker tracking also allows characterization of the mechanical effect of obstacles on the whisker shaft, such as whisker bending and small oscillations (Fig. 7), probably necessary for extrapolating receptor responses within the follicle. Locations of whiskers, relative to objects in the environment, is readily obtained by coordinate transformations between relative (head-centered) and absolute (world-centered) coordinates. Thus environmental features can be marked and moments of touch automatically detected and cross-referenced with neuronal signals. Since results of full-length tracking are unambiguous, this method can efficiently and accurately characterize kinematic parameters of whisking, especially when whiskers come into contact with stationary or moving objects and textures.

Tracking head and whisker movements with a single viewpoint precludes a three-dimensional description of head and whisker orientation. Thus, the top-down viewpoint used here does not capture vertical excursions of the whisker trajectories ( Bermejo et al. 2002). Our observation that curvature changes throughout protraction may be due to such excursions, such as may be caused by rotation of the follicle. Furthermore, anterior-posterior movements can only be estimated correctly when it is assumed that the head neither has pitch nor roll. Our whisker tracking method does not assume a particular viewpoint, and a two-viewpoint solution (using extra cameras or mirrors) may therefore in principle allow a more accurate description of whisker movements and curvature changes in all three dimensions.

Our tracking method requires video movies of good quality and assumes that whisker displacement is small from frame to frame. The second criterion is achieved using a fast video acquisition system; we observed maximal efficiency with frame rates >100 fps. As fast video integrates over very short periods of time, a strong source of illumination is required. We used an array of infrared light-emitting diodes or a fiber-optic light source, combined with a bright lens, to achieve strong lighting without excessive heating. We also found that backlighting gave better results than illumination of the whiskers from the top or sides. With our imaging system, we achieved stable tracking even when the diameter of a whisker (∼140 μm for the C2 whisker; Neimark et al. 2003) was less than the width of a pixel (∼250 μm at the horizontal plane of the whisker).

We chose high-speed video to track whisker movements because it does not require additional invasive procedures, and the underlying technology is scalable as the resolution of high-speed cameras continues to improve. Our method of automated analysis of high-speed video allows effective, direct, and accurate measurements of head and whisker kinematics. Furthermore, the method readily allows the experimenter to identify and characterize whisker interactions with environmental features at a resolution sufficient for analyzing their correlation with fast neuronal signaling. Thus the method is well suited to investigate mechanisms related to active sensing of the whisking sensorimotor loop ( Ahissar and Kleinfeld 2003), and somatosensory processes in general.


This work was supported by the Mrs. Esther Smidof Foundation, Israel Science Foundation Grant 377/02-1, United States-Israel Binational Science Foundation Grant 2003222, the MINERVA Foundation, the Human Frontier Science Program, and the Horowitz Fellowship from the Center for Complexity Science awarded to D. Derdikman.


We thank M. Pietr, S. Haidarliu, B. Schick, K. Bagdasarian, and N. Rubin for assistance during the preparation of this manuscript. E. Ahissar is the incumbent of the Helen and Sanford Diller Family Chair in Neurobiology.


  • 1 The Supplementary Material for this article (a movie and text) is available online at

  • The costs of publication of this article were defrayed in part by the payment of page charges. The article must therefore be hereby marked “advertisement” in accordance with 18 U.S.C. Section 1734 solely to indicate this fact.


View Abstract