The use of image analysis as a new approach to assess behaviour classification in a pig barn

The aim of this study was to develop an innovative method for measuring the activity level of pigs in a barn in real time. An infrared-sensitive camera was placed over two pens of the piggery, images were recorded for 24 h a day for eight days during the fattening period, and the activity and occupation indices were calculated every second in real time using software. In the laboratory, the recorded images were visually labelled to score the animals’ behaviour adopting the Martin and Bateson’s Scan sampling method, and to find a relation with the automatically measured activity index. Pigs’ behaviour was assigned in the following way, 0 no activity, 1 fighting or struggling, 2 biting one another, 3 abnormal behaviour as nuzzling or suckling one another (interacting pigs), 4 feed assumption time. Pigs spent most of the time lying inactively (82–90% of the time), following a diurnal rhythm with peaks related to the feeding administration routine; fighting episodes occurred very rarely (0.05–0.10% of the time). Based on the analysis of the automatically measured group activity index compared to the manual labelling, a relation was found between the activity index and the behaviour types (no activity, nuzzling and feeding). The novelty presented in this study was the development of on-line tools to monitor farm animals continuously during their life, in a fully automatic way, with objective measures and criteria without imposing additional stress to the animals. On-line animal observation, labelling, behaviour score, swine In the past, livestock management decisions have been based almost entirely on visual and auditory observation, judgment and experience of the farmer, since pig behaviour has been used extensively as an indicator of their welfare (Broom 2002). Housing for intensive rearing is usually a long-term condition for farm animals (Rushen 2003) and results in a chronic state for an individual. These intensive systems are responsible for a greater incidence of health diseases compared to extensively reared pigs, moreover, the barren environment does not allow the pigs to express many of their typical behaviours (Gade 2002). The slatted floor, wide-spread on Italian intensive pig farms, can induce mortality in slaughter pigs (Voslářová et al. 2010). This trade-off makes it very difficult to evaluate overall welfare, especially because the value of each welfare problem is assessed differently by different scientists (Fraser 2003). These problems can be identified by using various indicators of a husbandry system, and by evaluating their effect on pig welfare and health. These physical and behavioural abnormalities of pigs can be assessed by examination of the pigs at either the group or individual animal level. In field conditions, together with the increasing scale of the farms and the corresponding high number of animals per farm, this change has resulted in an increasing workload for the farmer and, at the same time, limited the possibilities for the farmer to monitor his or her animals. The aim of this study was to evaluate animal behaviour on an intensive swine farm through on-line automatic measurements of animal activity, and to rank animal behaviour with labelling procedure. ACTA VET. BRNO 2013, 82: 025–030; doi:10.2754/avb201382010025 Address for correspondence: Dr. Annamaria Costa Department of Health, Animal Science and Food Safety Faculty of Veterinary Medicine, Università degli Studi di Milano via Celoria 10, 20133 Milan, Italy Phone: +39-02-50317909 Fax: +39-02-50317909 Email: annamaria.costa@unimi.it http://actavet.vfu.cz/ Materials and Methods Description of the monitored buildings The study was conducted in a pig fattening house located in Northern Italy. The barn housed 350 finishing pigs, was open-spaced, 14 m wide × 21.2 m long, mechanically ventilated, subdivided into 16 pens each, 5.9 m wide × 2.6 m long, and with a fully slatted floor. The pens were delimited by a concrete wall 1 m high and 0.2 m thick. The wall with the entrance door and the opposite wall had four windows each to light the building. The windows had a surface area of 1.32 m2 (0.6 × 2.2 m; height × width) and were located 2 m above the floor. The pigs were fed 3 × daily, at 8.30 h, at 15.30 h and at 19.00 h. The troughs were placed on the longitudinal wall dividing the two pens; the drinking bowls were located at the corner of each pen. Lights were switched on 15 min before feed administration and the lighting schedule was 40 min per every feeding release time. Monitoring system of animal activity, definition of activity and occupation indices From the 16 pens in the barn, two pens were selected for the experiments; one pen contained 16 pigs, the other 17. At the start of the finishing stage, the mean weight of the pigs was 60 kg and their mean age was 150 days. An infrared sensitive CCD camera (VCB 3572IRP) was mounted 5 m above the floor with its lens pointing downward and directly above the wall separating the two pens to get a top view of both pens in the camera image (Plate III, Fig. 1). The camera was connected to a computer with a built-in frame grabber (Data Translations DT 3210) using a coaxial cable. Images were captured with a resolution of 768 × 586 pixels at a sample rate of 1 Hz, i.e. one frame per second. The monitoring phase was performed 24 h a day for eight days, observing each frame (1 frame per second). During this period, the Eyenamic system was running in real-time and video images from the camera were recorded simultaneously. Eyenamic is innovative software that continuously and automatically registers the behaviour of a group of animals. Prior to the experiment, the camera was calibrated so areas of pixels in the image could be converted to units of cm2 on the pen floor. Because no markers could be added to the pig pens visible in the camera image prior to the experiments, an in-depth camera calibration was not possible. The image was calibrated to establish a linear scale factor in cm/pixel so that the area of pixels in the image could be converted to units of cm2 on the pen floor. Fig. 1 shows the experimental setup and subdivision of the two pens into two areas (pen 1 into areas 1 and 2 with 16 animals, and pen 2 into areas 3 and 4 with 17 animals). Every second, the software automatically grabbed a monochrome image I (x, y, t) from the camera and calculated the difference of the intensity values with the previous image I (x, y, t-1), taken a second earlier. From this difference image, the binary ‘activity image’ Ia (x, y, t) was calculated, containing the pixels for which the intensity change exceeded a threshold:

