Next Article in Journal
Why Are Farmers Reluctant to Sell: Evidence from Rural China
Next Article in Special Issue
Facial Region Analysis for Individual Identification of Cows and Feeding Time Estimation
Previous Article in Journal
Design and Mechanical Analysis of a Cam-Linked Planetary Gear System Seedling Picking Mechanism
Previous Article in Special Issue
Estimating Body Weight in Captive Rabbits Based on Improved Mask RCNN
 
 
Font Type:
Arial Georgia Verdana
Font Size:
Aa Aa Aa
Line Spacing:
Column Width:
Background:
Article

An Approach towards a Practicable Assessment of Neonatal Piglet Body Core Temperature Using Automatic Object Detection Based on Thermal Images

1
Department of Animal Sciences, Georg-August-University, 37075 Göttingen, Germany
2
Institute of Mathematics, University of Mannheim, 68131 Mannheim, Germany
*
Author to whom correspondence should be addressed.
Agriculture 2023, 13(4), 812; https://doi.org/10.3390/agriculture13040812
Submission received: 9 March 2023 / Revised: 28 March 2023 / Accepted: 29 March 2023 / Published: 31 March 2023
(This article belongs to the Special Issue Artificial Intelligence in Livestock Farming)

Abstract

:
Body core temperature (BCT) is an important characteristic for the vitality of pigs. Suboptimal BCT might indicate or lead to increased stress or diseases. Thermal imaging technologies offer the opportunity to determine BCT in a non-invasive, stress-free way, potentially reducing the manual effort. The current approaches often use multiple close-up images of different parts of the body to estimate the rectal temperature, which is laborious under practical farming conditions. Additionally, images need to be manually annotated for the regions of interest inside the manufacturer’s software. Our approach only needs a single (top view) thermal image of a piglet to automatically estimate the BCT. We first trained a convolutional neural network for the detection of the relevant areas, followed by a background segmentation using the Otsu algorithm to generate precise mean, median, and max temperatures of each detected area. The best fit of our method had an R2 = 0.774. The standardized setup consists of a “FLIROnePro” attached to an Android tablet. To sum up, this approach could be an appropriate tool for animal monitoring under commercial and research farming conditions.

1. Introduction

In recent years, publications on the use of thermal imaging cameras in pig farming have increased. There are various approaches that estimate rectal temperature, which is considered the gold standard for body core temperature (BCT). See, for example, studies on sows [1,2,3], fattening pigs [4,5,6], and piglets [7,8,9].
The major advantage of thermal images is that they are non-contact and quick to acquire; thus, they can protect animals from unnecessary stress, or in the worst case, disease cross-transmission, by measuring the temperature with a rectal thermometer [10]. However, thermal cameras with good measurement accuracy are mostly very expensive, and thus their advantages over traditional digital rectal thermometers within a practical farm’s daily life are doubtful. In addition, approaches for the estimation of rectal temperature with thermal images are often based on multiple, manually recorded close-up images from different body parts, so called thermal windows [10,11], which can reduce the possible stress and time-saving benefits because multiple recordings close to the animal have to be taken by the personnel. Furthermore, unlike IR pyrometers (point measurement devices), a thermal image does not immediately provide the desired surface temperature without a manual effort. Several factors, such as the emissivity value of the object’s surface and the ambient climate information, need to be manually adjusted, and the relevant parts of the body have to be marked inside the manufacturer’s software to achieve accurate values of different body parts, e.g., maximum, minimum, and average, which are needed for the regression of the rectal temperature.
The BCT can be used as a hint for several diseases or hormonal changes, such as mastitis, metritis, and agalactia (MMA) [12], the onset of farrowing in sows [13], or, for example, classical fever in fattening pigs [1]. Further, thermal images were used to detect inflammation [14] and lesions [15], which are linked to isolated surface temperature deviations.
For neonatal piglets, especially for small ones [16], the BCT is a very important characteristic. Due to their lack of insulation [17], the temperature gradient between the ambient temperature and the BCT during the first hours of life leads to a loss of the BCT. This can result in reduced mobility and a decreased ability to compete for colostrum and, therefore, a reduced colostrum intake, which then increases the likelihood of starvation, diseases, and crushing [18]. For example, [19] and [20] found a decrease of 4–5 °C in the piglet’s BCT when they failed to suckle during the first 30 min of life. After 24 h of life, vital piglets should have reached their normal thermal homeostasis of about 38–39 °C again [21,22].
Therefore, the surveillance of a neonatal piglet’s surface temperature could help to detect individuals with lower survivability and enable early and targeted manual assistance from animal care personnel. Since this and the manual, continuous surveillance of fattening pigs for fever or lesions can be very time-consuming, a practicable time-saving solution is needed.
This study has two goals. The first is to automatically combine the relevant information of the thermal image and its acquisition, followed by the detection of the piglet’s body parts, to generate features for the second goal, which is the regression of the rectal temperature by only one top-view image.
To make the approach economically implementable on a practical farm, a comparatively cheap thermal camera (FlirOnePro for Android) was chosen. All computations of the present approach are performed by the free statistical software “R” [23] (Version 4.2.2) and implemented in the package “ThermalpigR” [24].

2. Materials and Methods

Based on our dataset of thermal images, the workflow of the study was organized as follows: Firstly, the ambient climate information are measured by an external sensor, the emissivity value adjustment, and the distance to the object and the readout of the radiometric data of the images are accumulated and computed to pixel-wise temperature values. Secondly, the machine learning methods of object detection (Yolov3-SPP) [25] and background subtraction (Otsu algorithm) [26] are used to automatically extract the regression features (e.g., mean and max of different body parts). Thirdly, a linear regression approach, based on the extracted features and transformations of them, is comprehensively tested to improve the estimation of the rectal temperature.

2.1. Data Acquisition

