Sow backfat thickness estimation method and system based on deep learning and image processing
By using deep learning and image processing technologies, a backfat thickness estimation system for sows was constructed, which solved the problems of high labor intensity and low efficiency in measuring backfat thickness in sows. It achieved automatic, real-time, and accurate backfat thickness estimation, reduced stress response in sows, and improved production efficiency.
Patent Information
- Application Number
- CN202511719790.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-11-21
- Publication Date
- 2026-02-17
AI Technical Summary
Existing methods for measuring backfat thickness in sows are labor-intensive, inefficient, and difficult to automate and dynamically monitor, thus affecting production efficiency. Furthermore, traditional methods are prone to causing stress reactions in sows.
A deep learning and image processing-based method was used to construct a sow rump depth image acquisition system. Through a lightweight improved target detection network and image processing technology, the ROI region of the sow rump was automatically extracted. The correlation between backfat thickness and external morphological parameters of the rump was analyzed, a sow backfat thickness estimation model was constructed, and an estimation system based on PyQt5 was developed.
It enables non-contact, automatic, real-time, and accurate estimation of backfat thickness in sows, reducing labor costs, minimizing stress in sows, improving measurement efficiency and accuracy, and supporting real-time tracking of backfat thickness changes, thus providing support for breeding management.
Smart Images