In the past, livestock management decisions have been based almost entirely on visual and auditory observation, judgment and experience of the farmer, since pig behaviour has been used extensively as an indicator of their welfare (Broom 2002).Housing for intensive rearing is usually a long-term condition for farm animals (Rushen 2003) and results in a chronic state for an individual.These intensive systems are responsible for a greater incidence of health diseases compared to extensively reared pigs, moreover, the barren environment does not allow the pigs to express many of their typical behaviours (Gade 2002).The slatted floor, wide-spread on Italian intensive pig farms, can induce mortality in slaughter pigs (Voslářová et al. 2010).This trade-off makes it very difficult to evaluate overall welfare, especially because the value of each welfare problem is assessed differently by different scientists (Fraser 2003).These problems can be identified by using various indicators of a husbandry system, and by evaluating their effect on pig welfare and health.These physical and behavioural abnormalities of pigs can be assessed by examination of the pigs at either the group or individual animal level.In field conditions, together with the increasing scale of the farms and the corresponding high number of animals per farm, this change has resulted in an increasing workload for the farmer and, at the same time, limited the possibilities for the farmer to monitor his or her animals.
The aim of this study was to evaluate animal behaviour on an intensive swine farm through on-line automatic measurements of animal activity, and to rank animal behaviour with labelling procedure.

Description of the monitored buildings
The study was conducted in a pig fattening house located in Northern Italy.The barn housed 350 finishing pigs, was open-spaced, 14 m wide × 21.2 m long, mechanically ventilated, subdivided into 16 pens each, 5.9 m wide × 2.6 m long, and with a fully slatted floor.The pens were delimited by a concrete wall 1 m high and 0.2 m thick.The wall with the entrance door and the opposite wall had four windows each to light the building.The windows had a surface area of 1.32 m 2 (0.6 × 2.2 m; height × width) and were located 2 m above the floor.The pigs were fed 3 × daily, at 8.30 h, at 15.30 h and at 19.00 h.The troughs were placed on the longitudinal wall dividing the two pens; the drinking bowls were located at the corner of each pen.Lights were switched on 15 min before feed administration and the lighting schedule was 40 min per every feeding release time.

Monitoring system of animal activity, definition of activity and occupation indices
From the 16 pens in the barn, two pens were selected for the experiments; one pen contained 16 pigs, the other 17.At the start of the finishing stage, the mean weight of the pigs was 60 kg and their mean age was 150 days.
An infrared sensitive CCD camera (VCB 3572IRP) was mounted 5 m above the floor with its lens pointing downward and directly above the wall separating the two pens to get a top view of both pens in the camera image (Plate III, Fig. 1).The camera was connected to a computer with a built-in frame grabber (Data Translations DT 3210) using a coaxial cable.Images were captured with a resolution of 768 × 586 pixels at a sample rate of 1 Hz, i.e. one frame per second.The monitoring phase was performed 24 h a day for eight days, observing each frame (1 frame per second).During this period, the Eyenamic system was running in real-time and video images from the camera were recorded simultaneously.Eyenamic is innovative software that continuously and automatically registers the behaviour of a group of animals.
Prior to the experiment, the camera was calibrated so areas of pixels in the image could be converted to units of cm 2 on the pen floor.Because no markers could be added to the pig pens visible in the camera image prior to the experiments, an in-depth camera calibration was not possible.The image was calibrated to establish a linear scale factor in cm/pixel so that the area of pixels in the image could be converted to units of cm 2 on the pen floor.Fig. 1 shows the experimental setup and subdivision of the two pens into two areas (pen 1 into areas 1 and 2 with 16 animals, and pen 2 into areas 3 and 4 with 17 animals).Every second, the software automatically grabbed a monochrome image I (x, y, t) from the camera and calculated the difference of the intensity values with the previous image I (x, y, t-1), taken a second earlier.From this difference image, the binary 'activity image' I a (x, y, t) was calculated, containing the pixels for which the intensity change exceeded a threshold: (1) From the activity image I a (x, y, t) the activity index a i (t) for zone Z i was calculated as the fraction of moving pixels with respect to the total number of pixels within the zone Z i : (2) The threshold τ 1 accounted for small intensity changes due to noise, e.g.electrical noise in the coax cabling and image acquisition circuits, small lighting variations, etc.The value of the threshold was set to 10% of the maximal intensity value, estimated by looking at the intensity variation of an 'empty' region, outside of the pig pen, equivalent to one minute of recording.An additional upper threshold τ 2 was applied to the activity index a i (t) to compensate for drastic intensity changes (e.g. when lights were switched on/off).In the case of such an event, almost all pixels in the activity image I a were 'active' and the activity index a i (t) was almost equal to 1 in all zones.The threshold τ 2 was set to 0.5 of the maximal activity index.If this threshold was exceeded, i.e. more than half of the zone area was active; the activity index was set to zero.The pixel area sums in the nominator and denominator of equation ( 2) have an accuracy of one pixel which, using the camera calibration factor was equivalent to an area of 2.9 cm 2 .