The thermal images of neonatal piglets were recorded at the experimental farm (Relliehausen) of the University of Göttingen with interruptions (COVID-19) in three runs from March 2020 to August 2020. The sows (11 in total) were housed in a common farrowing crate, had genetics of German Landrace × Large White (Viktoria—Bundeshybridzuchtprogramm), and were all between the 2nd and 5th farrowing cycle. After 30 min of life, the piglets were removed from the pen and examined. The examinations took place according to a standardized setup (Figure 1). The piglets were examined as they were and not dry rubbed. Directly after recording the animal’s individual top-view thermal image with a “FLIROnePro” (Teledyne FLIR LLC) [27] connected to an Android tablet for data transfer, the rectal temperature was measured with a rectal thermometer “SC 1080” (SCALA Electronic) [28]. According to the manufacturer, the accuracy of the camera is ± 5% in a temperature range of 15–35 °C for the camera and 5–120 °C for the image scene [27]. Before an image was taken, the camera was calibrated by manually starting the automatic calibration according to the description of the manufacturer [27]. When the neonatal piglets were measured, the camera was connected to a power supply and the battery was loaded until 100% or until a new piglet was born. In addition, the piglet’s bodies were measured with a measuring tape for body length and chest girth (Figure 1b) and were weighted with a digital table scale (readability of 5 g). After the examination, they were given an ear tag for identification. During data acquisition, ambient temperature and humidity were measured inside each pen using a “TGP-4500” climate data logger (Gemini Data Loggers) (accuracy for ambient temperature is 0.45 °C and for humidity ± 3% at 25 °C [29]) every 15 min. In total, 160 images of 64 piglets could be used for further analysis.

2.2. Temperature Determination

The temperature T of each pixel was calculated from the radiation through the formulae of [30].
T = B ln R 1 R 2 W + O + F
where, B , R 1 , R 2 , O , and F are calibration constants [30]. The object´s radiation W = W o b j is a function of the transmission value ( τ ) , the emissivity value ε , the radiation of the atmosphere ( W a t m ) , and the reflected radiation ( W r e f l ) ,
W o b j = W t o t a l ε τ 1 ε W r e f l ε 1 τ W a t m ε τ
The emissivity value ε of the piglet’s skin was set to 0.98 [31]. The transmission value is calculated by the following formula:
τ = X   e x p d α 1 + β 1 H + 1 X   e x p d α 2 + β 2 H
where X , α 1 , α 2 , β 1 , and β 2 are constants from the camera calibration, which are saved to the metadata of the image. The variable d is the distance to the image, which was standardized to 50 cm in this study. Finally, the vapor content H is calculated from the environmental temperature and the relative humidity:
H = H r e l   e x p 1.559 + 6.939 × 10 2 T a t m 2.7816 × 10 4 T a t m 2 + 6.846 × 10 7 T a t m 3
where H r e l ϵ (0,1) is the relative humidity, and T a t m is the environmental temperature. The environmental temperatures and the relative humidity for the time, when a thermal image was recorded, were interpolated linearly from the 15 min measurements of the climate data logger.

2.3. Object Detection and Feature Extraction

For training the object detection of the four classes (piglet, head, back, and back end), all 160 images were annotated in YOLO format by one expert using the Roboflow annotation tool [32]. A description and examples of annotation of the body parts are given in Table 1. If a body part is not completely inside an image, the body part is still annotated for its visible part. On seven images, the head was not completely inside the image and on one image the back end.
After splitting the data randomly into training, validation, and test sets (70/20/10-ratio), data augmentation methods (random horizontal, vertical flip, or rotate 90°, 180°, and 270°) were used (up to three times per image) to enlarge the training set to 316 images (validation and test set still containing 32 and 16 images, respectively). The convolutional deep neural network YOLOv3 [33] with spatial pyramid pooling block (SPP) [25,34] was trained via transfer learning from “Microsoft COCO” dataset’s [35] pretrained weights at a learning rate of 0.001 for 300 epochs with default hyperparameters (only number of classes was adapted and the batch size was set to 16) and evaluated afterwards, both via Google Colab [36]. An SPP block prevents images that have a different input size than required for the fully connected layers from being cropped or resized before the convolutional step. This ensures that all input images, regardless of their size, are neither distorted nor cut in such a way that all features are no longer visible. This enables multi-scale feature extraction, which leads to an improvement in performance in most cases [34]. A control logic to check if all four body parts are detected exactly once by YOLOv3-SPP was also implemented. An image where a body part is not detected has not been considered for further analysis. If a body part is detected several times, the detection with the highest confidence score is chosen. To measure the performance of the detection model, the common metrices precision (P), recall (R), and mean average precision (mAP), which is the arithmetic mean of the average precision (AP), were used:
P = T P T P + F P
R = T P T P + F N
A P = 0 1 p r d r
where T P denotes the number of true positives, F P is the number of false positives, and F N is the number of false negatives for precision and recall. Furthermore, AP is calculated as the integral from 0 to 1 over the precision p of the recall r. These metrices were calculated with a confidence score = 0.1 and a non-maximum suppression (NMS) = 0.6 on the validation set. The best model was chosen using a fitness score f,
f = 0.01 R ( τ c o n f ) + 0.99 m A P @ 0.5
where R ( τ c o n f ) is the recall at the specific confidence threshold and mAP@0.5 is the mAP with an interception over union of ≥0.5. The computation of the final model works with and without a CUDA-compatible GPU for user-friendliness.
After inferring all 160 images with this model, 150 images possessed all five body parts and stayed in the dataset for further analysis. To generate accurate mean and maximum temperature values for the detected body parts, the body part shapes were segmented from the background using the Otsu algorithm [26]. See Figure 2 for details. Whereby, the intersections of the detected bounding box area and the segmented foreground area contain the pixels that were used for further calculations.

2.4. Implementation

The complete workflow (Figure 3) is implemented in the R package “ThermalPigR” [24] using Python 3.8 besides R.
The package has several integrated functions which perform the following functions:
  • Combine the data from the ambient climate of each pen and match it with the thermal images.
  • Adjust the distance from the camera to the object and adjust the emissivity value of the object´s surface (Formulas (1)–(3)).
  • Perform body part detection (Yolov3-SPP) and control logic.
  • Perform background subtraction (Ostu).
  • Generate the features for regression models.
The images were processed using the R package “thermimage” [37]. The metadata of the radiometric JPEG images was imported using the function “flirsettings” and the radiometric values of each pixel were imported using the function “readflirJPG”. The regressions are performed with lsfit [23].

2.5. Data Anaysis

