An image classification method for the degree of African swine fever infection
By constructing a body posture fitting model and correcting perspective distortion, the spatial distortion problem caused by changes in pig posture and fixed-viewpoint imaging was solved, enabling accurate assessment of the degree of African swine fever infection and improving the stability of pathological feature extraction and infection degree classification.
Patent Information
- Application Number
- CN202610799278.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-06-04
- Publication Date
- 2026-11-17
Smart Images

Figure CN123119086A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of image classification technology, and specifically to an image classification method for the degree of African swine fever infection. Background Technology
[0002] In the prevention and control of African swine fever, early identification and accurate assessment of the degree of infection are crucial for pig farms to take timely isolation, diagnosis, and treatment measures. With the development of large-scale farming, using fixed camera equipment to collect images of pigs and identifying pathological features on the pig's body surface through image classification methods has become an important technical means to improve the efficiency of disease monitoring. Compared with manual inspection methods, visual monitoring has advantages such as being non-contact, allowing for continuous data collection, and being suitable for group management.
[0003] However, in actual farming environments, pigs are typically free-moving, and their standing direction, body posture, distance from the camera equipment, and angle relative to a fixed viewpoint continuously change. Raw images of pigs acquired from a fixed viewpoint are easily affected by perspective projection, causing varying degrees of stretching, compression, or misalignment of areas such as the pig's back, abdomen, and limbs in the image. This results in inconsistencies in the position, scale, and shape of the same surface area in different images. For pigs infected with African swine fever, pathological features such as erythema, hemorrhagic spots, cyanotic areas, and ulcers are usually distributed in localized areas of the pig's body surface. Their morphology, grayscale, texture, and boundary variations are crucial for determining the degree of infection. Existing image recognition methods mostly extract features directly from two-dimensional images, rarely considering the spatial distortion caused by changes in pig body posture and fixed-viewpoint imaging. This makes the extraction of connected components, contour localization, and boundary control point determination of pathological areas susceptible to posture deviations. Furthermore, existing technologies often lack an effective alignment mechanism with healthy baseline contours or images when analyzing pathological regions, making it difficult to accurately measure the scale changes, positional shifts, and grayscale differences of pathological regions relative to normal body surface morphology. When pathological regions are spatially misaligned in an image, the texture feature map obtained through subsequent cropping may include non-pathological areas or omit some true pathological areas, thereby reducing the accuracy and stability of classification models in assessing the degree of infection. Summary of the Invention
[0004] The purpose of this invention is to provide an image classification method for the degree of African swine fever infection, thereby solving the problems existing in the prior art.
[0005] To achieve the above objectives, the present invention provides the following technical solution: an image classification method for the degree of African swine fever infection, comprising: S1. Obtain the original pig images collected from a fixed viewpoint, construct a body posture fitting model, and calculate the body distance and body angle of the pig relative to the fixed viewpoint based on the projection offset between the body posture fitting model and the fixed viewpoint imaging reference to obtain spatial pose data. S2. Construct a perspective projection matrix based on the body angle and body distance in the spatial pose data, and determine whether there is perspective distortion in the original pig image. If there is perspective distortion, resample the original image pixels through the perspective projection matrix to obtain the first corrected image; if there is no perspective distortion, use the original pig image as the first corrected image. S3. Extract the set of connected pixels of the African swine fever pathological region from the first corrected image, and perform contour sampling on the set of connected pixels to obtain the boundary control points of the pathological region. S4. Based on the deviation between the boundary control points of the pathological region and the preset healthy baseline contour, adjust the scale deformation and position deformation of the pathological region, and generate a spatial misalignment compensation matrix based on the scale deformation and position deformation. S5. A spatial misalignment compensation matrix is used to perform affine compensation processing on the pathological areas of the body surface in the first corrected image to align the pathological areas of the body surface with the healthy baseline contour, thus obtaining the second corrected image. S6. Calculate the grayscale difference between the second corrected image and the preset health baseline image at the corresponding pixel positions to determine the feature alignment coordinates of the pathological area on the body surface. S7. Based on the feature alignment coordinates, crop the pathological texture feature map from the second corrected image, and input the pathological texture feature map into the preset classification model to obtain the African swine fever infection level assessment level.
[0006] Preferably, S1 includes: Obtain original images of live pigs, extract features from the original images of live pigs to obtain the outline of the pig's back and abdomen; The limb support points are located based on the outline of the pig's spine and abdomen, and a body posture fitting model is constructed based on the limb support points. Calculate the projection offset between the body posture fitting model and the fixed-viewpoint imaging reference; If the projection offset is greater than the preset offset threshold, the body distance and body angle are calculated based on the projection offset to obtain spatial pose data.
[0007] Preferably, S2 includes: Obtain the body angle and body distance from the spatial pose data, and construct a perspective projection matrix based on the body angle and body distance; The original pig images were mapped using a perspective projection matrix to obtain a set of mapped coordinates; Calculate the coordinate offset between the mapped coordinate set and the reference coordinate set; Determine whether the original pig image has perspective distortion, including whether the coordinate offset is greater than a preset threshold; If the coordinate offset is greater than the preset threshold, the original pig image is resampled by the perspective projection matrix to obtain the first corrected image. If the coordinate offset is not greater than the preset threshold, the original pig image is used as the first corrected image.
[0008] Preferably, S2 includes: Obtain the body angle and body distance from the spatial pose data, and construct a perspective projection matrix based on the body angle and body distance; The original pig images were mapped using a perspective projection matrix to obtain a set of mapped coordinates; Calculate the coordinate offset between the mapped coordinate set and the reference coordinate set; Determine whether the original pig image has perspective distortion, including whether the coordinate offset is greater than a preset threshold; If the coordinate offset is greater than the preset threshold, the original pig image is resampled by the perspective projection matrix to obtain the first corrected image. If the coordinate offset is not greater than the preset threshold, the original pig image is used as the first corrected image.
[0009] Preferably, S4 includes: Calculate the initial contour deviation between the boundary control points of the pathological region and the preset healthy baseline contour; Smooth boundary control points are obtained by fitting the initial contour deviation; If the curvature characteristics of the smooth boundary control points are greater than the preset threshold, then the scale deformation is determined by curvature adjustment. The positional deformation is calculated based on the relative displacement between the mapping control points corresponding to the scale deformation and the preset health baseline profile. A spatial misalignment compensation matrix is generated based on scale deformation and position deformation.
[0010] Preferably, S5 includes: Obtain the edge features of the pathological area on the body surface in the first corrected image, and calculate the spatial misalignment compensation matrix based on the edge features; A spatial misalignment compensation matrix is used to process the pathological area on the body surface to obtain a pixel mapping set. The grayscale interpolation distribution is determined and adjusted based on the pixel mapping set to obtain contour alignment data. The pathological areas on the body surface in the first corrected image are updated by contour alignment data. The pathological areas on the body surface in the first corrected image are then subjected to affine compensation processing using a spatial misalignment compensation matrix to align the pathological areas on the body surface with the healthy baseline contour, thus obtaining the second corrected image.
[0011] Preferably, S6 includes: A second corrected image and a preset health baseline image are acquired, and an affine transformation algorithm is used to perform spatial registration processing on the second corrected image and the preset health baseline image to obtain a registered image pair. Based on the registered image pairs, the gray-level difference at corresponding pixel positions is extracted by pixel-by-pixel subtraction to obtain the initial gray-level difference matrix.
[0012] Preferably, S6 further includes: For the initial gray-level difference matrix, Otsu's method is used for binarization segmentation to determine the connected components of abnormal regions; If the number of pixels in the connected components of the abnormal region is greater than a preset threshold, the edge contour pixels of the connected components of the abnormal region are extracted by the edge detection algorithm to determine the feature alignment coordinates of the pathological region on the body surface.
[0013] Preferably, S7 includes: A standard-size pixel matrix is obtained by resampling the second corrected image; Extract texture data from a standard-sized pixel matrix to generate a pathological texture feature map.
[0014] Preferably, S7 further includes: Dimensionality reduction of the pathological texture feature map is used to obtain a dimension-reduced pathological feature vector, and the dimension-reduced pathological feature vector is truncated to obtain the target pathological feature vector. The target pathological feature vector is input into a preset classification model to obtain a probability set, and the African swine fever infection level is determined based on the probability set.
[0015] As can be seen from the above technical solution, the present invention has the following beneficial effects: This image classification method for the degree of African swine fever infection obtains spatial pose data of pigs from a fixed viewpoint by constructing a body posture fitting model, and corrects perspective distortion of the original pig images accordingly, which can reduce the impact of changes in pig posture, distance, and angle on image recognition results. Simultaneously, by extracting the connected pixel set of the pathological regions on the body surface of the African swine fever infected pigs and determining the boundary control points of the pathological regions, and combining the scale deformation and position deformation of the healthy baseline contour to generate a spatial misalignment compensation matrix, affine compensation and normalization alignment are performed on the pathological regions, thereby reducing feature deviations caused by spatial misalignment. Furthermore, the feature alignment coordinates are determined by the grayscale difference between the second corrected image and the healthy baseline image, and the resulting pathological texture feature map is cropped and input into the classification model. This improves the accuracy and stability of extracting surface pathological features such as erythema, hemorrhage, cyanosis, and ulceration, thereby enhancing the classification reliability of the African swine fever infection degree assessment. Attached Figure Description
[0016] Figure 1 This is a signal transmission diagram of the present invention; Figure 2 This is a structural block diagram of the local terminal of an exemplary electronic device of the present invention; Figure 3 This is a structural block diagram of the network terminal of an exemplary electronic device of the present invention. Detailed Implementation
[0017] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0018] Example 1: like Figure 1 As shown, the present invention provides a technical solution: an image classification method for the degree of African swine fever infection, comprising: S1. Obtain the original pig image collected from a fixed viewpoint, construct a body posture fitting model based on the pig's back contour line, abdominal contour line and limb support points, and calculate the pig's body distance and body angle relative to the fixed viewpoint based on the projection offset between the body posture fitting model and the fixed viewpoint imaging reference to obtain spatial pose data. S2. Construct a perspective projection matrix based on the body angle and body distance in the spatial pose data, and determine whether there is perspective distortion in the original pig image; if there is perspective distortion, resample the original image pixel by pixel through the perspective projection matrix to obtain the first corrected image; if there is no perspective distortion, use the original pig image as the first corrected image. S3. Extract the connected component pixel set of the African swine fever pathological region from the first corrected image. The pathological region includes erythema, hemorrhage, cyanosis and / or ulceration. Perform contour sampling on the connected component pixel set to obtain the boundary control points of the pathological region. S4. Based on the deviation between the boundary control point of the pathological region and the preset healthy baseline contour, calculate the scale deformation and position deformation of the pathological region by combining local least squares fitting with curvature adjustment, and generate a spatial misalignment compensation matrix based on the scale deformation and position deformation. S5. The spatial misalignment compensation matrix is used to perform affine compensation processing on the pathological area of the body surface in the first corrected image to align the pathological area of the body surface with the healthy baseline contour, thus obtaining the second corrected image. S6. Calculate the grayscale difference between the second corrected image and the preset health baseline image at the corresponding pixel positions to determine the feature alignment coordinates of the pathological area on the body surface. S7. Based on the feature alignment coordinates, crop the pathological texture feature map from the second corrected image, and input the pathological texture feature map into a preset classification model to obtain the African swine fever infection level assessment grade.
[0019] In the above embodiments, the original pig images acquired from a fixed perspective serve as the basic data for image classification processing. The fixed perspective is formed by image acquisition devices set up in the pigsty passage, on the side of the pen, or above the pen.
[0020] Specifically, the installation location, shooting direction, focal length, and imaging range of the image acquisition equipment are calibrated before acquisition. The original pig images contain image information related to the pig's body, body surface areas, and pathological manifestations. Because pigs exhibit changes in standing position, body orientation, and limb support status within the acquisition area, the pathological areas in the original pig images will experience changes in imaging scale and coordinate position shifts. Therefore, this implementation first constructs a body posture fitting model based on the pig's back contour line, abdominal contour line, and limb support points, allowing the upper and lower edge morphology and support posture of the pig's body to be expressed through a unified geometric relationship.
[0021] Furthermore, the spine contour line is used to characterize the upper boundary of the pig's body and the direction of its body axis extension, the abdomen contour line is used to characterize the lower boundary of the pig's body and the undulation of its abdomen, and the limb support points are used to determine the pig's support position relative to the ground and image coordinate system of the acquisition area. Curve fitting is performed on the spine and abdomen contour lines, and combined with the positional relationship of the limb support points, to obtain a body posture fitting model.
[0022] Specifically, the body posture fitting model includes the body axis direction, body contour width, body contour length, support point coordinates, and body center coordinates. The body posture fitting model is compared with a fixed-view imaging reference to obtain the projection offset of the current pig posture relative to the standard imaging posture. The fixed-view imaging reference includes the standard body axis direction, standard body contour scale, standard support point position, and standard imaging distance. Based on the projection offset, the pig's body distance and body angle relative to the fixed viewpoint are calculated, forming spatial pose data.
[0023] In this embodiment, body distance is used to represent the distance deviation between the center of the pig's body and the fixed-view imaging reference, and body angle is used to represent the angular deviation between the direction of the pig's body axis and the direction of the fixed-view imaging reference.
[0024] Specifically, a perspective projection matrix is constructed based on the body angle and body distance. This matrix describes the mapping relationship between the original pig image coordinates and the standard imaging coordinates. The system compares the body angle with a preset angle threshold and the body distance with a preset distance threshold. If either the body angle or body distance exceeds the preset angle or distance threshold, the original pig image is determined to have perspective distortion. If neither the body angle nor the body distance exceeds the preset distance threshold, the original pig image is determined to have no perspective distortion.
[0025] Furthermore, when the original pig image has perspective distortion, pixel resampling is performed on the original pig image using a perspective projection matrix. Pixel resampling determines the corresponding coordinates of the target pixel in the original pig image based on the perspective projection matrix, and generates corrected pixel values based on these coordinates, thereby obtaining the first corrected image.
[0026] This process transforms the pig's body contour, surface area, and pathological areas to a coordinate system corresponding to a fixed-viewpoint imaging reference. When the original pig image has no perspective distortion, it is directly used as the first corrected image in subsequent processing.
[0027] Furthermore, the set of connected pixels representing the African swine fever (ASF) pathological regions on the body surface is extracted from the first corrected image. These pathological regions include at least one of erythema, hemorrhagic spots, cyanotic areas, and ulcer regions.
[0028] The aforementioned regions, as shown in the image, exhibit differences in color channel values, grayscale values, boundary morphology, and texture distribution compared to healthy body surface regions. During processing, suspected pathological pixels are first identified based on preset color thresholds, preset grayscale thresholds, or preset segmentation models. Then, through four-neighbor or eight-neighbor connected component analysis, spatially continuous suspected pathological pixels are grouped into a connected component pixel set. Subsequently, area filtering, hole filling, boundary smoothing, and morphological processing are performed on the connected component pixel set to obtain the pathological regions on the body surface that meet the processing conditions.
[0029] In this embodiment, contour sampling is performed on the outer contour of the connected component pixel set to obtain the pathological region boundary control points. The pathological region boundary control points are selected from the outer contour of the connected component according to a preset sampling interval or a preset number of boundary points, and are used to express the boundary position and boundary shape of the pathological region.
[0030] The process involves matching the boundary control points of the pathological region with a preset healthy baseline contour to obtain the deviation of the pathological region from the healthy body surface baseline position. This deviation includes lateral coordinate deviation, longitudinal coordinate deviation, and boundary normal deviation. The lateral coordinate deviation describes the positional change of the pathological region in the lateral direction of the image, the longitudinal coordinate deviation describes the positional change of the pathological region in the longitudinal direction of the image, and the boundary normal deviation describes the outward or inward expansion of the pathological region boundary relative to the healthy baseline contour.
[0031] Furthermore, local least squares fitting combined with curvature adjustment is used to calculate the scale and location deformations of the pathological region.
[0032] Specifically, local least squares fitting takes the corresponding points on the pathological region boundary control points and the preset healthy baseline contour as input, and solves the fitting relationship between the boundary control points and the healthy baseline contour within a preset local window. Curvature adjustment modifies the fitting constraints based on the curvature values at the pathological region boundary control points, so that the location of boundary curvature changes participates in the calculation of scale deformation and position deformation. Scale deformation is used to represent the scaling relationship of the pathological region relative to the healthy baseline contour in the horizontal and vertical directions, and position deformation is used to represent the translation relationship of the pathological region relative to the healthy baseline contour in the horizontal and vertical directions.
[0033] As a preferred embodiment, a spatial misalignment compensation matrix is generated based on scale deformation and position deformation.
[0034] Specifically, the spatial misalignment compensation matrix includes horizontal scaling parameters, vertical scaling parameters, horizontal translation parameters, vertical translation parameters, and rotation parameters.
[0035] The spatial misalignment compensation matrix describes the affine transformation relationship of the pathological region from its current position in the first corrected image to its corresponding position on the healthy baseline contour. The spatial misalignment compensation matrix is used to perform affine compensation processing on the pathological region on the body surface in the first corrected image, aligning the pathological region with the healthy baseline contour in both coordinate position and contour scale, thus obtaining the second corrected image.
[0036] Furthermore, the second corrected image and the preset health reference image are located in the same standard coordinate system. The system calculates the grayscale difference between the second corrected image and the preset health reference image at corresponding pixel positions to obtain a grayscale difference map.
[0037] Specifically, the grayscale difference image is used to represent the pixel differences between the current pig surface image and the healthy baseline image. Based on the pixel positions in the grayscale difference image that meet a preset grayscale difference threshold, the feature alignment coordinates of the pathological region on the body surface are determined. These feature alignment coordinates include the coordinates of the pathological region center, the pathological region boundary, and the coordinates of the pathological texture clipping region, used to define the clipping position of the pathological texture feature map in the second corrected image.
[0038] Furthermore, pathological texture feature maps are cropped from the second corrected image based on feature alignment coordinates.
[0039] Specifically, the pathological texture feature map includes color channel information, grayscale distribution information, boundary morphology information, and texture distribution information of the pathological area on the body surface. After the pathological texture feature map is input into a preset classification model, the preset classification model performs feature extraction and classification operations on the pathological texture feature map, and outputs the African swine fever infection level assessment grade. The output grade of the preset classification model is determined according to preset classification rules, which correspond to the infection level labels in the training samples.
[0040] Furthermore, through body pose fitting, perspective projection correction, extraction of pathological regions on the body surface, sampling of boundary control points, spatial misalignment compensation, grayscale difference calculation, and pathological texture feature classification, the pathological regions on the body surface of the original pig image are classified under standard coordinate relationships. This process eliminates coordinate inconsistencies caused by shooting distance, body angle, and pathological region position offsets, ensuring that the pathological texture feature map input to the preset classification model maintains a coordinate correspondence with the preset healthy baseline image.
[0041] A performance comparison table between the present invention and the prior art is also provided, as shown below: The above data reflects the potential performance range of fixed camera equipment when performing image classification in a farm environment. Existing two-dimensional image classification methods typically use the original image, a simple foreground segmentation image, or a directly cropped image as input. They do not specifically address the pig's body posture, perspective distortion, and spatial misalignment of pathological areas. Therefore, the classification results fluctuate significantly when the pig's standing direction changes, the shooting distance changes, or there is partial occlusion on the body surface.
[0042] This invention calculates spatial pose data using a body posture fitting model and generates a first corrected image using a perspective projection matrix, ensuring a uniform and fixed viewpoint reference for the pig's body before pathological area extraction. Subsequently, a spatial misalignment compensation matrix is generated using pathological area boundary control points, a healthy baseline contour, scale deformation variables, and positional deformation variables, aligning erythema, hemorrhage, cyanosis, and ulcer areas with the healthy baseline contour in the second corrected image. Further, feature alignment coordinates are determined using the grayscale difference matrix between the second corrected image and the preset healthy baseline image, and then the pathological texture feature map is cropped and input into the classification model. This processing reduces the interference of pose differences and spatial misalignment on the classification model, thus improving classification accuracy, recall, and pathological texture cropping coverage.
[0043] However, this invention does not mean that false alarms and false negatives can be completely eliminated. Factors such as fecal contamination, mud spots on the body surface, obstruction by fences, blurred movement, sudden changes in lighting, overlapping of pigs, and individual differences in skin color exist in farms. These factors can affect the extraction of pathological areas and the calculation of grayscale differences. Therefore, the false alarm and false negative rates in the table retain reasonable ranges.
[0044] In a set of fixed-viewpoint image verification experiments, images of pig body surfaces were collected, and manually labeled pathological areas and infection severity levels were used as controls. Existing two-dimensional image classification methods are significantly affected by pose changes in terms of infection severity classification accuracy, recall for mild infection identification, and pathological area contour localization, with infection severity classification accuracy ranging from 72.0% to 81.5%. After adopting the method of this invention, through body pose fitting, perspective correction, spatial misalignment compensation, and feature alignment processing, the infection severity classification accuracy reaches 84.0% to 91.5%, the mild infection identification recall rate reaches 76.0% to 86.5%, and the average pathological area contour offset is 3.5 pixels to 8.0 pixels.
[0045] The above results demonstrate that this invention can improve the stability and accuracy of classifying pathological images of pigs from a fixed perspective. However, its performance is still affected by image quality, occlusion status, lighting conditions, and the coverage of training samples. In practical applications, engineering errors can be further reduced by increasing the number of healthy baseline samples, periodically updating the threshold, and increasing the training ratio of occluded and low-light samples.
[0046] Example 2: S1 includes acquiring original pig images, extracting features from the original pig images to obtain the pig's back contour line and abdominal contour line; locating limb support points based on the pig's back contour line and abdominal contour line, and constructing a body posture fitting model based on the limb support points; calculating the projection offset between the body posture fitting model and the fixed-view imaging reference; if the projection offset is greater than a preset offset threshold, calculating the body distance and body angle based on the projection offset to obtain spatial pose data.
[0047] In this embodiment, the image acquisition device is fixedly installed on the side of the pigsty passage or the side of the pen. The installation height, lens orientation, focal length, imaging range, and ground reference area of the image acquisition device are calibrated before being put into use.
[0048] During calibration, a calibration board with four corner points is placed on the ground in the acquisition area. The positions of the four corner points in the actual ground coordinates are recorded, and the pixel positions of these four corner points are identified in the acquired image. The conversion relationship between ground coordinates and image coordinates is obtained from the correspondence between the four sets of actual ground coordinates and image pixel coordinates. This conversion relationship is used to subsequently convert the pixel positions of the limb support points from the image to their actual positions on the ground.
[0049] Furthermore, after obtaining the original pig images, foreground separation is first performed on the original pig images.
[0050] Specifically, when the original pig image is a color image, the red, green, and blue channels are weighted and summed according to preset grayscale conversion weights to obtain a grayscale image. The preset grayscale conversion weights use fixed values in image processing, with the red channel weight at 0.299, the green channel weight at 0.587, and the blue channel weight at 0.114. Then, this grayscale image is subtracted pixel-by-pixel from a pre-acquired empty pen background image at a fixed viewpoint, and the absolute value of the subtraction result is taken to obtain a background difference image. In the background difference image, each pixel value represents the grayscale difference between the current position of that pixel and the empty pen background.
[0051] Furthermore, the foreground separation threshold is determined by the grayscale histogram of the background difference image.
[0052] Specifically, each grayscale value between 0 and 255 is iterated over, and each grayscale value is used as a candidate threshold. The pixels in the background difference image are then divided into candidate foreground pixel groups and candidate background pixel groups. For each candidate threshold, the number of pixels in the candidate foreground pixel group, the number of pixels in the candidate background pixel group, the average grayscale value of the candidate foreground pixel group, and the average grayscale value of the candidate background pixel group are calculated. The difference between the average grayscale values of the two groups is then calculated, and the square of this difference is multiplied by the proportion of pixels in each group to obtain the inter-class discrimination value corresponding to that candidate threshold. The grayscale value with the largest inter-class discrimination value is selected as the foreground separation threshold.
[0053] In this process, pixels in the background difference image whose grayscale values reach the foreground separation threshold are identified as foreground pixels of pigs, while pixels whose grayscale values do not reach the foreground separation threshold are identified as background pixels, thus obtaining the foreground mask of pigs.
[0054] Furthermore, after obtaining the pig foreground mask, connected component analysis is performed on it. The connected component analysis uses an 8-neighborhood connection rule, meaning that the top, bottom, left, right, and four diagonally adjacent pixels of a pixel are all considered for connectivity. After completing the connected component analysis, the number of pixels contained in each connected component is calculated, and the connected component with the largest number of pixels is retained as the main pig region. Subsequently, morphological closing and opening operations are performed on the main pig region. The closing operation is used to fill holes within the boundary of the main pig region, and the opening operation is used to remove small protrusions connected to the boundary of the main pig region.
[0055] In this morphological operation, a circular structuring element is used. When the image height does not exceed 1080 pixels, the radius of the circular structuring element is 3 pixels; when the image height exceeds 1080 pixels, the radius of the circular structuring element is the integer pixel value obtained by dividing the image height by 360 and rounding it off. Through the above processing, the main pig body region is obtained for contour extraction.
[0056] Furthermore, when extracting the pig's spine outline, the pig's main body region is scanned column by column along the horizontal direction of the image. For each column containing pig main body pixels, the pig main body pixel with the vertical coordinate closest to the top edge of the image in that column is selected as a candidate spine point. To avoid interference from the pig's head and tail ends on the trunk spine outline, the leftmost and rightmost coordinates of the pig's main body region in the horizontal direction are first determined, and the horizontal span between them is calculated. Within this horizontal span, 0.08 times the horizontal span is excluded from the left end inwards, and 0.08 times the horizontal span is excluded from the right end inwards, with the remaining horizontal range serving as the trunk spine fitting range. The candidate spine points within this range are fitted with cubic spline curves according to the horizontal coordinate order to obtain the pig's spine outline.
[0057] In the specific fitting process, the fitting curve is made to pass through or approach the candidate points of the spine, and the sum of the squares of the longitudinal distances from each candidate point of the spine to the fitting curve is minimized, so that the spine contour line reflects the continuous direction of the upper boundary of the trunk.
[0058] Furthermore, when extracting the abdominal contour, the pig's main body region is still processed column by column along the horizontal direction of the image. For each column, the pig's main body pixels located below the spine contour are read first, and then continuous pig's main body pixel segments are searched downwards from the corresponding position of the spine contour. Since the limbs are located below the abdomen, directly using the pig's main body pixels at the bottom of the column would mistakenly take the hoof contour as the abdominal boundary. Therefore, this embodiment uses the continuous width change of the torso as the abdominal boundary criterion.
[0059] Specifically, the bottom positions of the main pig pixel segments in adjacent columns are compared. When the bottom position of a column shows a sudden change relative to the left and right adjacent columns due to the downward extension of limbs, the bottom position of that column is replaced with the arithmetic mean of the bottom positions of the left and right adjacent columns; when the bottom position of that column changes continuously with the bottom positions of the left and right adjacent columns, the bottom position of that column is retained. After processing each column, the obtained abdominal candidate points are fitted with cubic spline curves according to the horizontal coordinate order to obtain the abdominal contour line. This abdominal contour line, together with the back contour line, defines the pig's torso region.
[0060] Furthermore, when locating the limb support points, a limb search area is established with the abdominal contour line as the upper boundary. The limb search area consists of pixels located below the abdominal contour line within the main body area of the pig.
[0061] In this process, an 8-neighborhood connected component analysis is performed on the limb search area to obtain candidate limb regions. For each candidate limb region, the set of bottom pixels whose vertical coordinates are closest to the lower edge of the image is found, and the average horizontal coordinate of this set of bottom pixels is calculated. This average horizontal coordinate and the vertical coordinate of the bottom pixel set are used to form the support points of the candidate limb region. If there are more than four candidate limb regions, they are filtered according to their connection relationship with the abdominal contour line, retaining four support points that are continuously connected to the lower boundary of the torso and whose bottom positions fall within the ground-marked area. If the same limb is divided into two connected components due to occlusion, the connected components with a horizontal spacing not exceeding the diameter of the aforementioned circular structural element and consistent vertical bottom coordinates are merged before calculating the support points. This yields four support points for the pig's four limbs.
[0062] In this embodiment, when constructing a body posture fitting model based on the limb support points, the midline of the torso is first taken between the spine contour line and the abdominal contour line.
[0063] Specifically, 40 equally spaced sampling positions were set within the transverse range of the torso. At each sampling position, the longitudinal coordinates of the spine contour and the abdominal contour were read, and their arithmetic mean was used as the torso midline point for that sampling position. Then, a straight line fitting was performed on the 40 torso midline points. The straight line fitting process was as follows: the average of the transverse coordinates of the 40 sampling positions was calculated, and the average of the longitudinal coordinates of the 40 torso midline points was calculated; then, based on the deviation of the transverse coordinates of each sampling position from the average transverse coordinates, and the deviation of the longitudinal coordinates of that sampling position from the average longitudinal coordinates, the slope representing the degree of inclination of the torso midline was obtained; finally, the position of the torso midline was determined based on the average transverse coordinates, the average longitudinal coordinates, and the slope. The torso center point was taken as the arithmetic mean of the coordinates of the 40 torso midline points. The torso posture fitting model was formed by the spine contour, abdominal contour, torso midline, torso center point, and four limb support points.
[0064] Furthermore, a fixed-viewpoint imaging benchmark was established before the equipment was put into use. The specific establishment process was as follows: 30 frames of standard-posture pig images were acquired using the same image acquisition equipment, at the same fixed installation location, and in the same ground calibration area.
[0065] The acquisition conditions for standard-posture pig images are as follows: the pig's torso is centered within the ground calibration area, all four limb support points are located within the ground calibration area, and the pig's body axis is aligned with the preset direction of the fixed viewing angle. For 30 frames of standard-posture pig images, the spine contour, abdomen contour, torso center point, torso midline, and four limb support points are extracted following the aforementioned process. Then, in each frame, 40 sampling points are taken for the spine contour and 40 sampling points for the abdomen contour, and the torso center point and four limb support points are recorded. The arithmetic mean of the coordinates of the spine sampling points with the same sequence number in each of the 30 frames is calculated, as are the coordinates of the abdomen sampling points with the same sequence number, the coordinates of the torso center point, and the coordinates of the limb support points with the same sequence number. This yields the fixed-view imaging reference. This fixed-view imaging reference includes reference spine contour sampling points, reference abdomen contour sampling points, reference torso center point, and reference limb support points.
[0066] As a preferred embodiment, when calculating the projection offset between the body posture fitting model and the fixed-view imaging reference, the spine contour line in the current original pig image is sampled at the same 40 sampling positions as the fixed-view imaging reference, the current abdominal contour line is sampled at the same 40 sampling positions as the fixed-view imaging reference, and the current trunk center point and the current four limb support points are included in the calculation.
[0067] Therefore, the current body posture fitting model generates 85 current projection points, and the fixed-view imaging reference generates 85 reference projection points. These 85 current projection points and 85 reference projection points correspond one-to-one according to the same sequence number. For each pair of corresponding points, the difference in their lateral and longitudinal coordinates is calculated. The squares of the lateral and longitudinal coordinate differences are added together to obtain the squared projection distance of that pair of corresponding points. The sum of the squared projection distances of all 85 pairs of corresponding points is divided by 85, and the square root of the result is taken to obtain the projection offset between the body posture fitting model and the fixed-view imaging reference. This projection offset, expressed in pixels, characterizes the overall projection deviation of the pig's body in the fixed-view image.
[0068] Furthermore, the preset offset threshold is determined by 30 frames of standard posture pig images from the fixed-viewpoint imaging benchmark establishment phase.
[0069] Specifically, the projection offset of the body posture fitting model relative to the fixed-viewpoint imaging reference for each frame in 30 standard-pose pig images was calculated, resulting in 30 standard offset values. First, the 30 standard offset values were summed and divided by 30 to obtain the standard offset mean. Then, the difference between each standard offset value and the standard offset mean was calculated. The 30 differences were squared and summed, and the sum was divided by 29. The square root of the result was then taken to obtain the standard offset discrete value. The preset offset threshold was the standard offset mean plus three times the standard offset discrete value. This offset threshold, obtained using the same fixed viewpoint, the same calibration area, the same contour extraction process, and the same support point localization process, was used to characterize the allowable projection offset boundary under standard pose acquisition conditions.
[0070] Furthermore, when processing the original pig images, the current projection offset is compared with a preset offset threshold. If the current projection offset is greater than the preset offset threshold, it is determined that the current pig body posture has undergone a projection offset relative to the fixed-view imaging reference that needs to be included in the pose calculation, and the body distance and body angle are calculated based on the projection offset. If the current projection offset is not greater than the preset offset threshold, it is determined that the current pig image uses the pose parameters corresponding to the fixed-view imaging reference, and no updates to the body distance and body angle triggered by the projection offset are performed.
[0071] Furthermore, the calculation of body distance uses four limb support points as input. First, using the conversion relationship between ground coordinates and image coordinates obtained during device calibration, the image pixel coordinates of the current four limb support points are converted into actual ground coordinates.
[0072] During the conversion, the horizontal and vertical pixel coordinates of each support point are substituted into the aforementioned conversion relationship to obtain the actual horizontal and vertical coordinates of that support point in the ground coordinate system. Then, the actual horizontal coordinates of the four support points are added together and divided by 4 to obtain the actual horizontal coordinates of the current body's ground center point; the actual vertical coordinates of the four support points are added together and divided by 4 to obtain the actual vertical coordinates of the current body's ground center point. The four reference limb support points in the fixed-view imaging reference are also converted to actual ground coordinates in the same way, and the reference body's ground center point is obtained by arithmetic averaging. Finally, the straight-line distance between the current body's ground center point and the reference body's ground center point is calculated and used as the body distance. This body distance reflects the actual ground offset of the current pig support center relative to the fixed-view imaging reference support center.
[0073] Furthermore, the calculation of the body angle is also based on the actual ground coordinates of the four limb support points. First, the direction of the pig's body axis is determined according to the extension direction of the trunk midline, and then the four support points are sorted along the body axis. The two support points located at the front end of the body axis are designated as forelimb support points, and the two support points located at the rear end of the body axis are designated as hindlimb support points. The arithmetic mean of the actual ground coordinates of the two forelimb support points is calculated to obtain the center point of the forelimb; the arithmetic mean of the actual ground coordinates of the two hindlimb support points is calculated to obtain the center point of the hindlimb. Subsequently, the direction from the center point of the hindlimb to the center point of the forelimb is taken as the current direction of the pig's body axis, and the current body axis direction angle is determined according to the angle between this direction and the lateral reference direction of the ground coordinates. The center points of the forelimbs and hindlimbs in the fixed-view imaging reference are determined in the same way, and the reference body axis direction angle is obtained accordingly. The current body axis direction angle is subtracted from the reference body axis direction angle to obtain the body angle.
[0074] Specifically, when the calculated result exceeds the positive half-cycle or is less than the negative half-cycle, the body angle is converted to between the negative and positive half-cycles by adding or subtracting one full-cycle angle. This body angle represents the amount of deflection of the current pig's trunk direction relative to the fixed-view imaging reference direction.
[0075] Therefore, the spatial pose data output by S1 includes body distance and body angle, and simultaneously records the current torso center point, current torso midline, current four limb support points and their actual ground coordinates.
[0076] Example 3: S2 includes acquiring the body angle and body distance from the spatial pose data, constructing a perspective projection matrix based on the body angle and body distance; performing coordinate mapping processing on the original pig image using the perspective projection matrix to obtain a mapped coordinate set; calculating the coordinate offset between the mapped coordinate set and the reference coordinate set; determining whether the original pig image has perspective distortion, including determining whether the coordinate offset is greater than a preset threshold; if the coordinate offset is greater than the preset threshold, then resampling pixels of the original pig image using the perspective projection matrix to obtain a first corrected image; if the coordinate offset is not greater than the preset threshold, then using the original pig image as the first corrected image.
[0077] In this embodiment, S2 receives the spatial pose data output by S1. The spatial pose data includes body angles and body distances, and records the image coordinates of the current body center point, body axis direction, and limb support points. The body angles are represented by directional angles, with the fixed viewing angle imaging reference direction being zero degrees. A positive value is recorded when the pig's body axis deflects clockwise, and a negative value is recorded when it deflects counterclockwise.
[0078] In this context, body distance is represented by a directed distance, with positive values indicating the pig's support center is farther from the image acquisition device and negative values indicating it is closer to the device. This convention ensures that body angles and body distances have definite computational meanings in the subsequent construction of the perspective projection matrix.
[0079] The image acquisition equipment is calibrated after installation. The calibration includes the pixel scale corresponding to the lens focal length, the position of the image center point, the standard imaging distance under a fixed viewing angle, the standard body center point, the standard body axis direction, the standard torso projection length, and the standard torso projection width.
[0080] The standard imaging distance is determined by the straight-line distance between the reference body support center in the fixed-view imaging reference and the projected position of the image acquisition device on the ground. The standard torso projection length is determined by the distance between the sampling points at the front and rear ends of the torso in the fixed-view imaging reference. The standard torso projection width is determined by the average distance between the sampling points at the spine contour and the sampling points at the abdomen contour in the fixed-view imaging reference.
[0081] Furthermore, when constructing the perspective projection matrix, the current imaging distance is first determined based on the body distance. The current imaging distance is the standard imaging distance plus the body distance; when the body distance is positive, the current imaging distance is greater than the standard imaging distance; when the body distance is negative, the current imaging distance is less than the standard imaging distance.
[0082] Subsequently, the standard imaging distance is divided by the current imaging distance to obtain the projection scale correction factor. This projection scale correction factor is used to determine the conversion relationship between the torso projection size in the current image and the torso projection size in the standard image. Based on this projection scale correction factor, the standard torso projection length and standard torso projection width are converted into the current torso projection length and current torso projection width.
[0083] Furthermore, after determining the current torso projection length and current torso projection width, a control frame for the current torso is established with the current torso center point as the center.
[0084] Specifically, the current torso control frame includes four control points: upper front, lower front, upper back, and lower back. The upper front and upper back control points are located on the back side, while the lower front and lower back control points are located on the abdomen side. The current torso angle is used to determine the body axis direction of the current torso control frame, and the direction perpendicular to this body axis is used to determine the back and abdomen sides. Using the current torso center point as a reference, half the current torso projection length is taken along the body axis as the front-back position, and half the current torso projection width is taken along the direction perpendicular to the body axis as the up-down position, thus obtaining four current control points.
[0085] Simultaneously, a reference torso control frame is established within the fixed-viewpoint imaging reference. This reference torso control frame also includes four reference control points: upper front, lower front, upper rear, and lower rear. These four reference control points are centered on the standard torso center point, with the standard body axis as the front-rear direction, and are defined by the standard torso projection length and width. The current control point corresponds one-to-one with the reference control points in the order of upper front, lower front, upper rear, and lower rear.
[0086] Furthermore, after establishing the correspondence between the four sets of control points, the perspective transformation parameters between the current control point and the reference control point are solved. The perspective projection matrix adopts a 3x3 structure, with 8 parameters involved in the solution, and the last scale parameter is fixed at 1.
[0087] During processing, the horizontal and vertical coordinates of each current control point are substituted with the horizontal and vertical coordinates of the corresponding reference control point into the perspective coordinate transformation relationship. Each group of control points generates two linear equations, and the four groups of control points form a total of eight linear equations. These eight linear equations are solved using Gaussian elimination to obtain eight undetermined parameters in the perspective projection matrix. The resulting perspective projection matrix is used to convert the current imaging coordinates in the original pig image into standard coordinates under a fixed-viewpoint imaging reference.
[0088] In this embodiment, when performing coordinate mapping processing on the original pig image using a perspective projection matrix, the sampling points participating in the mapping are first determined. The sampling points are generated by the bounding rectangle of the main body region of the pig.
[0089] Specifically, 20 equally spaced sampling positions are set horizontally and 20 equally spaced sampling positions vertically within the circumscribed rectangle of the main pig area, forming 400 sampling points. Each sampling point has horizontal and vertical coordinates from the original image. The horizontal and vertical coordinates of each sampling point are sequentially substituted into the perspective projection matrix to obtain the corresponding unnormalized horizontal coordinate, unnormalized vertical coordinate, and homogeneous normalized value. Then, the unnormalized horizontal coordinate is divided by the homogeneous normalized value to obtain the mapped horizontal coordinate; the unnormalized vertical coordinate is divided by the homogeneous normalized value to obtain the mapped vertical coordinate. After performing the above processing on each of the 400 sampling points, a set of mapped coordinates is obtained.
[0090] As a preferred embodiment, the reference coordinate set is generated during the fixed-viewpoint imaging reference establishment stage. During generation, 20 equally spaced sampling positions are set in the horizontal direction and 20 equally spaced sampling positions in the vertical direction of the rectangle circumscribed around the reference pig's main body region, thus forming 400 reference sampling points. The reference sampling points are numbered sequentially from top to bottom and from left to right. The 400 sampling points in the original pig image are also numbered in the same order, so that the first mapped coordinate in the mapped coordinate set corresponds to the first reference coordinate in the reference coordinate set, up to the 400th mapped coordinate corresponding to the 400th reference coordinate.
[0091] Furthermore, when calculating the coordinate offset between the mapped coordinate set and the reference coordinate set, 400 sets of corresponding coordinates are processed one by one. For any set of corresponding coordinates, the difference between the horizontal coordinate of the mapped coordinate and the horizontal coordinate of the reference coordinate is first calculated, and then the difference between the vertical coordinate of the mapped coordinate and the vertical coordinate of the reference coordinate is calculated. Subsequently, the horizontal coordinate difference is squared, the vertical coordinate difference is squared, and the two squared results are added together to obtain the offset squared value of that set of corresponding coordinates. The offset squared values of the 400 sets of corresponding coordinates are summed, and the sum is divided by 400 to obtain the average offset squared value. The square root of the average offset squared value is the coordinate offset.
[0092] The coordinate offset, expressed in pixels, characterizes the degree of coordinate deviation of the original pig image from the fixed-viewpoint imaging reference after being mapped by the perspective projection matrix.
[0093] Furthermore, the preset threshold is determined by the data from the fixed-viewpoint imaging reference establishment stage. The specific process is as follows: Under the condition that the installation position of the image acquisition device, lens focal length, shooting direction, and ground calibration area remain unchanged, 30 frames of standard-pose pig images are acquired. For each frame of a standard-pose pig image, spatial pose data is acquired, a perspective projection matrix is constructed, a mapped coordinate set is generated, and its coordinate offset relative to the reference coordinate set is calculated, thus obtaining 30 standard coordinate offsets. The 30 standard coordinate offsets are added together and divided by 30 to obtain the average standard coordinate offset. Then, the difference between each standard coordinate offset and the average is calculated, the 30 differences are squared and summed, the sum is divided by 29, and the square root of the result is taken to obtain the discrete value of the standard coordinate offset.
[0094] The preset threshold is calculated by adding three times the discrete value of the standard coordinate offset to the mean of the standard coordinate offset. This threshold is redefined following the same process when the image acquisition equipment is reinstalled, the lens focal length is changed, or the fixed-viewpoint imaging reference is re-established.
[0095] Furthermore, when determining whether the original pig image has perspective distortion, the coordinate offset corresponding to the current original pig image is compared with a preset threshold. If the coordinate offset is greater than the preset threshold, the original pig image is determined to have perspective distortion, and pixel resampling processing begins. If the coordinate offset is not greater than the preset threshold, the original pig image is determined not to have perspective distortion requiring correction, and the original pig image is directly output as the first corrected image.
[0096] Furthermore, when the coordinate offset exceeds a preset threshold, pixel resampling is performed on the original pig image using a perspective projection matrix. Pixel resampling is performed using an inverse mapping method, that is, taking each target pixel position in the first corrected image as the calculation object, the source pixel position corresponding to that target pixel position in the original pig image is obtained using the inverse transformation relationship of the perspective projection matrix.
[0097] When the source pixel falls within the center of the original pig image, the color value of that pixel center is directly read as the target pixel value. When the source pixel falls between four adjacent pixels, bilinear interpolation is used to determine the target pixel value. The bilinear interpolation process is as follows: read the color values of the four adjacent pixels (top left, top right, bottom left, and bottom right) of the source pixel position; calculate the horizontal and vertical distances from the source pixel position to these four adjacent pixels; determine the weights of the four adjacent pixels based on the distances; then multiply the color values of the four adjacent pixels by their respective weights and sum them to obtain the target pixel value. After performing this processing on all target pixels in the first corrected image, the first corrected image is obtained.
[0098] Specifically, when the coordinate offset is no greater than a preset threshold, pixel resampling driven by the perspective projection matrix is not performed. The pixel coordinates, color values, and texture distribution in the original pig image remain unchanged, and this original pig image is used as the first corrected image.
[0099] Example 4: S3 includes acquiring a first corrected image, performing color space conversion and binarization on the first corrected image to obtain a pathological region on the body surface, the pathological region on the body surface including erythema, hemorrhage, cyanosis and ulceration regions; performing connectivity analysis on the pathological region on the body surface to obtain a set of connected component pixels; if the area of the set of connected component pixels is greater than a preset area threshold, then performing boundary extraction on the set of connected component pixels to obtain the contour of the pathological region; and performing contour sampling on the contour of the pathological region according to a preset sampling interval to obtain the boundary control points of the pathological region.
[0100] In this embodiment, S3 receives the first corrected image output by S2. The first corrected image is either the original pig image after perspective distortion judgment or the original pig image after resampling via a perspective projection matrix. To limit the extraction of pathological areas on the pig's body surface to the pig's body surface area, the pig's main body area mask obtained in the previous step is first called, and pixels located outside the main body area of the pig in the first corrected image are set as non-pathological pixels, so that the fence, ground, feed trough, and background areas are not included in the color determination process.
[0101] Furthermore, when performing color space conversion on the first corrected image, the red, green, and blue channel values of each pixel within the main pig region are read and converted into three color parameters: hue, saturation, and brightness. During the conversion, the red, green, and blue channel values are first compared to determine the maximum and minimum channel values. The brightness is then set to the maximum channel value.
[0102] Specifically, saturation is determined by the difference between the maximum and minimum channel values; when the maximum channel value is 0, the saturation is 0; when the maximum channel value is not 0, the saturation is obtained by dividing the difference between the maximum and minimum channel values by the maximum channel value. Hue is determined based on the color channel where the maximum channel value is located: when the maximum channel value is in the red channel, the hue in the red direction is determined by subtracting the blue channel value from the green channel value; when the maximum channel value is in the green channel, the hue in the green direction is determined by subtracting the red channel value from the blue channel value; when the maximum channel value is in the blue channel, the hue in the blue direction is determined by subtracting the green channel value from the red channel value. Hue is converted to an angle value within the range of 0 degrees to 360 degrees. Thus, each pixel involved in the processing has three determination parameters: hue, saturation, and brightness.
[0103] The pathological color threshold used for binarization was established during the equipment deployment phase. During this phase, sample images were acquired using the same image acquisition equipment, at the same fixed viewing angle, under the same supplemental lighting conditions, and with the same exposure parameters. These sample images included veterinarian-confirmed erythema samples, hemorrhagic spot samples, cyanotic samples, ulcer samples, and healthy body surface samples. After color space conversion of the sample images, the hue, saturation, and brightness values of the erythema pixels, hemorrhagic spot pixels, cyanotic pixels, ulcer pixels, and healthy body surface pixels were extracted.
[0104] Specifically, the color threshold for each type of pathological condition is determined based on the corresponding pathological sample pixels. Taking erythema as an example, the hue values of all erythema sample pixels are summed and divided by the number of erythema sample pixels to obtain the erythema hue mean. The difference between the hue value of each erythema sample pixel and the erythema hue mean is squared, the squared results are summed, the sum is divided by the number of erythema sample pixels minus 1, and the square root of the result is taken to obtain the erythema hue discrete value. The lower limit of the erythema hue threshold is the erythema hue mean minus 3 times the erythema hue discrete value, and the upper limit of the erythema hue threshold is the erythema hue mean plus 3 times the erythema hue discrete value. The saturation and brightness thresholds for erythema are determined using the same method. The hue threshold, saturation threshold, and brightness threshold for hemorrhage, cyanosis, and ulcer areas are also calculated separately for their respective sample pixels.
[0105] Furthermore, to prevent the color of healthy body surfaces from falling into the pathological threshold range, after obtaining the thresholds for various pathological colors, the pixels of healthy body surface samples are substituted into the aforementioned threshold ranges for verification.
[0106] If a pixel in a healthy body surface sample simultaneously falls within the hue, saturation, and brightness thresholds of a certain type of pathological color, the threshold boundaries are narrowed based on the color value range of that healthy body surface sample pixel until the healthy body surface sample pixel no longer simultaneously meets the three threshold conditions for that type of pathological color. If the equipment installation location, supplementary lighting color temperature, lens exposure parameters, or image resolution changes, sample images are re-acquired and the pathological color thresholds are redefined.
[0107] Furthermore, during binarization, each pixel within the main body region of the pig is sequentially evaluated. If the hue, saturation, and brightness of a pixel simultaneously fall within the erythema threshold range, the pixel is marked as an erythema pixel; if they all fall within the hemorrhage threshold range, the pixel is marked as a hemorrhage pixel; if they all fall within the cyanosis threshold range, the pixel is marked as a cyanosis pixel; and if they all fall within the ulcer threshold range, the pixel is marked as an ulcer pixel. Pixels marked as erythema pixels, hemorrhage pixels, cyanosis pixels, or ulcer pixels are assigned the value of pathological pixels in the binary image; the remaining pixels are assigned the value of non-pathological pixels. This yields a binary image of the pathological region on the body surface, which includes erythema, hemorrhage, cyanosis, and ulcer regions.
[0108] Furthermore, after obtaining the binary map of the pathological region on the body surface, connectivity analysis is performed on the pathological region. The connectivity analysis adopts the 8-neighborhood rule, that is, a pathological pixel is considered to be connected to pathological pixels in its upper, lower, left, right and four diagonally adjacent positions.
[0109] During processing, the binary image is scanned sequentially from the top edge to the bottom edge and from the left edge to the right edge. When a pathological pixel is encountered, its adjacent positions that have already been scanned are checked. If no numbered pathological pixel exists in the adjacent position, a new connected component number is assigned to the pathological pixel. If one numbered pathological pixel exists in the adjacent position, that number is assigned to the current pathological pixel. If two or more pathological pixels with different numbers exist in the adjacent position, the merging relationship between these numbers is recorded, and one of these numbers is assigned to the current pathological pixel. After the entire image is scanned, the pixels are uniformly numbered according to the recorded merging relationship, and pathological pixels with the same number form a set of connected component pixels.
[0110] As a preferred embodiment, the area of the connected pixel set is determined by the number of pathological pixels within the set. One pathological pixel corresponds to one pixel area, and the number of pathological pixels within the connected pixel set is the area of the connected pixel set.
[0111] Specifically, the preset area threshold is determined by the background interference region in the healthy pig images. The determination process is as follows: 30 frames of healthy pig images are acquired under the same fixed viewing angle and the same image acquisition parameters. Color space conversion, binarization processing, and connectivity analysis are performed on the 30 frames of healthy pig images sequentially to obtain interference connected regions formed by hair spots, shadow edges, skin wrinkles, and image noise. The interference connected region with the largest area value in each frame of healthy pig image is selected as the interference area of that frame image, resulting in 30 interference area values for the 30 frames. The 30 interference area values are added together and divided by 30 to obtain the mean interference area; then, the difference between each interference area value and the mean interference area is calculated, and the 30 differences are squared and summed. The sum is divided by 29, and the square root of the result is taken to obtain the discrete interference area value. The preset area threshold is the mean interference area plus three times the discrete interference area value. This threshold is recalculated as the fixed viewing angle, resolution, and color threshold change.
[0112] Furthermore, when filtering connected component pixel sets, the area of each connected component pixel set is compared with a preset area threshold. If the area of the connected component pixel set is greater than the preset area threshold, the connected component pixel set proceeds to the boundary extraction step. If the area of the connected component pixel set is not greater than the preset area threshold, the connected component pixel set does not participate in the pathological region contour generation. This process ensures that isolated pixels, reflective spots, and fine hair spots whose areas do not reach the threshold are not included in subsequent boundary control point calculations.
[0113] In this embodiment, when extracting the boundaries of a set of connected pixels with an area greater than a preset area threshold, each pathological pixel in the set is read sequentially, and its eight adjacent positions are checked. If there are non-pathological pixels among the eight adjacent positions, or if there are positions outside the image range, the pathological pixel is determined as a boundary pixel. After checking all pathological pixels in the set, the boundary pixel set is obtained.
[0114] Subsequently, the boundary pixel whose vertical coordinate is closest to the top edge of the image and whose horizontal coordinate is closest to the left edge of the image is selected from the boundary pixel set as the starting boundary point. Adjacent boundary pixels are then searched in a clockwise direction, and the passed boundary pixels are recorded sequentially. The tracing ends when the boundary tracking returns to the starting boundary point and the next adjacent boundary pixel matches the adjacent boundary pixel from the initial stage. The sequentially recorded sequence of boundary pixels constitutes the outline of the pathological region.
[0115] Specifically, the preset sampling interval is determined based on the imaging scale of the pig's main body under a fixed viewpoint. When establishing the fixed viewpoint imaging reference, the lateral span of the rectangle circumscribed by the reference pig's main body area is read. This lateral span is divided by 80 and rounded to the nearest integer to obtain the pixel value of the sampling interval. If the rounded value is less than 4, the sampling interval is 4 pixels. When the image resolution changes, the fixed viewpoint imaging reference changes, or the imaging scale of the pig's main body changes, the sampling interval is re-determined according to the above method.
[0116] When sampling the contour of the pathological region according to a preset sampling interval, the contour length is accumulated clockwise along the boundary pixel sequence, starting from the initial boundary point of the pathological region contour. When two adjacent boundary pixels are horizontally or vertically adjacent, the accumulated length increases by 1 pixel; when two adjacent boundary pixels are diagonally adjacent, the accumulated length increases by √2 pixels. When the accumulated length reaches the preset sampling interval, the boundary pixel at the current position is recorded as the pathological region boundary control point, and the contour length is re-accumulated from that position. After completing one full contour traversal, the pathological region boundary control points are obtained in boundary order.
[0117] Example 5: S4 includes calculating the initial contour deviation between the boundary control points of the pathological region and the preset healthy baseline contour; fitting smooth boundary control points based on the initial contour deviation; if the curvature characteristics of the smooth boundary control points are greater than a preset threshold, then using curvature adjustment to determine the scale deformation; calculating the position deformation based on the relative displacement between the mapped control points corresponding to the scale deformation and the preset healthy baseline contour; and generating a spatial misalignment compensation matrix based on the scale deformation and position deformation.
[0118] In this embodiment, S4 receives the pathological region boundary control points obtained in S3. The pathological region boundary control points are arranged sequentially according to the tracking direction of the pathological region contour, and each control point corresponds to the horizontal and vertical pixel coordinates in the first corrected image. The preset healthy baseline contour is obtained in the fixed-view imaging baseline establishment stage. The establishment process is as follows: under the same fixed viewpoint, images of healthy pigs that have been confirmed to have no pathological manifestations on the body surface are acquired. The healthy pig images are processed in the same way as S1 to S3 to obtain the contour points of the corresponding area of the healthy body surface. Then, the contour of the healthy body surface is sampled at the same sampling interval as the pathological region contour, and the coordinates of each sampling point are recorded to form the preset healthy baseline contour.
[0119] Furthermore, when calculating the initial contour deviation between the boundary control points of the pathological region and the preset healthy baseline contour, the point correspondence between the two is first established.
[0120] The specific processing involves: calculating the center point of the area enclosed by the pathological region boundary control points and the center point of the area enclosed by the preset healthy baseline contour; then, using their respective center points as starting points, sequentially numbering the boundary points according to the contour tracing direction. If the number of pathological region boundary control points differs from the number of healthy baseline contour points, adjustment is made using arc-length resampling. The arc-length resampling process involves: accumulating the pixel distance between adjacent contour points along the contour direction, and dividing the entire contour length equally according to the target number of points, obtaining the corresponding contour point at each division point. After resampling, the pathological region boundary control points and the healthy baseline contour points have the same number of points and the same numbering order.
[0121] Furthermore, after completing the point mapping, the initial contour deviation is calculated for each group of corresponding points. During calculation, the lateral and longitudinal coordinates of the first pathological region boundary control point are read, followed by the lateral and longitudinal coordinates of the first healthy baseline contour point. The lateral deviation is obtained by subtracting the lateral coordinates of the healthy baseline contour point from the lateral coordinates of the pathological region boundary control point; the longitudinal deviation is obtained by subtracting the longitudinal coordinates of the healthy baseline contour point from the longitudinal coordinates of the pathological region boundary control point. The second to the last group of corresponding points are processed in the same manner. The initial contour deviation is composed of the lateral and longitudinal deviations of each group of corresponding points. This initial contour deviation represents the direction and distance of deviation of the pathological region boundary relative to the healthy baseline contour in the first calibrated image coordinate system.
[0122] Furthermore, when fitting smooth boundary control points based on the initial contour deviation, the original coordinates of the pathological region boundary control points and the initial contour deviation are used as the fitting objects.
[0123] The specific processing is as follows: For each pathological region boundary control point, select the three control points preceding it, the control point itself, and the three control points following it as a local fitting point group. When the control point is located at the beginning or end of the contour, add control points from the other end of the contour in the order of the closed contour. Subsequently, number the seven control points in the local fitting point group according to the contour order, and perform quadratic curve fitting on the horizontal and vertical coordinates of the seven control points respectively. During fitting, the point number is used as the fitting parameter to minimize the sum of squared coordinate distances from the seven control points to the fitted curve. The coordinates of the fitted curve at the corresponding number of the current control point are used as the smoothed coordinates of that control point. After completing the above processing for all pathological region boundary control points, smoothed boundary control points are obtained.
[0124] In this embodiment, the curvature characteristics of the smooth boundary control points are determined according to the turning changes of three adjacent points. For any smooth boundary control point, its preceding and following smooth boundary control points are read. First, the direction from the preceding point to the current point is determined, and then the direction from the current point to the following point is determined. Subsequently, the angle between these two directions is calculated, and the distances from the preceding point to the current point and from the current point to the following point are calculated. The average of the two distances is used as a normalized distance benchmark, and the aforementioned angle is divided by the normalized distance benchmark to obtain the curvature characteristics of the current smooth boundary control point. All smooth boundary control points are processed in the same way to obtain the curvature characteristics corresponding to each control point.
[0125] Furthermore, the preset threshold corresponding to the curvature feature is determined during the preset healthy baseline contour establishment stage. Specifically, under the same fixed viewpoint, the same image resolution, and the same contour sampling interval, 30 frames of first-corrected images of healthy pigs are selected; the healthy body surface contour corresponding to the pathological region in each frame is extracted, and the curvature feature of each control point on the healthy contour is calculated according to the aforementioned adjacent 3-point turning change method. The curvature features of all healthy contour control points are added together and then divided by the total number of curvature features to obtain the average healthy curvature.
[0126] Subsequently, the difference between each healthy curvature feature and the mean healthy curvature is calculated. The squares of each difference are summed, and the sum is divided by the total number of curvature features minus 1. The square root of the result is then taken to obtain the discrete value of the healthy curvature. The preset threshold for the curvature feature is the mean healthy curvature plus three times the discrete value of the healthy curvature. This preset threshold is redefined when the fixed viewing angle, image resolution, or sampling interval changes.
[0127] As a preferred embodiment, when the curvature characteristic of a certain smooth boundary control point is greater than a preset threshold, the scale deformation corresponding to that position is determined by curvature adjustment.
[0128] The specific processing is as follows: First, calculate the distance from the center point of the pathological region to the smooth boundary control point, then calculate the distance from the center point of the healthy baseline contour to the corresponding healthy baseline contour point. Divide the distance from the center point of the pathological region to the smooth boundary control point by the distance from the center point of the healthy baseline contour to the corresponding healthy baseline contour point to obtain the basic scale ratio in that direction. Subsequently, divide the curvature feature of the smooth boundary control point by a preset threshold to obtain the curvature adjustment coefficient. Then multiply the basic scale ratio by the curvature adjustment coefficient to obtain the local scale deformation corresponding to the control point. For smooth boundary control points with curvature features not greater than the preset threshold, the curvature adjustment coefficient is set to 1, and the local scale deformation directly uses the basic scale ratio.
[0129] Furthermore, after obtaining the local scale deformation of each smooth boundary control point, the scale deformation along the body axis and the scale deformation perpendicular to the body axis are calculated respectively. The body axis direction is determined by the body posture fitting model obtained in S1. Along the body axis direction, smooth boundary control points located at the anterior and posterior boundaries of the pathological region are selected, their local scale deformation is read, and the arithmetic mean is calculated to obtain the scale deformation along the body axis direction. Along the perpendicular to the body axis direction, smooth boundary control points located at the dorsolateral and ventral lateral boundaries of the pathological region are selected, their local scale deformation is read, and the arithmetic mean is calculated to obtain the scale deformation along the perpendicular to the body axis direction.
[0130] The two scale deformations mentioned above are used to represent the scaling relationship of the pathological region relative to the preset healthy baseline contour in the body axis direction and the direction perpendicular to the body axis.
[0131] Furthermore, when determining the mapping control points based on the scale deformation, the center point of the pathological region is used as the scaling center. For each smooth boundary control point, first calculate the coordinate distance of the point relative to the center point of the pathological region along the body axis, and scale this coordinate distance according to the scale deformation along the body axis; then calculate the coordinate distance of the point relative to the center point of the pathological region along the perpendicular body axis, and scale this coordinate distance according to the scale deformation along the perpendicular body axis. After scaling in both directions, the scaling results are converted back to the horizontal and vertical coordinates of the first corrected image to obtain the mapping control point corresponding to the smooth boundary control point. After completing this process for all smooth boundary control points, a set of mapping control points is formed.
[0132] Furthermore, the positional deformation is calculated based on the relative displacement between the mapped control point and the preset health baseline profile.
[0133] Specifically, the process involves: reading each mapped control point and its corresponding healthy baseline contour point in numerical order; subtracting the lateral coordinates of the mapped control point from the lateral coordinates of the corresponding healthy baseline contour point to obtain the lateral displacement of that set of points; subtracting the longitudinal coordinates of the mapped control point from the longitudinal coordinates of the corresponding healthy baseline contour point to obtain the longitudinal displacement of that set of points. The lateral displacements are summed and divided by the number of corresponding points to obtain the lateral position deformation; the longitudinal displacements are summed and divided by the number of corresponding points to obtain the longitudinal position deformation. The lateral and longitudinal position deformations together represent the coordinate amount by which the pathological region still needs to be translated relative to the preset healthy baseline contour after scaling.
[0134] Furthermore, when generating the spatial misalignment compensation matrix, the scale deformation variables along the body axis, the scale deformation variables perpendicular to the body axis, the lateral position deformation variables, and the longitudinal position deformation variables are written into the affine transformation parameters. Since the scale deformation variables are obtained in the body axis and perpendicular body axis directions, a local coordinate relationship is first established with the center point of the pathological region as the origin during generation, and the image coordinates are transformed to the local coordinates corresponding to the body axis direction; then, body axis scaling and perpendicular body axis scaling are applied to these local coordinates; after scaling, the lateral position deformation variables and the longitudinal position deformation variables are added to the image coordinates as translation amounts.
[0135] The spatial misalignment compensation matrix formed by the above processing can transform the coordinates of the pathological area in the first corrected image to the position corresponding to the preset healthy baseline contour.
[0136] In this embodiment, the spatial misalignment compensation matrix specifically targets the pathological region and its adjacent texture regions. During compensation, each pixel within the pathological region is first transformed to local coordinates along the body axis relative to the center point of the pathological region. Then, its coordinates are scaled according to the body axis and perpendicular body axis scale variables. Subsequently, it is transformed back to the first corrected image coordinates, and horizontal and vertical position variables are superimposed. After processing by this matrix, the boundary control points of the pathological region correspond to the preset healthy baseline contour in terms of coordinate position and contour scale.
[0137] Example 6: S5 includes acquiring the edge features of the pathological region on the body surface in the first corrected image, calculating a spatial misalignment compensation matrix based on the edge features; processing the pathological region on the body surface using the spatial misalignment compensation matrix to obtain a pixel mapping set, determining and adjusting the grayscale interpolation distribution based on the pixel mapping set to obtain contour alignment data; updating the pathological region on the body surface in the first corrected image using the contour alignment data, and performing affine compensation processing on the pathological region on the body surface in the first corrected image using the spatial misalignment compensation matrix to align the pathological region on the body surface with the healthy baseline contour to obtain the second corrected image.
[0138] In this embodiment, step S5 uses the first corrected image and the pathological region on the body surface as processing objects. The first corrected image has already undergone perspective distortion judgment or perspective correction processing, and the pathological region on the body surface is obtained through binarization and connected component analysis in step S3. To enable the pathological region on the body surface to complete spatial position correction according to the healthy baseline contour, the edge features of the pathological region are first extracted from the first corrected image. Edge features include the pixel coordinates of the pathological region boundary, the order of boundary points, the direction of the boundary tangent, the direction of the boundary normal, the boundary grayscale change value, and the center point of the pathological region.
[0139] Furthermore, when acquiring edge features, the set of connected pixels in the pathological region of the body surface is first read. For any pixel in the connected region, its eight neighboring positions are checked; if a non-pathological pixel exists in one of the eight neighboring positions, that pixel is identified as a boundary pixel. After completing the check of all pixels, the set of boundary pixels of the pathological region is obtained.
[0140] Subsequently, the boundary pixel whose vertical coordinate is closest to the top edge of the image and whose horizontal coordinate is closest to the left edge of the image is selected from the boundary pixel set as the starting point. Adjacent boundary pixels are searched sequentially in a clockwise direction, and the order of the boundary pixels is recorded. When the tracing path returns to the starting point, the closed boundary of the pathological region is obtained.
[0141] Furthermore, after obtaining the closed boundary, the center point of the pathological region is calculated. Specifically, the horizontal coordinates of all pixels within the pathological region are summed and then divided by the number of pixels in the pathological region to obtain the horizontal coordinates of the center point; the vertical coordinates of all pixels within the pathological region are summed and then divided by the number of pixels in the pathological region to obtain the vertical coordinates of the center point. This center point serves as the transformation reference point for subsequent scaling, coordinate mapping, and affine compensation.
[0142] Furthermore, for any boundary point on the closed boundary, the preceding and following boundary points are read. The direction from the preceding boundary point to the following boundary point is taken as the boundary tangent direction of that boundary point. The boundary tangent direction is rotated 90 degrees to obtain the boundary normal direction. Subsequently, the grayscale value of one pixel inside the pathological area and one pixel outside the pathological area are read along the normal direction, and the boundary grayscale change value is obtained by subtracting the outer grayscale value from the inner grayscale value. The above processing is performed on all boundary points on the closed boundary to form edge feature data containing coordinates, arrangement order, tangent direction, normal direction, and grayscale change value.
[0143] Furthermore, when calculating the spatial misalignment compensation matrix based on edge features, boundary control points are first determined within the pathological region boundary. Specifically, the distance between adjacent boundary points is accumulated along the closed boundary. When adjacent boundary points are adjacent laterally or vertically, a distance of 1 pixel is accumulated; when adjacent boundary points are adjacent diagonally, a distance of √2 pixels is accumulated. Every time the accumulated distance reaches the sampling interval determined in step 4, the boundary point at the current position is selected as one boundary control point. This yields the pathological region boundary control points arranged in the order of the closed boundaries.
[0144] In this embodiment, a preset healthy baseline contour is used to form healthy baseline control points at the same sampling interval. If the number of control points at the boundary of the pathological region is inconsistent with the number of healthy baseline control points, the side with more control points is resampled according to the contour length until the number of control points is consistent. After resampling, the control points at the boundary of the pathological region correspond one-to-one with the healthy baseline control points in a clockwise order.
[0145] Furthermore, when calculating the spatial misalignment compensation matrix, three sets of non-collinear corresponding control points are selected as affine solution points. The first set of corresponding control points is the front boundary point of the pathological region along the body axis and its corresponding healthy reference point; the second set is the rear boundary point of the pathological region along the body axis and its corresponding healthy reference point; and the third set is the boundary point of the pathological region along the direction perpendicular to the body axis that is farthest from the center point and its corresponding healthy reference point. Each set of corresponding control points includes the current coordinates of the pathological region and the target coordinates of the healthy reference point.
[0146] Furthermore, when solving for the affine parameters, the horizontal and vertical coordinates of the current control point in the pathological region are substituted into the affine transformation relation, so that after transformation, they are equal to the horizontal and vertical coordinates of the corresponding healthy baseline control point, respectively. One set of corresponding control points generates two equations, and three sets of corresponding control points generate six equations.
[0147] Six affine parameters were obtained by solving linear equations: horizontal scaling parameter, vertical scaling parameter, horizontal shearing parameter, vertical shearing parameter, horizontal translation parameter, and vertical translation parameter. These six affine parameters were then incorporated into a matrix structure to obtain the spatial misalignment compensation matrix. This matrix was used to transform the pixel coordinates of pathological areas on the body surface in the first corrected image to their corresponding positions on the healthy baseline contour.
[0148] As a preferred embodiment, when processing the pathological region of the body surface using a spatial misalignment compensation matrix, the horizontal and vertical coordinates of each pixel within the pathological region are read one by one. These pixel coordinates are then substituted into the spatial misalignment compensation matrix to obtain the target horizontal and vertical coordinates of the pixel after affine transformation. Each original pixel coordinate and its target coordinate form a pixel mapping relationship. After processing all pixels within the pathological region, a pixel mapping set is obtained. The pixel mapping set records the correspondence between each pixel within the pathological region and its original position in the first corrected image to its contour-aligned position.
[0149] Furthermore, when determining the grayscale interpolation distribution based on the pixel mapping set, a reverse sampling method is used. Specifically, taking the target pixel position to be assigned in the target image as a reference, the source coordinates of the target pixel position in the first corrected image are calculated in reverse according to the inverse relationship of the spatial misalignment compensation matrix. If the source coordinates fall on an integer pixel position, the grayscale value of that integer pixel is directly read as the grayscale value of the target pixel. If the source coordinates fall between four integer pixels, the grayscale values of the four adjacent pixels (top left, top right, bottom left, and bottom right) are read; then the distances from the source coordinates to the centers of the four adjacent pixels are calculated in the horizontal and vertical directions, and the interpolation weights of the four adjacent pixels are determined based on the distances; the grayscale values of the four adjacent pixels are multiplied by their corresponding interpolation weights and then summed to obtain the grayscale value of the target pixel.
[0150] When the first corrected image is a color image, the red channel, green channel and blue channel are calculated according to the above process to obtain the color value of the target pixel.
[0151] Furthermore, the grayscale interpolation distribution is adjusted around the boundary of the compensated pathological region.
[0152] Specifically, first, the grayscale values of three consecutive pixels inside the boundary of the compensated pathological region are read, and then the grayscale values of three consecutive pixels on the healthy body surface outside the boundary are read. The arithmetic mean of the three grayscale values inside the boundary is calculated to obtain the average grayscale value inside the boundary; the arithmetic mean of the three grayscale values outside the boundary is calculated to obtain the average grayscale value outside the boundary; the average grayscale value inside the boundary is subtracted from the average grayscale value outside the boundary to obtain the boundary grayscale correction amount. Subsequently, grayscale transition processing is performed within a three-pixel band extending from the compensated boundary into the pathological region: three-quarters of the boundary grayscale correction amount is added at a position one pixel from the boundary, half of the boundary grayscale correction amount is added at a position two pixels from the boundary, and one-quarter of the boundary grayscale correction amount is added at a position three pixels from the boundary. This processing creates a continuous transition between the grayscale values at the edge of the compensated pathological region and the grayscale values of the adjacent healthy body surface.
[0153] Furthermore, after adjusting the grayscale interpolation distribution, contour alignment data is obtained. This data includes the target pixel coordinates of the compensated pathological region, the grayscale value of each target pixel, the color value of each target pixel, the coordinates of the compensated boundary control points, and the correspondence between the compensated boundary control points and the healthy baseline control points. The contour alignment data is used to replace the pixel content of the original pathological region in the first corrected image, while preserving the grayscale and color information of the pathological texture at the compensated location.
[0154] In this embodiment, when updating the pathological area on the body surface in the first corrected image using contour alignment data, the area to be updated is first determined. The area to be updated is formed by extending the contour of the original pathological area on the body surface outward by 3 pixels. Pixels within the area to be updated are cleared, and the cleared pixel values are filled in by neighboring healthy surface pixels through neighborhood interpolation.
[0155] Subsequently, the target pixels in the contour alignment data are written to the area to be updated according to their target coordinates. If two or more target pixels correspond to the same target coordinate, all pixel values corresponding to that coordinate are read, and the arithmetic mean is taken as the pixel value of that target coordinate. If there are unassigned pixels between adjacent target coordinates, the pixels that have been assigned values in the eight adjacent positions around the unassigned pixel are read, and the arithmetic mean of their grayscale or color values is taken and added to the unassigned pixel.
[0156] Furthermore, when performing affine compensation processing on the pathological region of the body surface using a spatial misalignment compensation matrix, each pixel within the pathological region is used as the transformation object, and coordinate transformation is performed according to the six affine parameters in the matrix. The horizontal and vertical coordinate scaling parameters are used to adjust the projection size of the pathological region in the horizontal and vertical directions, the horizontal and vertical shearing parameters are used to adjust the tilt difference of the pathological region boundary relative to the healthy baseline contour, and the horizontal and vertical translation parameters are used to move the pathological region to the corresponding position on the healthy baseline contour. The boundary control points after affine compensation are aligned with the healthy baseline control points according to the aforementioned numbering relationship.
[0157] Furthermore, the alignment results are recorded using the coordinate differences between the compensated boundary control points and the healthy baseline control points. Specifically, the compensated boundary control points and their corresponding healthy baseline control points are read one by one, and the differences in their horizontal and vertical coordinates are calculated. These differences are recorded as alignment residuals. The alignment residuals of all corresponding points are stored along with the second corrected image and used to determine the corresponding pixel relationship between the pathological region and the healthy baseline image during subsequent grayscale difference calculations.
[0158] After completing the above updates, a second corrected image is obtained. In the second corrected image, the non-surface pathological areas retain the pixel content of the first corrected image; the surface pathological areas undergo position updates, grayscale interpolation, and boundary transition processing based on the spatial misalignment compensation matrix and contour alignment data.
[0159] Example 7: S6 includes acquiring a second corrected image and a preset health baseline image; performing spatial registration processing on the second corrected image and the preset health baseline image using an affine transformation algorithm to obtain a registered image pair; extracting the gray-level difference of corresponding pixel positions through pixel-by-pixel subtraction based on the registered image pair to obtain an initial gray-level difference matrix; performing binarization segmentation processing on the initial gray-level difference matrix using Otsu's method to determine the connected components of the abnormal region; if the number of pixels in the connected components of the abnormal region is greater than a preset threshold, extracting the edge contour pixels of the connected components of the abnormal region using an edge detection algorithm to determine the feature alignment coordinates of the pathological region on the body surface.
[0160] In this embodiment, S6 takes the second corrected image and the preset health baseline image as input. The second corrected image is output by S5, in which the pathological areas on the body surface have been affine compensated according to the contour of the health baseline. The preset health baseline image is generated during the fixed-viewpoint imaging baseline establishment stage, and its acquisition conditions are consistent with those of the second corrected image, including the installation position of the image acquisition device, lens focal length, image resolution, supplementary lighting conditions, and acquisition area. The preset health baseline image is obtained from a healthy pig image after perspective correction, body contour extraction, and body surface region normalization processing, and is used as a reference image for grayscale difference calculation.
[0161] Furthermore, before spatial registration, the second calibration image and the preset health baseline image are converted to the same grayscale representation. If the second calibration image is a color image, the red, green, and blue channel values are read pixel by pixel. The red channel value is multiplied by 0.299, the green channel value by 0.587, and the blue channel value by 0.114. The three products are then added together to obtain the grayscale value of the pixel. The preset health baseline image is processed in the same way. If the input image is already a grayscale image, the original grayscale value is read directly.
[0162] After this processing is completed, both the second corrected image and the preset health baseline image participate in subsequent calculations with grayscale values between 0 and 255.
[0163] Furthermore, when using the affine transformation algorithm to spatially register the second corrected image with the preset health reference image, registration control points are first selected.
[0164] Specifically, the registration control points in the second corrected image are determined by the body posture fitting results and the compensation results for pathological areas on the body surface obtained in the previous steps, including the body center point, the anterior point of the body axis, the posterior point of the body axis, the midpoint of the dorsal side, and the midpoint of the ventral side. The corresponding registration control points in the preset healthy reference image are pre-recorded by a fixed-view imaging reference. The above control points are established according to the same anatomical position, that is, the body center point in the second corrected image corresponds to the body center point in the preset healthy reference image, the anterior point of the body axis in the second corrected image corresponds to the anterior point of the body axis in the preset healthy reference image, and the remaining control points correspond in the same way.
[0165] Furthermore, when solving for the affine transformation parameters, three sets of control points that are not on the same straight line are selected from the corresponding control points.
[0166] Specifically, each set of control points includes the coordinates of the current point in the second corrected image and the coordinates of the target point in the preset health baseline image. The horizontal and vertical coordinates of the current point are substituted into an affine transformation relationship, such that the transformed horizontal coordinates are equal to the horizontal coordinates of the target point, and the transformed vertical coordinates are equal to the vertical coordinates of the target point. One set of control points forms two linear equations, and three sets of control points form six linear equations. Solving these linear equations yields the horizontal scaling parameter, vertical scaling parameter, horizontal shearing parameter, vertical shearing parameter, horizontal translation parameter, and vertical translation parameter. These six parameters constitute the affine transformation relationship from the second corrected image to the preset health baseline image.
[0167] In this embodiment, after obtaining the affine transformation relationship, the second correction image is inversely mapped using the pixel coordinates of the preset health baseline image as the target coordinates.
[0168] Specifically, during processing, the target pixel positions in the preset health reference image are read one by one. Based on the inverse affine transformation, the source pixel position of the target pixel in the second corrected image is calculated. When the source pixel position falls within integer pixel coordinates, the corresponding grayscale value is directly read as the target pixel grayscale value. When the source pixel position falls between four adjacent integer pixels, the grayscale values of the top-left, top-right, bottom-left, and bottom-right pixels of that source pixel position are read. Interpolation weights are determined based on the horizontal and vertical distances from the source pixel position to the centers of the four pixels. The four grayscale values are then multiplied by their respective weights and summed to obtain the target pixel grayscale value. After completing the above processing for all pixels within the target coordinate range, a registered second corrected image with the same size and coordinate reference as the preset health reference image is obtained. The registered second corrected image and the preset health reference image together constitute a registered image pair.
[0169] Furthermore, when extracting the grayscale difference based on the registered image pair, the calculation is performed point by point according to the same pixel coordinates. For any pixel position, the grayscale value of the registered second corrected image at that position is read, and the grayscale value of the preset health reference image at that position is also read; the grayscale value of the registered second corrected image is subtracted from the grayscale value of the preset health reference image, and the absolute value of the subtraction result is taken to obtain the grayscale difference value of that pixel position.
[0170] The process involves performing the same operation on all corresponding pixel positions in a scanning order from the top edge to the bottom edge and from the left edge to the right edge of the image. The resulting grayscale differences are then arranged according to the original pixel coordinates to form an initial grayscale difference matrix. Each element in this matrix corresponds to a pixel position, and its value represents the grayscale difference between the current body surface image and the healthy baseline image at that position.
[0171] Furthermore, the Otsu method is used to perform binarization segmentation on the initial gray-level difference matrix. During processing, the number of pixels corresponding to each gray-level difference value from 0 to 255 in the initial gray-level difference matrix is first counted to form a gray-level difference histogram.
[0172] Subsequently, each grayscale difference from 0 to 255 is used as a candidate segmentation threshold. For any candidate segmentation threshold, pixels with grayscale differences no greater than the threshold are assigned to the baseline difference group, and pixels with grayscale differences greater than the threshold are assigned to the abnormal difference group. The percentage of pixels in the baseline and abnormal difference groups is calculated, and the average grayscale difference of each group is calculated. The difference between the average grayscale differences of the two groups is then calculated, squared, and multiplied by the percentage of pixels in each group to obtain the inter-class discrimination value corresponding to the candidate segmentation threshold. After traversing all candidate segmentation thresholds from 0 to 255, the candidate segmentation threshold with the largest inter-class discrimination value is selected as the Otsu method segmentation threshold.
[0173] As a preferred embodiment, the initial gray-level difference matrix is binarized according to the Otsu method segmentation threshold. Pixels with gray-level differences greater than the Otsu method segmentation threshold are marked as abnormal pixels, and pixels with gray-level differences not greater than the Otsu method segmentation threshold are marked as background pixels, thereby obtaining an abnormal region binary map. This abnormal region binary map is used to separate regions from the gray-level difference matrix that have gray-level differences from the healthy baseline image.
[0174] Furthermore, when determining the connected components of the anomalous regions, an 8-neighborhood connectivity analysis is performed on the binary image of the anomalous regions. The scanning order is from the top edge of the image to the bottom edge of the image, and from the left edge of the image to the right edge of the image.
[0175] When an abnormal pixel is detected, its eight neighboring locations that have already been scanned are checked. If no numbered abnormal pixel exists in the neighboring locations, a new connected component number is assigned to the current abnormal pixel. If one numbered abnormal pixel exists in the neighboring locations, that number is assigned to the current abnormal pixel. If two or more abnormal pixels with different numbers exist in the neighboring locations, the merging relationship between these numbers is recorded, and all numbers with merging relationships are unified into the same number after the entire image is scanned. Ultimately, abnormal pixels with the same number constitute one connected component of the abnormal region.
[0176] Furthermore, the preset threshold number is determined by the gray-level difference interference components of the healthy samples. To determine this, 30 frames of second-calibrated images of healthy pigs are acquired under the same fixed viewpoint, image resolution, registration control point rules, and Otsu's segmentation process, and each frame is paired with a preset healthy baseline image to form a registration image pair. For each frame of the second-calibrated image of healthy pigs, spatial registration, pixel-by-pixel subtraction, Otsu's binarization, and 8-neighborhood connectivity analysis are performed sequentially to obtain the gray-level difference interference connected components in the healthy samples. The gray-level difference interference connected component with the largest number of pixels is selected from each frame of the second-calibrated image of healthy pigs, and its pixel count is recorded, resulting in 30 interference pixel count values across the 30 frames. The 30 interference pixel count values are summed and divided by 30 to obtain the mean number of interference pixels. Then, the difference between each interference pixel count value and the mean number of interference pixels is calculated, and the 30 differences are squared and summed. The sum is divided by 29, and the square root of the result is taken to obtain the discrete value of the number of interference pixels.
[0177] The preset threshold is calculated by adding three times the discrete value of the number of interfering pixels to the average number of interfering pixels. This preset threshold is redefined when the fixed viewing angle, resolution, lighting conditions, registration control point rules, or preset health baseline image change.
[0178] Furthermore, when judging the connected components of abnormal regions, the number of abnormal pixels contained in each connected component is counted. If the number of pixels in a connected component of an abnormal region is greater than a preset threshold, then that connected component of the abnormal region is included in the edge contour extraction. If the number of pixels in a connected component of an abnormal region is not greater than the preset threshold, then that connected component of the abnormal region is not included in the feature alignment coordinate determination.
[0179] When extracting edge contour pixels of connected components in abnormal regions using the edge detection algorithm, each abnormal pixel in the connected component of the abnormal region is read sequentially, and its eight adjacent positions are checked. If background pixels or positions exceeding the image boundary exist among the eight adjacent positions, the abnormal pixel is identified as an edge contour pixel. After checking all abnormal pixels, a set of edge contour pixels is obtained.
[0180] Subsequently, the pixel closest to the top edge of the image in vertical coordinate and closest to the left edge in horizontal coordinate is selected from the set of edge contour pixels as the starting contour point. Adjacent edge contour pixels are searched one by one in a clockwise direction, and the search order is recorded. When the search path returns to the starting contour point, the edge contour pixels are obtained in contour order.
[0181] Furthermore, when determining the feature alignment coordinates of the pathological area on the body surface, the boundary coordinates of the abnormal area are first calculated based on the edge contour pixels. The horizontal coordinates of all edge contour pixels are read, and the smallest horizontal coordinate is taken as the left boundary coordinate, and the largest horizontal coordinate is taken as the right boundary coordinate; the vertical coordinates of all edge contour pixels are read, and the smallest vertical coordinate is taken as the upper boundary coordinate, and the largest vertical coordinate is taken as the lower boundary coordinate.
[0182] Then, the center coordinates of the abnormal region are calculated. The horizontal coordinates of all edge contour pixels are added together and then divided by the number of edge contour pixels to obtain the center horizontal coordinates. The vertical coordinates of all edge contour pixels are added together and then divided by the number of edge contour pixels to obtain the center vertical coordinates.
[0183] Specifically, to ensure that the subsequent cropped pathological texture feature map includes the edges of abnormal regions, texture cropping region coordinates are formed based on the boundary coordinates of the abnormal regions. The texture cropping region coordinates are obtained by extending the left, right, upper, and lower boundary coordinates outwards by a fixed pixel width. The fixed pixel width is determined during the fixed-viewpoint imaging benchmark establishment stage, taking the integer value obtained by dividing the horizontal span of the circumscribed rectangle of the main pig region in the preset healthy benchmark image by 100 and rounding it off; if the resulting integer is less than 3, the fixed pixel width is 3 pixels. If the extended cropping region coordinates exceed the image boundary, they are confined to the image boundary. The feature alignment coordinates of the pathological region on the body surface are formed by the center coordinates of the abnormal region, the boundary coordinates of the abnormal region, and the texture cropping region coordinates.
[0184] Example 8: S7 includes obtaining a standard-size pixel matrix, which is obtained by resampling a second corrected image; extracting texture data from the standard-size pixel matrix to generate a pathological texture feature map; reducing the dimensionality of the pathological texture feature map to obtain a dimensionality-reduced pathological feature vector, and truncating the dimensionality-reduced pathological feature vector to obtain a target pathological feature vector; inputting the target pathological feature vector into a preset classification model to obtain a probability set, and determining the African swine fever infection severity assessment level based on the probability set.
[0185] In this embodiment, S7 receives the feature alignment coordinates output by S6 and determines the texture clipping region in the second corrected image accordingly. The feature alignment coordinates include the coordinates of the center of the abnormal region, the coordinates of the boundary of the abnormal region, and the coordinates of the texture clipping region.
[0186] During processing, the corresponding pixels in the second corrected image are read according to the coordinates of the texture clipping region to form an image block to be resampled. This image block to be resampled contains the pathological area on the body surface and its adjacent edge areas, and is used to preserve the grayscale changes, boundary changes and local texture changes of erythema, hemorrhage, cyanosis or ulcer areas.
[0187] Furthermore, when obtaining a standard-size pixel matrix, the input layer size of the preset classification model is used as the target size.
[0188] In this embodiment, the target size is 224 rows and 224 columns. If the number of horizontal or vertical pixels in the image block to be resampled is different from 224, resampling is performed. During resampling, the horizontal range of the image block to be resampled is divided into 224 target column positions, and the vertical range is divided into 224 target row positions. For each target pixel in the standard-size pixel matrix, the source position of the target pixel in the image block to be resampled is calculated based on its target row number and target column number. This source position is determined by the left boundary coordinates, top boundary coordinates, horizontal span, vertical span, target column number, and target row number of the image block to be resampled.
[0189] Furthermore, when the source position falls within an integer pixel position of the image block to be resampled, the pixel value of that integer pixel is directly read as the target pixel value. When the source position falls between four adjacent integer pixels, the pixel values of the top-left, top-right, bottom-left, and bottom-right pixels of that source position are read; then the distances from the source position to the center of these four pixels in the horizontal and vertical directions are calculated, and four interpolation weights are assigned based on the distances; finally, the four pixel values are multiplied by their corresponding weights and then summed to obtain the target pixel value.
[0190] When the second corrected image is a color image, the red, green, and blue channels are calculated as described above. After processing all target pixels in 224 rows and 224 columns, a standard-sized pixel matrix is obtained.
[0191] Furthermore, when extracting texture data from a standard-sized pixel matrix, a grayscale matrix is first generated. For each pixel in the standard-sized pixel matrix, the red channel value, green channel value, and blue channel value are read. The red channel value is multiplied by 0.299, the green channel value by 0.587, and the blue channel value by 0.114. The three products are then added together to obtain the grayscale value of the pixel.
[0192] If the standard-size pixel matrix itself is a grayscale matrix, its grayscale values are read directly. Then, the grayscale values are divided by 255 to obtain normalized grayscale values, so that the input values fall within a fixed range of 0 to 1.
[0193] As a preferred embodiment, the texture data consists of grayscale distribution data, edge variation data, and neighborhood difference data. The grayscale distribution data directly uses a normalized grayscale matrix to represent the light and dark states of the pathological region.
[0194] The edge change data is calculated using the grayscale difference between adjacent pixels: For any pixel, the grayscale values of its left and right pixels are read, subtracted, and the absolute value is taken to obtain the horizontal grayscale change value; then, the grayscale values of its upper and lower pixels are read, subtracted, and the absolute value is taken to obtain the vertical grayscale change value; the horizontal and vertical grayscale change values are added together to obtain the edge change value of that pixel. Pixels located at the matrix boundary are supplemented with their neighboring valid pixels to complete the calculation.
[0195] Specifically, the neighborhood difference data is calculated within a 3-row, 3-column neighborhood. For any central pixel, the grayscale values of its eight neighboring pixels are read, and the absolute value of the difference between the grayscale values of each of the eight neighboring pixels and the grayscale value of the central pixel is calculated. These eight absolute differences are then summed and divided by 8 to obtain the neighborhood difference value of the central pixel. This process is performed on all pixels in 224 rows and 224 columns to form a neighborhood difference matrix.
[0196] Furthermore, when generating the pathological texture feature map, grayscale distribution data, edge variation data, and neighborhood difference data are synthesized using the same pixel coordinates. Specifically, the normalized grayscale value, edge variation value, and neighborhood difference value are recorded simultaneously at the same pixel location to form a 3-channel texture representation. After all pixels in rows 224 and columns 224 have undergone 3-channel synthesis, the pathological texture feature map is obtained. This pathological texture feature map serves as the input for subsequent feature vectorization and dimensionality reduction processing.
[0197] Before dimensionality reduction of the pathological texture feature map, it is first expanded into an original pathological feature sequence. The expansion order is to read from row 1 to row 224 sequentially, and within each row, to read from column 1 to column 224 sequentially; at the same pixel position, the normalized gray value, edge variation value, and neighborhood difference value are read sequentially. After expansion in this order, an original pathological feature sequence with a length of 150528 is obtained.
[0198] Furthermore, the dimensionality reduction mapping matrix is established during the training phase of the pre-defined classification model. During establishment, each pathological texture feature map in the training samples is converted into a training feature sequence according to the same unfolding order.
[0199] Subsequently, the arithmetic mean of each feature position across all training samples is calculated, and this arithmetic mean is subtracted from the value of each training sample at that feature position to obtain a centered training feature sequence. Feature directions are then calculated based on the centered training feature sequence and arranged in descending order of variance. The first 512 feature directions are used to form a dimensionality reduction mapping matrix, and the arithmetic mean of each feature position is saved along with the dimensionality reduction mapping matrix.
[0200] In this embodiment, when actually processing the current pathological texture feature map, the original pathological feature sequence is first centered according to the arithmetic mean saved during the training phase, that is, the value of each position in the current original pathological feature sequence is subtracted from the arithmetic mean of the corresponding position during the training phase.
[0201] After centering, the original pathological feature sequence is projected onto 512 feature directions. Each projected value is obtained by multiplying each element in the centered feature sequence by its corresponding weight in the feature direction and then summing the results. The 512 projected values are arranged in order of feature directions to form a reduced-dimensional pathological feature vector.
[0202] Furthermore, when truncating the dimensionality-reduced pathological feature vectors, the target dimension determined during the training phase is followed. In this embodiment, the target dimension is 128.
[0203] During processing, elements 1 to 128 of the reduced-dimensional pathological feature vector are retained, while elements 129 to 512 are deleted to obtain the target pathological feature vector. The target dimension is determined during the training phase. The determination process is as follows: the classifier is trained using feature vectors of 64, 128, 256, and 512 dimensions respectively, and the number of correct classifications for each dimension is counted on the same validation sample set; the dimension corresponding to the maximum number of correct classifications is taken as the target dimension. If two dimensions have the same maximum number of correct classifications, the dimension with the smaller value is selected as the target dimension. When retraining the preset classification model, the target dimension is re-determined according to the above process.
[0204] Furthermore, when the target pathological feature vector is input into the preset classification model, the preset classification model reads 128 feature values in the order of vector elements.
[0205] Specifically, the pre-defined classification model includes an input layer, a feature mapping layer, and an output layer. The input layer receives a 128-dimensional target pathological feature vector; the feature mapping layer multiplies the input features with the weights determined during the training phase, sums the products, and adds a bias value to obtain the input value for each hidden node; each hidden node then undergoes a nonlinear transformation to generate intermediate features; the output layer maps the intermediate features into four output values. These four output values correspond to no obvious abnormalities, suspected mild infection, moderate infection, and severe infection, respectively.
[0206] To obtain the probability set, the four output values were normalized. The process involved first performing exponential operations on each of the four output values, then summing the results to obtain the normalized denominator. Subsequently, the probability value corresponding to each output value was divided by this normalized denominator. The four probability values were arranged in the order of no obvious abnormalities, suspected mild infection, moderate infection, and severe infection, forming a probability set, and the sum of the four probability values was 1.
[0207] Furthermore, when determining the assessment level of African swine fever infection based on the probability set, four probability values in the probability set are read and the magnitudes of the four probability values are compared.
[0208] The infection severity level corresponding to the highest probability value is used as the African swine fever infection severity assessment level of the current pathological texture feature map. When two or more probability values are equal and both are the maximum value, the level ranked first is selected as the output level in the order of severe infection, moderate infection, suspected mild infection, and no obvious abnormalities. Thus, step 7 can convert the pathological area on the body surface in the second corrected image into a standard-sized pixel matrix, and then form a pathological texture feature map from the texture data. After dimensionality reduction, truncation, and classification processing, the determined infection severity assessment level is output.
[0209] Example 9: Figure 2 This is a structural block diagram of the local terminal of an exemplary electronic device (machine) of the present invention; as shown... Figure 2 As shown, the electronic device of the present invention includes a processor 11, a memory 12, a storage space 13 for storing program code, and program code 14 for executing the method steps according to the present invention. The program code 14 for executing the method steps according to the present invention is used to execute the above-described control logic.
[0210] Figure 3 This is a structural block diagram of the network end of an exemplary electronic device of the present invention; as shown below. Figure 3 As shown, the present invention also provides an electronic device (machine), which may include at least one processor 210, at least one memory 230 communicatively connected to the processor, and a communication bus 240 and a communication interface 220 connecting different system components (including the memory 230 and the processor 210). The processor 210, the memory 230 and the communication interface 220 are connected through the communication bus 240 and communicate with each other. The communication interface 220 is used for data interaction with external devices. The memory 230 stores a machine-executable program that can be executed by the processor, and the processor 210 can execute the above-mentioned control logic by calling the machine-executable program.
[0211] Communication bus 240 represents one or more of several bus architectures, including a memory bus or memory controller, peripheral bus, graphics acceleration port, processor, or local bus using any of the various bus architectures. Examples of these architectures include, but are not limited to, Industry Standard Architecture (ISA) buses, Micro Channel Architecture (MAC) buses, Enhanced ISA buses, Video Electronics Standards Association (VESA) local buses, and Peripheral Component Interconnect (PCI) buses.
[0212] Electronic devices typically include a variety of computer system readable media, which can be any available media that can be accessed by the electronic device, including volatile and non-volatile media, and removable and non-removable media.
[0213] Memory 230 may include computer system readable media in the form of volatile memory, such as random access memory (RAM) and / or cache memory. The electronic device may further include other removable / non-removable, volatile / non-volatile computer system storage media. Memory 230 may include at least one program product having a set (e.g., at least one) of program modules configured to perform the control logic described above.
[0214] A program / utility having a set (at least one) of program modules can be stored in memory 230. Such program modules include, but are not limited to, an operating system, one or more applications, other program modules, and program data. Each or some combination of these examples may include an implementation of a network environment.
[0215] Machine-executable programs for performing this invention can be written in one or more programming languages or a combination thereof. These programming languages include object-oriented programming languages such as Java, C++, and Python, and may also include specialized engineering languages such as R. The program code can be executed entirely on the user's computer, partially on the user's computer, as a standalone software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In cases involving remote computers, the remote computer can be connected to the user's computer via any type of network—including a local area network (LAN) or a wide area network (WAN)—or can be connected to an external computer (e.g., via the Internet using an Internet service provider).
[0216] The present invention also discloses a storage medium on which a machine-executable program as described above is stored.
[0217] The aforementioned storage medium may be any combination of one or more computer-readable media. Computer-readable media may be, for example, computer-readable signal media or computer-readable storage media. Computer-readable storage media include, but are not limited to, electrical, magnetic, optical, electromagnetic, infrared, or semiconductor systems, apparatuses, or devices, or any combination thereof. More specific examples of computer-readable storage media (a non-exhaustive list) include: electrical connections having one or more wires, portable computer disks, hard disks, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM), or flash memory, optical fiber, portable compact disk read-only memory (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination thereof. In this invention, a computer-readable storage medium may be, for example, any tangible medium containing or storing a program that can be used by or in conjunction with an instruction execution system, apparatus, or device.
[0218] Computer-readable signal media may include data signals propagated in baseband or as part of a carrier wave, carrying computer-readable program code. Such propagated data signals may take various forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination thereof. Computer-readable signal media may also be any computer-readable medium other than computer-readable storage media, capable of sending, propagating, or transmitting programs for use by or in connection with an instruction execution system, apparatus, or device.
[0219] Program code contained on a computer-readable medium may be transmitted using any suitable medium, including but not limited to wireless, wire, optical fiber, RF, etc., or any suitable combination thereof.
[0220] Although embodiments of the invention have been shown and described, it will be understood by those skilled in the art that various changes, modifications, substitutions and alterations can be made to these embodiments without departing from the principles and spirit of the invention, the scope of which is defined by the appended claims and their equivalents.
Claims
1. A method of image classification of the extent of African swine fever infection, characterized by, include: S1. Obtain the original pig images collected from a fixed viewpoint, construct a body posture fitting model, and calculate the body distance and body angle of the pig relative to the fixed viewpoint based on the projection offset between the body posture fitting model and the fixed viewpoint imaging reference to obtain spatial pose data. S2. Construct a perspective projection matrix based on the body angle and body distance in the spatial pose data, and determine whether there is perspective distortion in the original pig image. If there is perspective distortion, resample the original image pixel by using the perspective projection matrix to obtain the first corrected image. If there is no perspective distortion, the original pig image is used as the first corrected image; S3. Extract the set of connected pixels of the African swine fever pathological region from the first corrected image, and perform contour sampling on the set of connected pixels to obtain the boundary control points of the pathological region. S4. Based on the deviation between the boundary control points of the pathological region and the preset healthy baseline contour, adjust the scale deformation and position deformation of the pathological region, and generate a spatial misalignment compensation matrix based on the scale deformation and position deformation. S5. A spatial misalignment compensation matrix is used to perform affine compensation processing on the pathological areas of the body surface in the first corrected image to align the pathological areas of the body surface with the healthy baseline contour, thus obtaining the second corrected image. S6. Calculate the grayscale difference between the second corrected image and the preset health baseline image at the corresponding pixel positions to determine the feature alignment coordinates of the pathological area on the body surface. S7. Based on the feature alignment coordinates, crop the pathological texture feature map from the second corrected image, and input the pathological texture feature map into the preset classification model to obtain the African swine fever infection level assessment level.
2. The image classification method of the extent of African swine fever infection according to claim 1, characterized in that: S1 includes: Obtain original images of live pigs, extract features from the original images of live pigs to obtain the outline of the pig's back and abdomen; The limb support points are located based on the outline of the pig's spine and abdomen, and a body posture fitting model is constructed based on the limb support points. Calculate the projection offset between the body posture fitting model and the fixed-viewpoint imaging reference; If the projection offset is greater than the preset offset threshold, the body distance and body angle are calculated based on the projection offset to obtain spatial pose data.
3. The image classification method of the extent of African swine fever infection according to claim 1, characterized in that: S2 includes: Obtain the body angle and body distance from the spatial pose data, and construct a perspective projection matrix based on the body angle and body distance; The original pig images were mapped using a perspective projection matrix to obtain a set of mapped coordinates; Calculate the coordinate offset between the mapped coordinate set and the reference coordinate set; Determine whether the original pig image has perspective distortion, including whether the coordinate offset is greater than a preset threshold; If the coordinate offset is greater than the preset threshold, the original pig image is resampled by the perspective projection matrix to obtain the first corrected image. If the coordinate offset is not greater than the preset threshold, the original pig image is used as the first corrected image.
4. The image classification method for the degree of African swine fever infection according to claim 1, characterized in that: S3 includes: A first corrected image is acquired, and the first corrected image is subjected to color space conversion and binarization to obtain the pathological area on the body surface, which includes erythema, hemorrhage, cyanosis and ulceration areas. Connectivity analysis is performed on pathological areas on the body surface to obtain a set of connected pixel regions; If the area of the connected component pixel set is greater than the preset area threshold, then the boundary of the connected component pixel set is extracted to obtain the contour of the pathological region. The contour of the pathological region is sampled according to the preset sampling interval to obtain the boundary control points of the pathological region.
5. The image classification method for the degree of African swine fever infection according to claim 1, characterized in that: S4 includes: Calculate the initial contour deviation between the boundary control points of the pathological region and the preset healthy baseline contour; Smooth boundary control points are obtained by fitting the initial contour deviation; If the curvature characteristics of the smooth boundary control points are greater than the preset threshold, then the scale deformation is determined by curvature adjustment. The positional deformation is calculated based on the relative displacement between the mapping control point corresponding to the scale deformation and the preset health baseline profile. A spatial misalignment compensation matrix is generated based on scale deformation and position deformation.
6. The image classification method of the extent of African swine fever infection according to claim 1, characterized in that: S5 includes: Obtain the edge features of the pathological area on the body surface in the first corrected image, and calculate the spatial misalignment compensation matrix based on the edge features; A spatial misalignment compensation matrix is used to process the pathological area on the body surface to obtain a pixel mapping set. The grayscale interpolation distribution is determined and adjusted based on the pixel mapping set to obtain contour alignment data. The pathological areas on the body surface in the first corrected image are updated by contour alignment data. The pathological areas on the body surface in the first corrected image are then subjected to affine compensation processing using a spatial misalignment compensation matrix to align the pathological areas on the body surface with the healthy baseline contour, thus obtaining the second corrected image.
7. The image classification method of the extent of African swine fever infection according to claim 1, characterized in that: S6 includes: A second corrected image and a preset health baseline image are acquired, and an affine transformation algorithm is used to perform spatial registration processing on the second corrected image and the preset health baseline image to obtain a registered image pair. Based on the registered image pairs, the gray-level difference at corresponding pixel positions is extracted by pixel-by-pixel subtraction to obtain the initial gray-level difference matrix.
8. The image classification method of the extent of African swine fever infection according to claim 7, characterized in that: S6 further includes: For the initial gray-level difference matrix, Otsu's method is used for binarization segmentation to determine the connected components of abnormal regions; If the number of pixels in the connected components of the abnormal region is greater than a preset threshold, the edge contour pixels of the connected components of the abnormal region are extracted by the edge detection algorithm to determine the feature alignment coordinates of the pathological region on the body surface.
9. The image classification method for the degree of African swine fever infection according to claim 1, characterized in that: S7 includes: A standard-size pixel matrix is obtained by resampling the second corrected image; Extract texture data from a standard-sized pixel matrix to generate a pathological texture feature map.
10. The image classification method for the degree of African swine fever infection according to claim 9, characterized in that: The S7 also includes: Dimensionality reduction of the pathological texture feature map is used to obtain a dimension-reduced pathological feature vector, and the dimension-reduced pathological feature vector is truncated to obtain the target pathological feature vector. The target pathological feature vector is input into a preset classification model to obtain a probability set, and the African swine fever infection level is determined based on the probability set.