Labelling procedure
After downloading recorded data to the laboratory, the image files were visually assessed and labelled observing each frame (one frame per second) in order to evaluate animal behaviour during the day.The observed frames were monitored and analyzed 24 h/day for 8 days by Eyenamic software.The behaviour of the pigs was observed according to the Scan sampling method described by Martin and Bateson (1986), a focal animal sampling that scans a whole group of animals to record specific, limited behaviors.The pig behaviour was recorded continuously to provide a correct and accurate record, measuring the variation of animal activity and occupation index when the behaviour started, the true duration, frequency and the time at which behaviour I a (x, y, t) = { 1 if I (x, y, t) -I (x, y, t -1) > τ 1 0 otherwise patterns started and stopped.Behaviour pattern scores were assigned as follows: 0 -no activity, 1 -fighting or struggling, 2 -biting one another, 3 -abnormal behaviour intended as nuzzling or suckling one another (interacting pigs), 4 -feed assumption time.When two or more behaviour patterns were observed, they were both labelled, for example, when both fighting and biting was observed simultaneously in the pig group, behaviours were labelled as 12.

Statistical analysis
As mentioned previously, the Activity Index was calculated by Eyenamic as the fraction of moving pixels with respect to the total number of pixels within a certain area, while the Occupation Index was calculated as the fraction of pixels corresponding to a region of the image occupied by pigs with respect to the total number of pixels within the same zone.These two indices, one datum for second for each area, were submitted to a variance analysis (Proc GLM, SAS 9.2, 2010) to evaluate the effect of the areas, time and feeding administration on these two variables.We performed the tests using target significance levels of 0.01 and 0.001.Frequency analysis (Proc FREQ, SAS 9.2, 2010) was performed to investigate the behaviour dynamics of pigs according to Lyons et al. (1995).Finally, another variance analysis (Proc GLM, SAS 9.2, 2010) was performed on all data, either those provided by Eyenamic software or those coming from the labelling procedure, to study the effect of labelled behaviour pattern on animal activity level.

Results
The daily mean activity of pigs for every area is shown in Table 1.Animal activity was higher in area 4 (0.0190, P < 0.001) near the corridor, where farmers usually passed for their daily inspections.The maximum activity values in relation to the time of observation occurred in all areas (P < 0.001) during feed administration in the barn (8.30 h, 15.30 h, 19.00 h and during the release of extra water at 22.00 h).During the night the activity index showed the lowest values recorded (less than 0.005 units).The activity of the pigs followed a diurnal rhythm with peaks occurring with the management routine procedures (feeding administration, farmer's inspections, Fig. 2A).During feeding time, the pigs moved to

27
Table 1.Ls means of activity and occupation index calculated by Eyenamic on observed pigs during the experimental period.the trough distributing themselves in a homogeneous way in all the areas; at the end of the feeding time, most of the pigs moved to areas 1 and 4, near to the corridor, using these areas as a "resting place".As a consequence, the occupation index increased in these two areas (Fig. 2B).Table 1 reports the mean Occupation indexes calculated by Eyenamic in pigs during the 24 h in each day of the trial, and Fig. 2B shows the mean daily trend of the Occupation Indexes.Daily Occupation Index was higher in area 1 (pen 1) and area 4 (pen 2), both placed near the corridor (0.504 and 0.534 units, respectively, P < 0.001).
Hourly values of the Occupation Index reached up to 0.75 units in area 4. Areas 2 and 3 near the external wall characterized by a humid floor surface and limited air flow were essentially utilized by animals as defaecation zones.The Frequency Analysis conducted in the laboratory on labelled behaviours showed that the pigs spent most of the time lying inactive (from 81.52% in area 4 to 90.29% of the time in area 3).Fighting episodes or attacks conducted by pigs occurred occasionally and only for a mean value of 18 × a day, i.e. 0.05-0.10% of the observation time.Biting behaviour occurred rarely (0.20- 0.52% of the experimental period), nuzzling behaviour was exhibited by the pigs for 7.73-16.41% of the time; 1.69% of the time was dedicated to feed consumption.During the day biting and fighting were observed as an abnormal behaviour pattern following the normal exploratory behaviour of nuzzling (Fig. 3).These behaviour patterns were observed mainly during the day and not at night, after the re-mixing of pigs to return to rest on the floor.The pigs became inactive 55 min after feeding time (Fig. 2A).Example of the measured activity index and the behaviour type for area 1 are shown in Fig. 4A.The GLM procedure highlighted the effect of the type of behaviour on the animal activity index, showing that feeding consumption (labelled as 4) corresponded to an activity index of 0.54 (P < 0.05), nuzzling (labelled as 3) corresponded to an activity index of 0.19 (P < 0.01).The analysis of the automatically measured group activity index compared to the manual labelling reported in Fig. 4A and 4B, highlights the relationship between the activity index and the behaviour types called 'no activity', 'nuzzling' and 'feeding'.Feeding represents a period with higher activity.However, behaviour related to aggressiveness of individual pigs ('fighting' and 'biting', Fig. 4A and 4B) cannot be detected from instantaneous measurements of the group activity index.Fig. 3 shows that the pigs tended to exhibit exploratory behaviour mainly from 9.00 h to 22.00 h, especially during the hours of the day characterized by higher light intensity (from 12.00 h to 18.00 h).Around feeding times some aggressive behaviour occurred, probably as an expression of the re-establishment of the social hierarchy among the animals.

Discussion
The pigs' activity followed a diurnal rhythm with peaks related to management routine (Lyons et al. 1995).The pigs spent most of time inactive, with fight episodes rarely lasting

Activity index
longer than four seconds.The attacked pig vacated the area and the dominant pig assumed the place previously occupied by the other pig.The high values related to "inactivity" may be due to the slatted floor that makes walking difficult (Lyons et al. 1995).Similar values were found by Ekkel et al. (2003) in a study performed on pigs of various live weights (from 30 to 100 kg) reared on partly slatted floor.There was a significant period effect for the space-sharing data; pigs showed more 'social lying behaviour', i.e. tended to huddle more during the night compared to the day, since the spacesharing percentages were higher during the night.Fighting episodes occurred very rarely (0.05-0.10% of the time) and were less intense than those recorded by Lyons et al. (1995), whereas nuzzling which can be read as "social behaviour" occurred more frequently in our study (up to 16.41% in area 4) compared to 1.6% measured by Lyons et al. (1995).Nuzzling can be a sign of socialization or interaction among pigs but when it is exhibited for long periods as in our study, it can be also an expression of disease, a frustrated suckling behaviour brought about by early weaning (Lyons et al. 1995) or the beginning of cannibalism episodes.The overhead view was the best way to have a complete coverage of the boxes but presented some difficulty in labelling the pigs' behaviour.In particular cases, e.g. when pigs were lying to rest, it was hard to distinguish whether they were suckling or nuzzling.It was therefore assigned the subjective score of "3" to indicate all the abnormal behaviours including both nuzzling and suckling.The recorded images showed that pig suckling usually lasted longer than nuzzling (sometimes more than 5 min).At slaughter time, injuries were noticed on the legs of these pigs which could be due to the suckling behaviour observed on the video images.The lack of interest and rare episodes of abnormal behaviour shown by the pigs during the observation period could be explained by lack of environmental enrichment, by the building structure itself and the presence of the fully slatted floor; since previous studies reported that barren housed pigs behave more aggressively and display more abnormal agonistic behaviour than enriched housed pigs (O'Connell and Beattie 1999).
Fig 2A.Hourly mean values of activity index calculated by Eyenamic on observed pigs during the experimental period.

Fig. 2B .
Fig. 2B.Hourly mean values of occupation indexes calculated by Eyenamic on observed pigs during the experimental period

Fig. 4A .
Fig. 4A.Example of the manual behaviour labelling of the pigs in zone 1.

Fig. 4B .
Fig. 4B.The automatic activity index in zone 1 as measured by the software during the experimental period.
Fig.1.The two pens each divided in two areas (first pen with 16 pigs in area 1 and 2, second pen with 17 pigs in area 3 and 4).The four areas were monitored by Eyenamic software to calculate the occupation and activity indexes on observed pigs during the trial.