First, a rough outlier detection of the thermal images was performed by considering the highest 10 % difference between max head surface temperature (highest correlation to the rectal temperature (Figure 4)) and rectal temperature (15 outliers found). Additionally, all piglets with a rectal temperature <34 °C were sorted out (one outlier found) (Figure 5). The remaining 134 images were used to fit the linear regression models.
A total of 62 features were examined, including the maximum, median, and mean temperature values of the body parts (12 features), the square of maximum and mean for each body part (8 features), the 99th, 95th, and 90th quantiles for each body part (12 features), as well as the consideration of all pairwise absolute temperature differences as further features (e.g., |mb_mbe| for the difference between “max_back” and “max_be”) (28 features). In cases where the algebraic sign of the differences does not change in the dataset, the three features |Ta–Tb|, Ta, and Tb were collinear and the feature |Ta–Tb| was excluded as a feature whenever Ta or Tb was included in the model. In a few cases, Ta–Tb contains only a few changes in the algebraic sign (<10) for the whole dataset, which were considered measurement errors and the feature |Ta–Tb| was treated as if there was no change.
Additionally, the interpolated environmental variables, relative humidity, and ambient temperature were used (Table 2).
To find the best combination, a Best Subset Selection (BSS) [38] for 1–9 variables plus an intercept was performed using the AICc as stop criterion.
For testing potential improvements in the regression, the manually measured features’ body length and girth were additionally applied. Since length and girth are not automatically given, a simple linear regression of body length and girth with the Euclidean distance in pixels from the thermal images as features was also attempted. All regression models were checked for performance using the metrices root mean square error (RMSE), the coefficient of determination (R2), and a variation of the Akaike information criterion for small sample sizes (AICc) (9)–(11).
R M S E = i = 1 N y ^ i y i 2 N
Here, y i is the measured value and y ^ i is the prediction of the model. Thus, the RMSE has the same unit and scale as the variable being estimated. Additionally, the coefficient of determination R2 was computed to show how well the rectal temperature is explained by a model:
R 2 = 1 i = 1 N y i y ^ i 2 i = 1 N y i y ¯ i 2 ,
where y ¯ i corresponds to the mean of the measured values y i . To address the substantial risk of AIC selecting models that have too many variables, we chose the model by taking the one with the lowest AICc (AIC for small sample sizes):
A I C c = A I C + 2 p ( p + 1 ) n p 1
where AIC is defined as A I C = 2 ln L + 2 p , L denotes the log-likelihood estimate, n denotes the sample size, and p denotes the number of variables.

3. Results

3.1. Object Detection

The training progress of the YOLOv3-SPP model can be seen in Figure 6. The evaluation of the model is performed after each of the 300 epochs on the validation set (32 images). After 50 epochs, the model is already very good, with a precision of ~0.78, a recall of ~0.98, and a mAP of ~0.95. After 300 epochs, the best model was chosen by taking the model with the highest fitness score (8) for the validation set, which was the model after 238 epochs. Finally, YOLOv3-SPP was able to detect the trained body parts with a precision of 0.78, a recall of 0.98, and a mAP@0.5 of 0.97.
For final testing on the test set, the parameter’s confidence score and NMS were adapted to conf = 0.3 and NMS = 0.1. In the 15 test set images, all the body parts were detected at one time except for one image, where the back was not detected. These settings are chosen for the final model. For 160 images, an 8GB ram storage laptop with Intel Core i5-8265U CPU @ 1.6 GHz needed 103 s to run the model (~0.64 s/image).

3.2. Rectal Temperature Regression

As can be seen in Table 3 the simple linear regression of the max values of the areas “head” and “piglet” show promising results. As mentioned before, the features “max head” and “max piglet” have highest correlation (both 0.81) with the rectal temperature (Figure 4). The best model, acording to AICc (436.7), was the model with eight features, including “max_head”, “max_be”, “max_be2”, “air humidity”, “T_mb_mbe”, “Q_pig99”, “Q_head95”, and “T_mp_ab”. This model has an R2 = 0.774 and an RMSE = 0.406. The model with nine features had an AICc of 437.5. The best models for a fixed number of features (1–8) plus an intercept can be found in Table 4. The regression results of the overall best model (8 features) can be seen in Figure 7.

4. Discussion

In this study, an approach toward a practicable assessment of a neonatal piglet´s body temperature using object detection on thermal images was presented. The advantages are that only one top-view image per piglet is needed and that the evaluation of the image is automated. The standardized setup can provide images when the physical circumstances during image acquisition (distance to the object, object emissivity, air humidity, and air temperature) are stable and can be easily adapted, respectively, and measured automatically by other sensors. The usage of object detection algorithms enables the automatic calculation of features for the regression of the rectal temperature. This can save time and reduce the manual effort for the practical or scientific surveillance and monitoring of pigs. All computations are integrated in the R package “ThermalPigR” [24]. Nevertheless, this is only one possible approach, and the presented solution will be discussed in detail in the following sections.

4.1. Object Detection

In our opinion, the object detection results are sufficient to detect the piglet’s body parts. They might be further improved by a larger dataset and better image quality (some body parts were cut off by the edge of the image). Unfortunately, data acquisition was terminated early by a fire at the experimental farm and could not be resumed. Originally, the collection of data on at least 300 piglets was planned. A different Deep Convolutional Neural Network (DCNN) could also provide improved results. YOLOv3 is now fairly old, and there are more recent DCNNs. Some of them are able to generate better results on typical competition datasets such as “Microsoft COCO” [35] or “ImageNet” [39], but some of them are also larger (have more layers) and thus need more computing time. We chose YOLOv3-SPP because it is well documented and has been published several times with similar tasks. Images of insufficient quality and those causing errors during detections were sorted out by the implemented control logic.
As described in Section 2.4 and shown in the examples in Table 1, bounding box detection has the disadvantage that the body parts and the background are located within a bounding box. This problem is solved by performing background segmentation using the established Otsu algorithm [26]. Another approach could be via the use of polygonal annotation, where the objects are completely segmented by the DCNN. However, polygonal annotation has the disadvantage that it is much more time-consuming during the annotation process.

4.2. Region of Interest

