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

Institutions

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
Controls
|||
ALL TIME
JAN
FEB
MAR
APR
MAY
JUN
JUL
AUG
SEP
article

Mastitis detection in dairy cows with varying postures using infrared thermography based on YOLOv8n-improved and random forest models

Longwei Guo, Qiuju Xie, Hang Song, Jun Hu et al.
Computers and Electronics in Agriculture
Effects of Environmental Stressors on Livestock
article

Mastitis detection in dairy cows with varying postures using infrared thermography based on YOLOv8n-improved and random forest models

Longwei Guo, Qiuju Xie, Hang Song, Jun Hu, Huize Lv, Hang Xue, Miao Wu, Hang Shi, Hui Zhang
article en

Abstract

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.

Computers and Electronics in AgricultureVol. 256
Northeast Agricultural University (CN), Heilongjiang Bayi Agricultural University (CN)
Life in Land
Openalex Percentile: Top 14%
Effects of Environmental Stressors on Livestock
AI Navigator

Ask Laika to Summarize, Analyze, and Connect papers live on the map.

Summarize Papers & Methodologies

Extract key findings, datasets, and comparative methods across publications.

Benchmark Rankings & Visual Analytics

Rank top research institutions, authors, funders, topics, and journals by Field-Weighted Citation Impact (FWCI) and paper volume with instant charts.

Connect Distant Disciplines

Bridge topological clusters on the map to find hidden collaborative intersections.