Infrared Thermography and Machine Learning for Mastitis Detection in Dairy Cows: A Pilot Case Study in Egyptian Farms

Mastitis is a major and costly dairy disease that reduces milk yield and quality and harms animal welfare. This study evaluated infrared thermography (IRT) combined with machine learning (ML) for non-invasive mastitis screening in dairy cows and explored links with biological and feeding-system variables in Egyptian farms. A total of 976 thermal udder images obtained from 488 Holstein cows were used, including 708 healthy and 268 mastitic images. Images were captured before milking, processed with CLAHE, resized to 224 × 224 pixels, and split using cow-level grouping before augmentation to prevent animal-level data leakage. The training set contained 780 original images and was augmented to a balanced 4708-image set (2354 per class), while the held-out test set remained unaugmented, with 196 original images (142 healthy and 54 mastitic). EfficientNetB3 with global average and max pooling extracted 3072 thermal features, and ten ML classifiers were evaluated. In the image-level hold-out evaluation, MLP achieved the best performance (accuracy = 86.22%, AUC = 0.9184, sensitivity = 74.07%, specificity = 90.85%), followed by SVM (accuracy = 83.67%, AUC = 0.8963). A separate group-based five-fold cross-validation yielded a more conservative AUC of 0.6812 ± 0.1323 and accuracy of 0.6244 ± 0.0642. Logistic regression analyses did not identify statistically significant associations between model predictions and somatic cell count (SCC), California Mastitis Test (CMT), blood biomarkers, or nutritional variables at p < 0.05. Ration A (Delta Misr) showed a higher observed mastitis incidence (20/40; 50.0%) than Ration B (Copenhagen; 16/45; 35.6%), but nutritional predictors were not statistically significant, indicating that farm-level confounding should be considered. Overall, IRT with ML remains a promising non-invasive screening approach, but broader multicenter datasets and independent external validation are needed before routine farm deployment.

Authors

Institutions

Publication Details

Journal
Veterinary Sciences
Published
2026-06-30
DOI
https://doi.org/10.3390/vetsci13070640
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
OCT
article

Infrared Thermography and Machine Learning for Mastitis Detection in Dairy Cows: A Pilot Case Study in Egyptian Farms

Sobhy M. A. Sallam, Elsayed Metwalli Badr, A ElMasry, Allam Af et al.
Veterinary Sciences
Effects of Environmental Stressors on Livestock
article

Infrared Thermography and Machine Learning for Mastitis Detection in Dairy Cows: A Pilot Case Study in Egyptian Farms

Sobhy M. A. Sallam, Elsayed Metwalli Badr, A ElMasry, Allam Af, Eman A. Elwakeel, Marwa F. A. Attia, Alaa. T. Elmaria
article en

Abstract

Mastitis is a major and costly dairy disease that reduces milk yield and quality and harms animal welfare. This study evaluated infrared thermography (IRT) combined with machine learning (ML) for non-invasive mastitis screening in dairy cows and explored links with biological and feeding-system variables in Egyptian farms. A total of 976 thermal udder images obtained from 488 Holstein cows were used, including 708 healthy and 268 mastitic images. Images were captured before milking, processed with CLAHE, resized to 224 × 224 pixels, and split using cow-level grouping before augmentation to prevent animal-level data leakage. The training set contained 780 original images and was augmented to a balanced 4708-image set (2354 per class), while the held-out test set remained unaugmented, with 196 original images (142 healthy and 54 mastitic). EfficientNetB3 with global average and max pooling extracted 3072 thermal features, and ten ML classifiers were evaluated. In the image-level hold-out evaluation, MLP achieved the best performance (accuracy = 86.22%, AUC = 0.9184, sensitivity = 74.07%, specificity = 90.85%), followed by SVM (accuracy = 83.67%, AUC = 0.8963). A separate group-based five-fold cross-validation yielded a more conservative AUC of 0.6812 ± 0.1323 and accuracy of 0.6244 ± 0.0642. Logistic regression analyses did not identify statistically significant associations between model predictions and somatic cell count (SCC), California Mastitis Test (CMT), blood biomarkers, or nutritional variables at p < 0.05. Ration A (Delta Misr) showed a higher observed mastitis incidence (20/40; 50.0%) than Ration B (Copenhagen; 16/45; 35.6%), but nutritional predictors were not statistically significant, indicating that farm-level confounding should be considered. Overall, IRT with ML remains a promising non-invasive screening approach, but broader multicenter datasets and independent external validation are needed before routine farm deployment.

Veterinary SciencesVol. 13(7)
Qassim University (SA), Mansoura University (EG), Benha University (EG), Buraydah Colleges (SA), Agricultural Research Center (EG), Alexandria University (EG)
Zero hunger
Openalex Percentile: Top 10%
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.