As mentioned, many approaches to estimating the rectal temperature of pigs use so-called “thermal windows”. A thermal window is a skin area perfused by blood that can be considered the “window” of body temperature [10]. By contrast, a non-thermal window is a skin area that is covered with a thick layer of fat [2]. By deciding to make our approach as practicable as possible and using only one image, no real “thermal window”, such as the eye or the ear base, could be taken for the feature generation. However, Ref. [10] also stated that neonatal piglets, on the contrary to older pigs, may be looked upon as one large thermal window, where the skin temperature is almost uniform throughout the body surface due to their lack of insulation. This fact and the suggestion that nearly all piglets should be in a similar hormonal situation after 30 min of life because they have to overcome the same physiological challenges [40] might explain why the correlation of the maximum surface temperatures of the different body parts with the rectal temperature is very high in our study.
Tabuaciri et al. measured the average surface temperature of a crown to rump line and found a correlation of 0.75 with the rectal temperature of piglets (within 24 h of life), which is confirmed by the correlations of the max back (0.72) and the max back end (0.73) with the rectal temperature in our study. The highest correlations were found for the ear base (0.85 average of left and right) by [41]. In our study, we had the highest correlations for the max head and max piglet (both 0.81); however, the ear base was not specifically annotated. This can be explained by the fact that the max temperature of the head or the whole piglet, of course, may contain the ear base temperature if it is visible.
For the other pigs, Ref. [10] stated the influence of physiological differences such as age, the hormonal cycle, or stress on the surface temperature. Especially for piglets, Ref. [42] found significant results for the highest surface temperature after vaccination (day 14) and a lower surface temperature for older piglets (24 days) than younger piglets (days 4–18).

4.3. Surface Temperature Influencing Factors

Besides physiological influencing factors, the environment also has an impact on the surface temperature of the pigs. For example, the environmental temperature or wind can reduce the surface temperature of areas that are not well supplied with blood through convection [2]. The same is also true for, e.g., the resting areas of the animals. If there is high thermal conductivity in the materials, it can lead to a large deviation of the animal´s surface temperature in the areas that are in contact with the material due to heat conduction, depending on the temperature difference [6]. Nevertheless, the influence of wind and environmental surfaces can be ignored in our study. The experimental compartment was ventilated by a perforated ceiling, which has the beneficial attribute of low wind speeds. The heat conduction through the environmental surface is not relevant for the body parts that were examined (back, back end, and head from a top view). Thus, for settings other than ours, e.g., the outdoor climatic conditions in husbandry systems, these factors need to be integrated into the evaluation.

4.4. Regression

The simple linear regressions for the “max_head” and the “max_piglet” already provide good results (head: R2 = 0.651, RMSE = 0.507; piglet: R2 = 0.634, RMSE = 0.52). The authors of [2] found similar results for simple regression attempts for different body parts of sows where the RMSE was equal to 0.42 and 0.51 for the average ear base and max shoulder temperature, respectively. The variable selection for multiple linear regression was guided by the laborious but precise BSS method [38]. To keep computing times reasonable, we performed the BSS up to seven features plus the intercept. For more than seven features we always kept two features fixed. These two fixed variables are either “max_head” and its square or “max_be” and its square, as either pair shows up in all top ten fits for 5–7 variables. As assistance to the original features, we calculated absolute temperature differences that were similar to [2]. These new features provide additional information about the body core temperature, in cases where the temperature differences show different algebraic signs. When the temperature difference of two fixed body parts of all the pigs always has the same sign, the newly created feature might still be of interest as it is interpretable, but it might reduce the number of features in the model. In the best model, the feature “max_be” had the highest influence (−11.96), followed by features “Q_pig99” (+1.291), “Q_head95” (−0.9839), “max_head” (+0.9705), and “T_mb_mbe” (−0.7446). The features “max_be2” (+0.171), “T_mp_ab” (+0.1257), and “air humidity” (−0.00712) had the lowest influence.
Further approaches to improving the regression by supplying additional features (manually measured piglet body length and chest girth), which describe the body constitution of the piglets, improved the fit to R2 = 0.778 and RMSE = 0.405 when only six features were included. Indeed, both the body length (R2 = 0.29) and the chest girth (R2 = 0.47) are positively correlated to the rectal temperature, and therefore, they are beneficial for the regression model. However, these manually measured features are not given under practical conditions; thus, these two quantities were not considered in this study. Approaches that estimated the body length and chest girth from the pixel distances measured from the images with a simple linear regression did not work well (R2 = 0.11 (girth) and R2 = 0.05 (length)). This might be a result of the inconsistent position of the piglets during the image acquisition. With a standardized body position, the regression of the body length and girth should perform much better, as Ref. [43] described in their study, concerning the estimation of the bodyweight of pigs from images. The model that includes the length and girth can be found in the Appendix A (Table A1). To sum up, a rather sophisticated feature selection was performed, and an R2 = 0.774 was the best model found. The greatest limitation of a model with higher accuracy is the occurrence of inadequacies during the acquisition of the surface temperature. The measuring accuracy of the camera and the degree of moisture on the surface of the piglets should be the main factors. More data of the same quality should also not significantly improve the model anymore, since the overall performance seems to be limited to the inadequacies during the acquisition of the surface temperature.

4.5. Future Research and Usage

Generally, our approach is well suited for other studies that include the evaluation of thermal images. However, if a thermal camera from another manufacturer is included in new studies, the Formulas (1)–(3) must be adapted.
Since the aim of this study was to create a practical measuring tool, we decided to use the comparatively cheap thermal imaging camera “FLIR One Pro”. In addition to the lower accuracy compared to the more expensive thermal imaging cameras, the battery life and simultaneous charging and recording of the thermal images, or operation without a battery, are not possible, which renders continuous automatic data recording impossible. Furthermore, the camera is not suitable for permanent operation in a pig pen, as no protection against moisture or dust is guaranteed. However, a protection case could probably solve this problem.
In practical farming, for neonatal piglets, this approach might be used to detect piglets that are suffering from deep hypothermia (32–34 °C [44]) without the need to measure their rectal temperature, which can save additional stress on the fragile piglets. The ones who are suffering from hypothermia could be assisted in achieving access to the colostrum and placed under a heatlamp afterwards. Moreover, this approach might be used for continuously monitoring the body core temperature of fattening pigs in group pens with a sorting gate, individual feeding troughs, or drinking stations with an individual radio-frequency identification (RFID). For such an application of the algorithm presented, the following adaptations are necessary: As mentioned, the surface temperature of the pigs is altered in correlation to the body core temperature when they age, due to more fat layers and less peripheral blood flow. If the approach should remain a “one topview image” solution, more research on the surface temperature of pigs with different body weights and breeds is needed. Otherwise, an approach using “thermal windows” could also be a solution. Therefore, the object detector needs to be trained to detect, for example, the eyes of pigs. Whether a simple or multiple linear regression should be used depends on the feature selection.

