Mastitis detection in dairy cows with varying postures using infrared thermography based on YOLOv8n-improved and random forest models
Current automated mastitis detection methods typically identify dairy cows only in a fixed standing posture, which limits their scope and practical flexibility. To address potential occlusion issues across different postures, we divided the key anatomical regions into three areas (the eye, the back surface of the udder (BSU) and the lower surface of the udder (LSU)) and developed an infrared thermography (IRT)-based automated diagnostic system for cows in various postures within a lactation barn. First, a three-stage image enhancement method was applied to extract contour and texture features from the IRT images. Next, the You Only Look Once v8 Nano (YOLOv8n) model was improved by integrating Dynamic Snake Convolution to better capture subtle and complex texture patterns. We further optimised the weight distribution of contour and texture features using an efficient multi-scale attention module to reduce the loss of critical information in the deep network. Structural improvements included adding a P2 detection head to focus on contour features in the target regions. Finally, we built three machine learning models to diagnose mastitis using the maximum body temperatures of these critical regions. Results showed that the three-stage image enhancement effectively enriched IRT details, strengthened contour and texture features and improved detection confidence for the eye, BSU and LSU by 0.025, 0.05 and 0.04, respectively. The improved YOLOv8n model achieved top performance, with precision (P) of 94.2%, 97.8% and 96.1%; recall (R) of 96.6%, 94.1% and 89.7%; and average precision at an intersection-over-union of 50% ([email protected]) of 94.3%, 93.7% and 94.2% for the eye, BSU and LSU, respectively. Compared with the baseline YOLOv8n model, the enhanced version improved P, R and [email protected] metrics by 2%∼5.4% across the three regions of interest. Among the diagnostic models, random forest achieved the highest accuracy at 92.31%. This method broadens the application of automated mastitis detection and provides a reference framework for building automatic monitoring systems for mastitis in feeder barns.
Authors
- Longwei Guo
- Qiuju Xie
- Hang Song (ORCID: https://orcid.org/0009-0008-7352-0855)
- Jun Hu (ORCID: https://orcid.org/0009-0003-2743-0641)
- Huize Lv
- Hang Xue (ORCID: https://orcid.org/0009-0008-4953-8748)
- Miao Wu
- Hang Shi
- Hui Zhang
Institutions
- Northeast Agricultural University (CN)
- Heilongjiang Bayi Agricultural University (CN)
Publication Details
- Journal
- Computers and Electronics in Agriculture
- Published
- 2026-09-15
- DOI
- https://doi.org/10.1016/j.compag.2026.112430
- Primary Topic
- Effects of Environmental Stressors on Livestock
- Type
- article
- Field-Weighted Citation Impact
- 0.00