Figure CN121545006A_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the field of sow reproductive performance evaluation, specifically relating to a method and system for estimating backfat thickness in sows based on deep learning and image processing. Background Technology
[0002] The reproductive performance and lifespan of sows are important indicators of the economic benefits of sow production. Backfat, a layer of adipose tissue located under the skin on the back of the sow, provides energy for its daily activities and secretes a large number of active substances, and is significantly related to its health and reproductive performance.
[0003] A suitable backfat thickness range plays a positive role in the reproductive stages of sows, including estrus, conception, pregnancy, and lactation. For multiparous sows, maintaining appropriate backfat thickness at different reproductive stages ensures normal secretion of reproductive hormones, maintains good reproductive function, and thus achieves sustained and stable reproductive performance. If sows maintain a certain backfat thickness after weaning, they can return to estrus more quickly, shorten the weaning-to-estrus interval, and improve reproductive efficiency. Therefore, dynamic monitoring of sow backfat thickness is crucial for improving sow reproductive performance and pig productivity.
[0004] Currently, backfat thickness in sows is mainly measured using three methods: visual pressure measurement, ultrasonic measurement, and CT scanning. These methods are labor-intensive, inefficient, and lack accuracy, failing to meet the needs of automated and dynamic monitoring of backfat thickness in pregnant sows, thus impacting production efficiency. Therefore, this study proposes a method and system for estimating backfat thickness in sows based on deep learning and image processing. This method eliminates the need for direct contact with the pig, avoiding stress and injury, and minimizing human interference. It has significant practical implications for large-scale sow farming management, precise nutritional control, and fattening strategy development. Summary of the Invention
[0005] To address the shortcomings of existing technologies, this invention provides a method and system for estimating backfat thickness in sows based on deep learning and image processing, so as to at least partially solve the above-mentioned problems.
[0006] To achieve the above objectives, this invention provides a method and system for estimating backfat thickness in sows based on deep learning and image processing, comprising:
[0007] S1. Construct a sow rump depth image acquisition system and acquire sow rump depth images and backfat thickness data;
[0008] S2. After preprocessing the acquired depth image, a lightweight improved object detection network is used for training and testing to extract the ROI region of the sow's rump image. Based on this recognition, image processing methods are used to extract the external morphological parameters of the sow's rump.
[0009] S3. Analyze the correlation between backfat thickness and external morphological parameters of the rump, and construct a backfat thickness estimation model for sows based on the selected rump feature parameters. At the same time, a backfat thickness estimation system for sows was constructed based on the PyQt5 development tool.
[0010] This invention discloses a method and system for estimating backfat thickness in sows based on deep learning and image processing. The entire estimation process can be automated without human intervention, and the estimation speed can meet real-time requirements while the estimation accuracy can meet production requirements.
[0011] The beneficial effects of this invention are as follows:
[0012] 1. This invention features an automatic estimation system that integrates deep learning and image processing technologies to achieve non-contact, automatic, real-time, and accurate estimation of backfat thickness in sows. This system enables rapid batch measurement of sows, significantly reducing labor costs and stress responses in sows. By periodically collecting images of sow rump depth, it can also track changes in backfat thickness in real time, providing support for timely adjustments to feeding programs.
[0013] 2. This invention addresses the problems of traditional contact ultrasound measurement of sow backfat thickness, which relies on manual operation, easily causes stress to sows, and is inefficient, as well as the problem of insufficient estimation accuracy caused by inaccurate feature extraction in non-contact models. It proposes an integrated solution of deep image fusion, deep learning, and image processing, which provides a new paradigm for non-contact measurement of breeding parameters by integrating animal phenotype and machine vision. Compared with traditional RGB visual images, which can only capture two-dimensional texture information and are easily affected by lighting, depth images can directly reflect three-dimensional structure and better match the intrinsic relationship between sow rump shape and backfat thickness. Attached Figure Description
[0014] To more clearly illustrate the technical solutions in this invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are some embodiments of this invention. For those skilled in the art, other drawings can be obtained from these drawings without creative effort.
[0015] Figure 1 This is a schematic diagram of the method and system flow for estimating backfat thickness in sows according to the present invention;
[0016] Figure 2 This is a diagram of the sow rump depth image acquisition system of the present invention;
[0017] Figure 3 This is a color depth map of the sow's rump according to the present invention;
[0018] Figure 4 This is a diagram of the lightweight improved YOLOv8n-ShuffleNetV2 structure of the present invention;
[0019] Figure 5 This is a flowchart of the ROI region image processing of the present invention;
[0020] Figure 6 This is a diagram of the sow backfat thickness estimation system of the present invention. Detailed Implementation
[0021] To make the objectives, technical solutions, and advantages of this invention clearer, the technical solutions of this invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some, not all, of the embodiments of this invention. All other embodiments obtained by those skilled in the art based on the embodiments of this invention without creative effort are within the scope of protection of this invention.
[0022] This invention can be widely applied to backfat estimation in sows at different growth stages, such as the backfat fattening period, gestation period, lactation period, and non-pregnant period. Furthermore, this invention can also be adapted to other breeds of sows requiring backfat thickness estimation, or applied to other fields through knowledge transfer.
[0023] The present invention will be further described in detail below with reference to the accompanying drawings and specific embodiments:
[0024] Figure 1 This is a schematic diagram of the method and system flow for estimating backfat thickness in sows provided by the present invention, as shown below. Figure 1 As shown, this embodiment of the invention provides a method and system for estimating backfat thickness in sows based on deep learning and image processing, including:
[0025] Step S101: Construct a sow rump depth image acquisition system.
[0026] Specifically, the system includes an Azure Kinect DK depth camera, a USB cable, an adjustable stand, and a laptop computer. It also features a sow rump depth image acquisition system developed using the PyQt5 development tool.
[0027] Specifically, Figure 2 A diagram of a sow rump depth image acquisition system, such as... Figure 2As shown, this acquisition program is used to acquire depth images and RGB images of the sow's rump. Clicking the "Run" button on the program interface acquires the sow's rump depth image; clicking the "Stop" button terminates the program after image acquisition is complete.
[0028] Step S102: Obtain the depth image of the sow's rump and the backfat thickness data.
[0029] Specifically, the sow rump depth image was acquired by the constructed sow rump depth image acquisition system, and the backfat thickness parameter was measured using an ultrasonic backfat meter (Pig Doctor). The measurement point was the internationally recognized P2 point in the pig industry. During the image acquisition process, the depth camera was placed at a height of 100 cm above the ground, parallel to the pig pen behind the pig, to prevent the rear fence from obstructing the imaging process.
[0030] Step S103: Preprocess the acquired depth image.
[0031] Specifically, Figure 3 A color depth map of the sow's rump, such as... Figure 3 As shown, considering the pig's body length and position in the image, depth value filtering is applied to the original image. A minimum effective depth value of 300 mm and a maximum effective depth value of 1400 mm are set, retaining pixels within this range and setting the values of pixels outside this range to 0. Subsequently, the filtered image is normalized and colorized to unify the depth value range and eliminate differences introduced by the filtering.
[0032] Step S103: Train and test a lightweight improved object detection network to extract the ROI region from the sow's rump image.
[0033] It should be noted that, to ensure data diversity and avoid overfitting of the recognition model, data augmentation methods such as flipping, mirroring, and adding Gaussian noise were used to expand the 2640 colorized depth images to 13200 images. Simultaneously, the sow's rump was manually annotated in the images using the Labelimg professional annotation tool, with the annotation category set to "buttocks". The dataset was then randomly divided into test, training, and validation sets in a 1:8:1 ratio.
[0034] Specifically, Figure 4 A lightweight improvement to the YOLOv8n-ShuffleNetV2 architecture diagram, as shown below. Figure 4 As shown, the ShuffleNetV2 network is introduced to reconstruct the backbone network of YOLOv8, making the model lightweight. By reducing the model size, the maximum improvement in accuracy and efficiency is achieved.
[0035] Specifically, the trainable parameters, model size, training time, and mAP50-95 of each model are shown in Table 1. The results show that the YOLOv8n model reconstructed using the lightweight ShuffleNetV2 achieves a good balance among multiple metrics. This model has only 2.79MB of parameters and a model size of 5.6MB, significantly lower than YOLOv8s, YOLOv8m, and YOLOv8l models, and also better than the benchmark YOLOv8n. In terms of detection accuracy, its mAP50-95 reaches 0.942, basically on par with the best-performing YOLOv8m, and higher than YOLOv8n and YOLOv8l. This indicates that the lightweight design did not sacrifice recognition accuracy; instead, it maintained strong feature extraction capabilities through efficient feature interaction and channel shuffle mechanisms. The training time is only 5.8 hours, demonstrating good training efficiency.
[0036] Model Training parameters Model size (MB) Training time (h) MAP50-95 Yolov8n 3005843 6.3 4.5 0.939 Yolov8s 11125971 22.5 6.5 0.941 Yolov8m 25840339 52.1 15.8 0.942 Yolov8l 43630611 87.5 30.6 0.936 Yolov8n+ShuffleNetV2 2790247 5.6 5.8 0.942
[0037] Table 1 Performance Comparison of Different Models
[0038] Step S104: Based on this recognition, image processing methods are used to extract the external morphological parameters of the sow's rump.
[0039] Specifically, Figure 5 A flowchart of the ROI region image processing, such as Figure 5 As shown, morphological operations such as mean filtering, binarization, and opening are performed on the obtained ROI image. A leg region removal algorithm is introduced to extract the center point of the processed sow rump binarized image. Ellipse fitting and circle fitting are completed by combining the edge pixels of the sow rump to extract external morphological parameters.
[0040] It should be noted that different standing postures of sows can lead to differences in the size and shape of the leg images. Furthermore, the slatted floor of the pigsty connects to the leg imaging area, further interfering with the extraction of the sow's true rump contour. To eliminate this interference, a leg region removal algorithm is introduced: horizontal lines are drawn sequentially from the top of the sow's contour image downwards. The number of intersections between each horizontal line and the sow's contour area is calculated. The first horizontal line with more than 4 intersections is selected, and the area below this line is determined as the leg region, retaining only the area above it.
[0041] It should be noted that due to variations in sow body length and different standing positions during feeding, the distance between the sow's rump and the depth camera fluctuates during image acquisition. This distance variation leads to distortion of the sow's image outline size, thus affecting the extraction of the sow's external morphological parameters. To eliminate this effect, this study extracted the depth distance (i.e., the distance from the rump to the depth camera) of all sow rump ROIs and selected 1000 mm as a unified reference depth distance. The actual length and area calculation formulas are shown in equations (1) - (3) below:
[0042]
[0043]
[0044]
[0045] In the formula, D S D is the sampling depth. R The reference depth distance is 1000 mm; K is the depth scaling factor; and L is the conversion length. P A is the pixel length; A is the transformed area. P The pixel area.
[0046] Step S105: Analyze the correlation between backfat thickness and external morphological parameters of the buttocks.
[0047] It should be noted that this study extracted a total of 11 external morphological parameters, including the pixel area of the buttocks (AB), the pixel area of the fitted ellipse (AFE), the pixel area of the minimum bounding rectangle (AR), the pixel length of the buttock contour perimeter (EB), the pixel length of the major axis of the fitted ellipse (MIE), the pixel length of the minor axis of the fitted ellipse (MAE), the pixel length of the radius of the fitted circle (RC), the pixel width of the buttocks (HB), the pixel height of the buttocks (HH), the roundness (CB), and the ellipticity (OB).
[0048] Specifically, backfat thickness showed the highest correlation with parameters reflecting rump area, followed by parameters reflecting rump length, while the correlation with other parameters was significantly lower. Correlation analysis revealed that ellipticity and roundness had weak correlations with backfat thickness; therefore, they were excluded to avoid negatively impacting the backfat thickness estimation model for sows.
[0049] Specifically, a multicollinearity (VIF) test was performed on the remaining nine external morphological parameters. The results showed that the VIF values of each variable were much greater than 10, indicating that the model was significantly affected by the collinearity problem. Therefore, principal component analysis (PCA) was used to reduce the dimensionality of the above nine parameters to two principal components (see Table 2), which can effectively avoid the collinearity problem.
[0050] Table 2 Principal Component Load Matrix
[0051] index <![CDATA[F1]]> <![CDATA[F2]]> AB 0.3843 -0.0142 AFE 0.3842 -0.0390 AR 0.3821 -0.0451 HB 0.3165 0.6515 HH 0.3325 -0.3498 EB 0.3711 -0.0609 MIE 0.2962 0.4347 MAE 0.3398 -0.3373 RC 0.3214 0.3781
[0052] It should be noted that the cumulative contribution rate of the two principal components reached 92.74%, with principal component 1 (F1) having the highest contribution rate at 74.50%. This indicates that F1 has the greatest impact on the backfat thickness of sows and is a comprehensive principal component. Furthermore, the correlation analysis results show that all nine external parameters are significantly positively correlated with backfat thickness; therefore, F1 is named the area factor. The parameters of principal component 2 (F2) are related to the length attribute, and its absolute load value is significantly higher than other indicators; therefore, F2 is named the length factor. The calculation formulas for F1 and F2 are shown in equations (4)-(5).
[0053]
[0054]
[0055] Step S106: Construct a backfat thickness estimation model for sows using the selected rump feature parameters.
[0056] It should be noted that this paper uses a random sampling strategy to divide the dataset into a training set (152 heads) and a test set (102 heads), and the statistical values are shown in Table 3.
[0057] Table 3. Statistical characteristics of back fat thickness during training and testing (mm)
[0058] Dataset Sample size Maximum value Minimum value average value Standard deviation training set 152 29 6 17.13 5.59 test set 102 29 6 17.01 5.66
[0059] It should be noted that this study uses the area factor and length factor as the two principal component factors as input factors for the machine learning model. In the parameter optimization stage, a Bayesian optimization algorithm is employed to systematically traverse preset parameter combinations to find the optimal parameters. The coefficient of determination (R²) is used as the performance evaluation criterion to evaluate each predefined parameter combination, thereby selecting the optimal parameters for each model. The optimized parameters of the elastic network regression model are shown in Table 4; all other parameters use default settings.
[0060] Table 4. Parameter selection for the elastic network regression model after optimization based on Bayesian algorithm.
[0061] Machine Model parameter EN Alpha=0.157, l1_ratio=0.1, Max_iter=2000
[0062] Specifically, the elastic network regression showed the best predictive ability, with a determination coefficient (R²) as high as 0.8356, and mean squared error (MSE) and mean absolute error (MAE) of 5.2126 mm² and 1.8102 mm, respectively, achieving the best results in all indicators in the test set. A backfat thickness estimation model for sows was constructed based on F1 and F2, as shown in formula (6):
[0063]
[0064] Step S107: A backfat thickness estimation system for sows was built using the PyQt5 development tool.
[0065] Specifically, Figure 6 A diagram illustrating the backfat thickness estimation system for sows, such as... Figure 6 As shown, after inputting an image of a sow's rump, the system can automatically perform a series of steps, including preprocessing, target detection, image processing, and extraction of external feature parameters, to achieve real-time estimation of the sow's backfat thickness. This system can be integrated into inspection robots used in pig farms to realize real-time acquisition of sow backfat thickness. It eliminates the need for direct contact with the pig, avoiding stress and injury, and allows for the measurement of backfat thickness in a large number of sows in a short time, improving detection efficiency. It also reduces human interference, improving the accuracy and reliability of measurement results, and providing strong support for precision management in the pig industry.
Claims
1. A method and system for estimating backfat thickness in sows based on deep learning and image processing, characterized in that, Includes the following steps: S1. Construct a sow rump depth image acquisition system and obtain sow rump depth images and backfat thickness data. S2. After preprocessing the acquired depth image, a lightweight improved object detection network is used for training and testing to extract the ROI region of the sow's rump image. Based on this recognition, image processing methods are used to extract the external morphological parameters of the sow's rump. S3. Analyze the correlation between backfat thickness and external morphological parameters of the rump, and construct a backfat thickness estimation model for sows based on the selected rump feature parameters. At the same time, a backfat thickness estimation system for sows was constructed based on the PyQt5 development tool.
2. The method and system for estimating backfat thickness in sows based on deep learning and image processing according to claim 1, characterized in that: In step S1, a sow rump depth image acquisition system is constructed. The specific steps are as follows: the system includes an Azure Kinect DK depth camera, a USB cable, an adjustable stand, and a laptop computer. The sow rump depth image acquisition system is developed based on the PyQt5 development tool.
3. The sow rump depth image acquisition system developed based on PyQt5 development tools according to claim 2, characterized in that: This data acquisition program is used to acquire depth images and RGB images of the sow's rump. Clicking the "Run" button on the program interface will acquire the sow's rump depth image; clicking the "Stop" button after image acquisition is complete will terminate the program.
4. The method and system for estimating backfat thickness in sows based on deep learning and image processing according to claim 1, characterized in that: In step S1, the depth image of the sow's rump and the backfat thickness data are acquired. Specifically, the sow's rump depth image is obtained using the constructed sow rump depth image acquisition system, and the backfat thickness parameter is measured using an ultrasonic backfat meter (Pig Doctor), with the measurement point being the internationally recognized P2 point in pig farming. During image acquisition, the depth camera is placed at a height of 100 cm above the ground, parallel to the pigpen behind the pig, to prevent the rear fence from obstructing the imaging process.
5. The method and system for estimating backfat thickness in sows based on deep learning and image processing according to claim 1, characterized in that: In step S2, the acquired depth image is preprocessed. Specifically, the original image is filtered for depth values, taking into account the pig's body length and position in the image. Then, the filtered image is normalized and colored to unify the depth value range and eliminate the differences introduced by the filtering.
6. The method and system for estimating backfat thickness in sows based on deep learning and image processing according to claim 1, characterized in that: In step S2, a lightweight improved object detection network is used for training and testing to extract the ROI region from the sow's rump image. Specifically, the ShuffleNetV2 network is introduced to reconstruct the backbone network of YOLOv8, making the model lightweight. By reducing the model size, the maximum improvement in accuracy and efficiency is achieved.
7. The method and system for estimating backfat thickness in sows based on deep learning and image processing according to claim 1, characterized in that: In step S2, based on this recognition, image processing methods are used to extract the external morphological parameters of the sow's rump. Specifically, the steps are as follows: morphological operations such as mean filtering, binarization, and opening are performed on the obtained ROI image, and a leg region removal algorithm is introduced. The center point is extracted from the processed binarized image of the sow's rump, and ellipse and circle fitting are performed using the edge pixels of the sow's rump to extract the external morphological parameters.
8. The method and system for estimating backfat thickness in sows based on deep learning and image processing according to claim 1, characterized in that: In step S3, the correlation between backfat thickness and external morphological parameters of the buttocks is analyzed. Specifically, backfat thickness has the highest correlation with parameters reflecting the area of the buttocks, followed by parameters reflecting the length of the buttocks, while the correlation with other parameters is significantly lower.
9. The method and system for estimating backfat thickness in sows based on deep learning and image processing according to claim 1, characterized in that: The selected rump feature parameters in step S3 are used to construct a backfat thickness estimation model for sows. Specifically, the selected rump feature parameters are dimensionality reduced using principal component analysis, and then the area factor and length factor are input into an elastic network regression model to construct the backfat thickness estimation model for sows.
10. The model for estimating backfat thickness in sows according to claim 9, characterized in that: The elastic network regression model exhibited the best predictive power, with a determination coefficient (R²) as high as 0.8356, and mean squared error (MSE) and mean absolute error (MAE) of 5.2126 mm. 2 With a diameter of 1.8102 mm, it is the best in all indicators in the test set.
11. The method and system for estimating backfat thickness in sows based on deep learning and image processing according to claim 1, characterized in that: In step S3, a backfat thickness estimation system for sows was built using the PyQt5 development tool. Specifically, after inputting an image of the sow's rump, the system automatically performs a series of steps, including preprocessing, target detection, image processing, and extraction of external feature parameters, to achieve real-time estimation of the sow's backfat thickness.