5. Conclusions

In conclusion, a practicable approach for an automatic evaluation of the thermal images from neonatal piglets is presented. An R package has been developed and is available online. Integrated functions accumulate data from climate sensors with the original thermal images, while considering the specific emissivity values of the examined object’s surfaces and the distances of the camera to the object to generate precise thermal images. It uses a CDNN (YOLOv3-SPP) to automatically detect the regions of interest of a single top-view image of piglets and separates the regions from the background using the Otsu algorithm. Finally, regression features for multiple regressions are generated, and regressions for the body core temperature can be computed. The whole approach can be navigated and controlled with R, while object detection is performed by Python.

Author Contributions

Conceptualization, S.K. and I.T.; methodology, S.K., L.H. and M.S.; software, L.H.; validation, S.K. and L.H.; formal analysis, S.K., L.H., M.S. and I.T.; investigation, S.K. and L.H.; resources, M.S. and I.T.; data curation, S.K.; writing—original draft preparation, S.K.; writing—review and editing, S.K., L.H., M.S. and I.T.; visualization, S.K.; supervision, M.S. and I.T.; project administration, M.S. and I.T.; funding acquisition, I.T. All authors have read and agreed to the published version of the manuscript.

Funding

This research received no external funding.

Institutional Review Board Statement

The animal study protocol is in accordance with the German legal and ethical requirements of appropriate animal procedures; it achieved Ethical Clearance by the Institutional Animal Welfare Committee of the Georg-August University Göttingen (E9-19, 18.12.2019).

Data Availability Statement

A part of the dataset analyzed in this study as well as the R package “ThermalPigR” [24] are included in a GitHub repository. For more information, please contact the corresponding author.

Conflicts of Interest

The authors declare no conflict of interest.

Appendix A

Table A1. The best multiple linear regression model of all features including chest girth and body length on rectal temperature with six features plus intercept. R2 is the coefficient of determination, RMSE is the root mean square error, and AICc is a variation of the Akaike information criterion for small sample sizes.
Table A1. The best multiple linear regression model of all features including chest girth and body length on rectal temperature with six features plus intercept. R2 is the coefficient of determination, RMSE is the root mean square error, and AICc is a variation of the Akaike information criterion for small sample sizes.
Feature
Name
Coefficients
Intercept+187.26
Max_be−10.500
Max_be2+0.1575
Girth+0.1556
Length−0.0632
Max_head+1.0482
Q_head90−0.4490
R20.778
RMSE0.405
AICc431.1

References

  1. Traulsen, I.; Naunin, K.; Müller, K.; Krieter, J. Untersuchungen zum Einsatz der Infrarotthermographie zur Messung der Körpertemperatur bei Sauen. Züchtungskunde 2010, 82, 437–446. [Google Scholar]
  2. Feng, Y.Z.; Zhao, H.T.; Jia, G.F.; Ojukwu, C.; Tan, H.Q. Establishment of Validated Models for Non-Invasive Prediction of Rectal Temperature of Sows Using Infrared Thermography and Chemometrics. Int. J. Biometeorol. 2019, 63, 1405–1415. [Google Scholar] [CrossRef] [PubMed]
  3. Jia, G.; Li, W.; Meng, J.; Tan, H.; Feng, Y. Non-Contact Evaluation of a Pig’s Body Temperature Incorporating Environmental Factors. Sensors 2020, 20, 4282. [Google Scholar] [CrossRef] [PubMed]
  4. Jara, A.L.; Hanson, J.M.; Gabbard, J.D.; Johnson, S.K.; Register, E.T.; He, B.; Tompkins, S.M. Comparison of Microchip Transponder and Noncontact Infrared Thermometry with Rectal Thermometry in Domestic Swine (Sus Scrofa Domestica). J. Am. Assoc. Lab. Anim. Sci. 2016, 55, 588–593. [Google Scholar]
  5. Jorquera-Chavez, M.; Fuentes, S.; Dunshea, F.R.; Warner, R.D.; Poblete, T.; Morrison, R.S.; Jongman, E.C. Remotely Sensed Imagery for Early Detection of Respiratory Disease in Pigs: A Pilot Study. Animals 2020, 10, 451. [Google Scholar] [CrossRef] [Green Version]
  6. Loughmiller, J.A.; Spire, M.E.; Dritz, S.S.; Fenwick, B.W.; Hosni, M.H.; Hogge, S.B. Relationship between Mean Body Surface Temperature Measured by Use of Infrared Thermography and Ambient Temperature in Clinically Normal Pigs and Pigs Inoculated with Actinobacillus Pleuropneumoniae. Am. J. Vet. Res. 2001, 62, 676–681. [Google Scholar] [CrossRef]
  7. Chung, T.H.; Jung, W.S.; Nam, E.H.; Kim, J.H.; Park, S.H.; Hwang, C.Y. Comparison of Rectal and Infrared Thermometry for Obtaining Body Temperature of Gnotobiotic Piglets in Conventional Portable Germ Free Facility. Asian-Australas. J. Anim. Sci. 2010, 23, 1364–1368. [Google Scholar] [CrossRef]
  8. Kammersgaard, T.S.; Malmkvist, J.; Pedersen, L.J. Infrared Thermography—A Non-Invasive Tool to Evaluate Thermal Status of Neonatal Pigs Based on Surface Temperature. Animal 2013, 7, 2026–2034. [Google Scholar] [CrossRef] [Green Version]
  9. Xiong, Y.; Gates, R.S.; Cooper, N.C.; Ellis, M. Neonatal Piglet Core Body Temperature Model from Surface Temperature and Environment Measurements. Am. Soc. Agric. Biol. Eng. 2018. [Google Scholar] [CrossRef]
  10. Soerensen, D.D.; Pedersen, L.J. Infrared Skin Temperature Measurements for Monitoring Health in Pigs: A Review. Acta Vet. Scand. 2015, 57, 5. [Google Scholar] [CrossRef] [Green Version]
  11. Tattersall, G.J.; Milsom, W.K. Transient Peripheral Warming Accompanies the Hypoxic Metabolic Response in the Golden-Mantled Ground Squirrel. J. Exp. Biol. 2003, 206, 33–42. [Google Scholar] [CrossRef] [PubMed] [Green Version]
  12. Furniss, S.J. Measurements of Rectal Temperature to Predict “Mastitis, Metritis and Agalactia” (MMA) in Sows After Farrowing. Prev. Vet. Med. 1987, 5, 133–139. [Google Scholar] [CrossRef]
  13. Gulliksen, S.M.; Framstad, T.; Kielland, C.; Velazquez, M. Infrared Thermography is a Possible Technique for Estimation of Parturition Onset in Sows. Res. Sq. 2022, 1–21. [Google Scholar] [CrossRef] [PubMed]
  14. Savary, P.; Hauser, R.; Ossent, P.; Jungbluth, T.; Gygax, L.; Wechsler, B. Eignung der Thermographie zur Erfassung von Entzündungen an den Gliedmaßen von Mastschweinen. Dtsch. Tierarztl. Wochenschr. 2008, 115, 324–329. [Google Scholar] [CrossRef]
  15. Staveley, L.M.; Zemitis, J.E.; Plush, K.J.; D’Souza, D.N. Infrared Thermography for Early Identification and Treatment of Shoulder Sores to Improve Sow and Piglet Welfare. Animals 2022, 12, 3136. [Google Scholar] [CrossRef] [PubMed]
  16. Herpin, P.; Damon, M.; Le Dividich, J. Development of Thermoregulation and Neonatal Survival in Pigs. Livest. Prod. Sci. 2002, 78, 25–45. [Google Scholar] [CrossRef]
  17. Mount, L.E. The Metablic Rate of the New-born Pig in Relation to Environmental Temperature and to Age. J. Physiol. 1959, 147, 333–345. [Google Scholar] [CrossRef]
  18. Devillers, N.; Le Dividich, J.; Prunier, A. Influence of Colostrum Intake on Piglet Survival and Immunity. Animal 2011, 5, 1605–1612. [Google Scholar] [CrossRef] [Green Version]
  19. Pattison, R.J.; English, P.R.; MacPherson, O.; Roden, J.A.; Birnie, M. Hypothermia and Its Attempted Control in Newborn Piglets. Proc. Br. Soc. Anim. Prod. 1990, 1990, 81. [Google Scholar] [CrossRef]
  20. Baxter, E.M.; Edwards, S.A. Piglet Mortality and Morbidity: Inevitable or Unacceptable? In Advances in Pig Welfare; Woodhead Publishing: Duxford, UK, 2018; pp. 73–100. [Google Scholar] [CrossRef]
  21. Berthon, D.; Herpin, P.; Duchamp, C.; Dauncey, M.J.; Le Devidich, J. Modification of Thermogenic Capacity in Neonatal Pigs by Changes in Thyroid Status during Late Gestation—PubMed. J. Dev. Physiol. 1993, 19, 253–261. [Google Scholar]
  22. Herpin, P.; Le Dividich, J.; Berthon, D.; Hulin, J. Assessment of Thermoregulatory and Postprandial Thermogenesis over the First 24 Hours after Birth in Pigs. Exp. Physiol. 1994, 79, 1011–1019. [Google Scholar] [CrossRef] [PubMed]
  23. R Core Team. R: A Language and Environment for Statistical Computing; R Foundation for Statistical Computing: Vienna, Austria, 2022; Available online: https://www.r-project.org/ (accessed on 12 October 2022).
  24. Küster, S.; Haverkamp, L. GitHub—Kuesterst/ThermalPigR. Available online: https://github.com/kuesterst/ThermalPigR (accessed on 22 January 2023).
  25. Jocher, G. Yolov3/Yolov3-Spp.Cfg—Roboflow-Ai/Yolov3 GitHub. Available online: https://github.com/roboflow-ai/yolov3/blob/master/cfg/yolov3-spp.cfg (accessed on 12 October 2022).
  26. Otsu, N. Threshold Selection Method from Gray-Level Histograms. IEEE Trans. Syst. Man. Cybern. 1979, SMC-9, 62–66. [Google Scholar] [CrossRef] [Green Version]
  27. Anonymous. FLIROnePro User Manual. Available online: https://www.manualslib.com/manual/1978018/Flir-One-Series.html#manual (accessed on 8 November 2022).
  28. Anonymous. Veterinär-Thermometer SC 1080 (SC 12). Available online: https://shop.scala-electronic.de/produkt/veterinaer-thermometer-sc-1080/ (accessed on 8 November 2022).
  29. Anonymous. TGP-4500 Data-Logger. Available online: https://www.geminidataloggers.com/de/data-loggers/tinytag-plus-2/tgp-4500 (accessed on 8 November 2022).
  30. Minkina, W.; Dudzik, S. Infrared Thermography: Errors and Uncertainties; J. Wiley: Hoboken, NJ, USA, 2009; ISBN 978-0-470-68224-1. [Google Scholar]
  31. Soerensen, D.D.; Clausen, S.; Mercer, J.B.; Pedersen, L.J. Determining the Emissivity of Pig Skin for Accurate Infrared Thermography. Comput. Electron. Agric. 2014, 109, 52–58. [Google Scholar] [CrossRef]
  32. Anonymous. Roboflow Annotate. Available online: https://roboflow.com/annotate (accessed on 12 October 2022).
  33. Redmon, J. YOLOv3: An Incremental Improvement. arXiv 2018, arXiv:1804.02767. [Google Scholar] [CrossRef]
  34. He, K.; Zhang, X.; Ren, S.; Sun, J. Spatial Pyramid Pooling in Deep Convolutional Networks for Visual Recognition. IEEE Trans. Pattern Anal. Mach. Intell. 2015, 37, 1904–1916. [Google Scholar] [CrossRef] [PubMed] [Green Version]
  35. Lin, T.-Y.; Maire, M.; Belongie, S.; Bourdev, L.; Girshick, R.; Hays, J.; Perona, P.; Ramanan, D.; Zitnick, C.L.; Dolí, P. Microsoft COCO: Common Objects in Context. arXiv 2015, arXiv:1405.0312. [Google Scholar] [CrossRef]
  36. Bisong, E. Building Machine Learning and Deep Learning Models on Google Cloud Platform; Apress: Berkeley, CA, USA, 2019. [Google Scholar]
  37. Tattersall, G.J. Thermimage: Thermal Image Analysis. Available online: https://cran.r-project.org/web/packages/Thermimage/index.html (accessed on 10 October 2022).
  38. Hocking, R.R.; Leslie, R.N. Selection of the Best Subset in Regression Analysis. Technometrics 1967, 9, 531–540. [Google Scholar] [CrossRef]
  39. Deng, J.; Dong, W.; Socher, R.; Li, L.-J.; Li, K.; Fei-Fei, L. ImageNet: A Large-Scale Hierarchical Image Database. In Proceedings of the 2009 IEEE Conference on Computer Vision and Pattern Recognition, Miami, FL, USA, 20–25 June 2009; pp. 248–255. [Google Scholar] [CrossRef] [Green Version]
  40. Diel, B.; Oster, M.; Vernunft, A.; Wimmers, K.; Bostedt, H. Intrinsic challenges of neonatal adaptation in swine. Arch. Anim. Breed. 2022, 65, 427–438. [Google Scholar] [CrossRef]
  41. Tabuaciri, P.; Bunter, K.L.; Graser, H.-U. Thermal Imaging as a Potential Tool for Identifying Piglets at Risk. AGBU Pig Genet. Work. 2012, 23–30. [Google Scholar]
  42. Sasaki, Y.; Furusho, K.; Ushijima, R.; Tokunaga, T.; Uemura, R.; Sueyoshi, M. Body Surface Temperature of Suckling Piglets Measured by Infrared Thermography and Its Association with Body Weight Change. Japan Agric. Res. Q. 2016, 50, 361–368. [Google Scholar] [CrossRef] [Green Version]
  43. Kollis, K.; Phang, C.S.; Banhazi, T.M.; Searle, S.J. Weight Estimation Using Image Analysis and Statistical Modelling: A Preliminary Study. Appl. Eng. Agric. 2007, 23, 91–96. [Google Scholar] [CrossRef]
  44. Lossec, G.; Herpin, P.; Le Dividich, J. Thermoregulatory Responses of the Newborn Pig during Experimentally Induced Hypothermia and Rewarming. Exp. Physiol. 1998, 83, 667–678. [Google Scholar] [CrossRef] [PubMed]
Figure 1. (a) Setup of thermal imaging, animal’s individual top-view thermal images were recorded in a standardized distance, and (b) manual measurement of body length (A to B) and chest girth (C). (c) Example of a thermal image, where dark-blue/purple indicates low temperature and yellow/white indicates high temperature.
Figure 1. (a) Setup of thermal imaging, animal’s individual top-view thermal images were recorded in a standardized distance, and (b) manual measurement of body length (A to B) and chest girth (C). (c) Example of a thermal image, where dark-blue/purple indicates low temperature and yellow/white indicates high temperature.
Agriculture 13 00812 g001
Figure 2. Example Otsu algorithm for the head of a piglet: (a) shows the four bounding box detections of YOLOv3-SPP; (b) is an image of the area “piglet” after gray value conversion (0–255); (c) shows a binary image of the piglet, after thresholding with Otsu algorithm on image (b). Image (d) shows the overlap of the white foreground area (c) and the detected “head bounding box area” from (a). The pixels inside the red area are used for further calculations of the head.
Figure 2. Example Otsu algorithm for the head of a piglet: (a) shows the four bounding box detections of YOLOv3-SPP; (b) is an image of the area “piglet” after gray value conversion (0–255); (c) shows a binary image of the piglet, after thresholding with Otsu algorithm on image (b). Image (d) shows the overlap of the white foreground area (c) and the detected “head bounding box area” from (a). The pixels inside the red area are used for further calculations of the head.
Agriculture 13 00812 g002
Figure 3. Workflow chart of the R package “ThermalPigR”. On the left is the original data from data acquisition. In the middle, the computation is performed by R and Python (object detection). After feature calculation the rectal temperature of the piglets is estimated (right site).
Figure 3. Workflow chart of the R package “ThermalPigR”. On the left is the original data from data acquisition. In the middle, the computation is performed by R and Python (object detection). After feature calculation the rectal temperature of the piglets is estimated (right site).
Agriculture 13 00812 g003
Figure 4. Pearson correlations of the rectal temperature (Rkt) and the body parts (mean and max) (upper right), and a histogram (diagonal) and scatterplot (bottom left) of the body parts. All captions are in °C.
Figure 4. Pearson correlations of the rectal temperature (Rkt) and the body parts (mean and max) (upper right), and a histogram (diagonal) and scatterplot (bottom left) of the body parts. All captions are in °C.
Agriculture 13 00812 g004
Figure 5. Outlier detection: blue cross indicates a rectal temperature <34 °C and red triangles indicate 10% of the biggest differences between rectal temperature and max surface temperature of the piglet’s head.
Figure 5. Outlier detection: blue cross indicates a rectal temperature <34 °C and red triangles indicate 10% of the biggest differences between rectal temperature and max surface temperature of the piglet’s head.
Agriculture 13 00812 g005
Figure 6. Progress of the fine-tuning process of the YOLOv3-SPP model on the training set (n = 316) for 300 epochs. The evaluation of the metrics precision, recall, and mAP is performed on the validation set (32 images).
Figure 6. Progress of the fine-tuning process of the YOLOv3-SPP model on the training set (n = 316) for 300 epochs. The evaluation of the metrics precision, recall, and mAP is performed on the validation set (32 images).
Agriculture 13 00812 g006
Figure 7. Results of the best multiple linear model (8 features) on all data. The blue lines highlight a deviation of ± 0.5 °C from the measured rectal temperature.
Figure 7. Results of the best multiple linear model (8 features) on all data. The blue lines highlight a deviation of ± 0.5 °C from the measured rectal temperature.
Agriculture 13 00812 g007
Table 1. Description and example images of body part annotation using bounding boxes with Roboflow annotation tool [32].
Table 1. Description and example images of body part annotation using bounding boxes with Roboflow annotation tool [32].
AnnotationDescriptionExamples
PigletA rectangle bounding box fitting the whole piglet with legs, snout, and tail inside.Agriculture 13 00812 i001
HeadA rectangle bounding box fitting the piglet’s head. The ears and snout are inside the box if visible and the shoulders are building the border to the back. Agriculture 13 00812 i002
BackA rectangle bounding box fitting the piglet’s back. The shoulders and the hips are building the borders for the box.Agriculture 13 00812 i003
Back endA rectangle bounding box fitting the piglet’s back end. The hips and the tail are inside the box if visible.Agriculture 13 00812 i004
Table 2. Indexing of features. Where mb = max back, mbe = max back end, mh = max head, mp = max piglet, ab =average/mean back, abe = average/mean back end, ah = average/mean head, and ap = average/mean piglet.
Table 2. Indexing of features. Where mb = max back, mbe = max back end, mh = max head, mp = max piglet, ab =average/mean back, abe = average/mean back end, ah = average/mean head, and ap = average/mean piglet.
NrEnvironment, Max, Median, and Mean
(n = 14)
Nr99th, 95th, 90th Quantile
(n = 12)
NrAbsolute Temps.
(n = 14)
NrAbsolute Temps.
(n = 14)
NrQuadratic Temps.
(n = 8)
1Temperature15Q_back9927mb_mbe41mh_ab55Max_head2
2Air Humidity16Q_be9928mb_mh42mh_abe56Max_back2
3Max_back17Q_head9929mb_mp43mh_ah57Max_be2
4Max_be18Q_pig9930mb_ab44mh_ap58Max_pig2
5Max_head19Q_back9531mb_abe45mp_ab59Mean_head2
6Max_pig20Q_be9532mb_ah46mp_abe60Mean_back2
7Median_back21Q_head9533mb_ap47mp_ah61Mean_be2
8Median_be22Q_pig9534mbe_mh48mp_ap62Mean_pig2
9Median_head23Q_back9035mbe_mp49ab_abe
10Median_pig24Q_be9036mbe_ab50ab_ah
11Mean_back25Q_head9037mbe_abe51ab_ap
12Mean be26Q_pig9038mbe_ah52abe_ah
13Mean_head 39mbe_ap53abe_ap
14Mean_pig 40mh_mp54ah_ap
Table 3. Results of simple linear regression of the max values of body features on rectal temperature. R2 is the coefficient of determination, RMSE is the root mean square error, and AICc is a variation of the Akaike information criterion for small sample sizes. y represents the rectal temperature and x the max value of the feature.
Table 3. Results of simple linear regression of the max values of body features on rectal temperature. R2 is the coefficient of determination, RMSE is the root mean square error, and AICc is a variation of the Akaike information criterion for small sample sizes. y represents the rectal temperature and x the max value of the feature.
MAX
Feature
EquationR2RMSEAICc
heady = +8.696 + 0.7982x0.6510.507480.5
piglety = +9.225 + 0.7796x0.6340.520487.1
backy = +12.97 + 0.6817x0.5220.593522.7
back endy = +14.4 + 0.6337x0.4960.610530
Table 4. The best multiple linear regression models of all features (62) on rectal temperature with varying numbers of features (1–8) plus intercept. R2 is the coefficient of determination, RMSE is the root mean square error, and AICc is a variation of the Akaike information criterion for small sample sizes.
Table 4. The best multiple linear regression models of all features (62) on rectal temperature with varying numbers of features (1–8) plus intercept. R2 is the coefficient of determination, RMSE is the root mean square error, and AICc is a variation of the Akaike information criterion for small sample sizes.
Feature
Names
1
Feature
2
Features
3
Features
4
Features
5
Features
6
Features
7
Features
8
Features
Intercept+8.696+7.703+116.2+183.2+206.2+193+203.2+201.3
Max_head+0.7982+1.406−4.936+1.237 +0.9523+1.122+0.9705
Q_head90 −0.5901−0.5685−0.5952 −0.3876
Max_head2 +0.09198
Max_be −10.21−12.09−10.72−11.99−11.96
Max_be2 +0.1536+0.1733+0.1627+0.1718+0.171
Max_pig +1.195
Air Humidity −0.00976−0.00843 *−0.00846 *−0.00712 *
T_mb_mbe −0.7739 −0.6724−0.7446
T_mb_mh +0.4404
Q_pig99 +1.169+1.291
Q_head95 −1.064−0.9839
T_mp_ab +0.1257
R20.6510.6870.7000.7290.7500.7590.7700.774
RMSE0.5070.4800.4700.4470.4300.4210.4120.406
AICc480.5468.2464.7453.2444.9441.8438.1436.7
* Rounded to the 5th decimal place.
Disclaimer/Publisher’s Note: The statements, opinions and data contained in all publications are solely those of the individual author(s) and contributor(s) and not of MDPI and/or the editor(s). MDPI and/or the editor(s) disclaim responsibility for any injury to people or property resulting from any ideas, methods, instructions or products referred to in the content.

Share and Cite

MDPI and ACS Style

Küster, S.; Haverkamp, L.; Schlather, M.; Traulsen, I. An Approach towards a Practicable Assessment of Neonatal Piglet Body Core Temperature Using Automatic Object Detection Based on Thermal Images. Agriculture 2023, 13, 812. https://doi.org/10.3390/agriculture13040812

AMA Style

Küster S, Haverkamp L, Schlather M, Traulsen I. An Approach towards a Practicable Assessment of Neonatal Piglet Body Core Temperature Using Automatic Object Detection Based on Thermal Images. Agriculture. 2023; 13(4):812. https://doi.org/10.3390/agriculture13040812

Chicago/Turabian Style

Küster, Steffen, Lion Haverkamp, Martin Schlather, and Imke Traulsen. 2023. "An Approach towards a Practicable Assessment of Neonatal Piglet Body Core Temperature Using Automatic Object Detection Based on Thermal Images" Agriculture 13, no. 4: 812. https://doi.org/10.3390/agriculture13040812

Note that from the first issue of 2016, this journal uses article numbers instead of page numbers. See further details here.

Article Metrics

Back to TopTop