A system and method for detecting abnormalities on the surface of pigs based on visual images
By calculating the degree of change and grayscale change of pixels in the pig image, clustering and enhancement processing, and distinguishing pig areas, the problem of simultaneous enhancement of background and abnormal areas in the existing technology is solved, and the detection accuracy is improved.
Patent Information
- Application Number
- CN202410711622.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-04
- Publication Date
- 2024-09-27
- Estimated Expiration
- 2044-06-04
AI Technical Summary
When existing image enhancement technology detects abnormal areas on the surface of pigs, it will cause the background area and the abnormal area to be enhanced simultaneously, reducing detection accuracy.
By acquiring continuous frames of pig herd images, calculating the degree of position change and grayscale change of pixel points, clustering is obtained to obtain the pig herd area, and different degrees of image enhancement are performed based on the grayscale value and confidence level to distinguish normal areas and abnormal areas.
It improves the efficiency and accuracy of surface abnormality detection in pigs, clearly distinguishes abnormal areas, and reduces background interference.
Smart Images

Figure CN118279936B
Abstract
Description
Technical Field
[0001] The present invention relates to the field of image enhancement technology, and in particular to a system and method for detecting surface anomalies of pigs based on visual images. Background Art
[0002] Pigs are one of the important livestock in agriculture and play an important role in human food supply. If there are abnormal areas on the skin surface of pigs, it may be caused by infectious diseases. Infectious diseases have a great impact on pigs, causing the growth and development of pigs to slow down or even a large number of pigs to die, thus causing a lot of economic losses to farmers. Therefore, farmers usually use detection systems to detect abnormal areas in pigs, and notify relevant technicians in time when abnormal areas appear to inspect and treat the pigs in abnormal areas to reduce the spread of infectious diseases and minimize economic losses.
[0003] In order to detect abnormal areas on the surface of pigs in the prior art, it is necessary to first enhance the pig image to obtain the abnormal area. Since the grayscale values of the pixels in the abnormal area and the background area in the pig image are similar to a certain extent, the existing image enhancement technology will enhance the background area and the abnormal area simultaneously when enhancing the pig image, resulting in no obvious contrast between the abnormal area and the background area, causing certain interference to the detection of abnormalities on the pig surface and reducing the accuracy of abnormal area detection. Summary of the invention
[0004] In order to solve the technical problem that the existing image enhancement technology will simultaneously enhance the background area and the pig area, thereby interfering with the identification of the abnormal area and resulting in low accuracy of pig surface abnormality detection, the purpose of the present invention is to provide a pig surface abnormality detection system and method based on visual images, and the technical solutions adopted are as follows:
[0005] A method for detecting surface abnormalities of a pig group based on visual images, the method comprising:
[0006] Acquire continuous frames of pig group images;
[0007] Obtain the degree of change of each pixel point according to the degree of position change and grayscale change of the pixel point in the pig group image of continuous frames; obtain the pig group area of each pig group image according to the degree of change;
[0008] Obtain suspected abnormal areas and normal areas of the pig herd according to the grayscale values of the surface pixels of the pig herd in the pig herd area; obtain the confidence of the pixels in the suspected abnormal area according to the grayscale contrast difference between the pixels in the suspected abnormal area and all the neighboring pixels; obtain the grayscale enhancement degree of each pixel in the pig herd area on each pig herd image according to the grayscale distribution characteristics of the pixels in the pig herd area; enhance the pixels in the normal area according to the grayscale enhancement degree, and enhance the pixels in the suspected abnormal area according to the grayscale enhancement degree and the confidence, and obtain the enhancement results of all pixels in the pig herd area;
[0009] Abnormal areas on the surface of the pigs are detected based on the enhancement results.
[0010] Furthermore, the method for obtaining the degree of change includes:
[0011] The optical flow method is used to track and match each pixel in the continuous frame pig group images, and the matching pixels form a pixel sequence;
[0012] Calculating the distance between two adjacent pixel points in each pixel point sequence in the same coordinate system as the position change degree between the two pixel points;
[0013] Calculating the grayscale difference between two adjacent pixel points in each pixel point sequence as the grayscale change degree between the two pixel points;
[0014] The product of the position change degree and the grayscale change degree between all two adjacent pixel points in each pixel point sequence is accumulated to obtain the change degree of the pixel point sequence.
[0015] Further, the pig group area of each pig group image is obtained according to the degree of change, including:
[0016] Each pixel point in all the pixel point sequences is clustered in the corresponding pig herd image according to the degree of change, and all the pixel points in all the pixel point sequences on each pig herd image are divided into pig herd area pixels and background area pixels according to the clustering result, and the pig herd area of each pig herd image is obtained.
[0017] Furthermore, the suspected abnormal area and the normal area of the pigs are obtained according to the grayscale values of the pixels in the pig group area, including:
[0018] The area composed of all pixels whose grayscale values are smaller than the median value of the pixels in the pig herd area is taken as the suspected abnormal area of the pig herd, and the area composed of all pixels whose grayscale values are larger than the median value of the pixels in the pig herd area is taken as the normal area of the pig herd.
[0019] Furthermore, the method for obtaining the confidence level includes:
[0020] A neighborhood window is preset with each pixel point in the suspected abnormal area within the pig herd area as the center;
[0021] Calculate the grayscale difference between each pixel in the suspected abnormal area and each neighboring pixel in the neighborhood window as a first grayscale difference;
[0022] Calculate the grayscale difference between each pixel in the suspected abnormal area and the grayscale mean of all neighboring pixels in the neighborhood window as the second grayscale difference;
[0023] Multiplying the first grayscale difference by the second grayscale difference to obtain a grayscale contrast difference of each pixel in the suspected abnormal area relative to each neighboring pixel in the neighborhood window;
[0024] The average grayscale contrast difference of each pixel in the suspected abnormal area relative to all pixels in the neighborhood window is calculated, and the reciprocal of the grayscale contrast difference average is used as the confidence of each pixel in the suspected abnormal area.
[0025] Furthermore, the method for obtaining the grayscale enhancement degree includes:
[0026] The difference between each pixel point in the pig herd area and the grayscale mean of all pixels in the pig herd area is calculated as the grayscale difference degree of each pixel point in the pig herd area;
[0027] The frequency of each gray value in the pig herd area is used as the gray display degree of the pixel points of each gray value in the pig herd area;
[0028] The grayscale enhancement degree of each pixel point in the pig herd area is obtained according to the grayscale difference degree and the grayscale display degree; the grayscale enhancement degree is negatively correlated with the grayscale difference degree and the grayscale display degree.
[0029] Furthermore, the grayscale enhancement degree of each pixel point in the pig group area is obtained according to the grayscale difference degree and the grayscale display degree, including:
[0030] The grayscale enhancement degree is obtained according to the grayscale enhancement degree calculation formula, and the grayscale enhancement degree calculation formula is as follows:
[0031] ; In the formula, Indicates The first The grayscale enhancement degree of each pixel; Indicates The first The gray value of each pixel; Indicates The number of pixels in the pig area in the pig image; Indicates The serial number of the pixel points in the pig herd area in the pig herd image; Indicated in The pig area in the pig herd image is The number of pixels with the same grayscale value; Indicates The first The grayscale difference of each pixel; Indicates The first The grayscale display degree of each pixel; Represents an exponential function with a natural constant as base.
[0032] Furthermore, the enhancement results of all pixels in the pig area are obtained, including:
[0033] When a pixel point belongs to the normal area of the pig image, an enhancement result of the pixel point is obtained according to the gray value of the pixel point and the gray enhancement degree of the pixel point; the enhancement result of the pixel point is in direct proportion to the gray value and the gray enhancement degree;
[0034] When a pixel point belongs to the suspected abnormal area of the pig herd image, the enhancement result of the pixel point is obtained according to the grayscale value of the pixel point, the grayscale enhancement degree of the pixel point and the confidence of the pixel point; the enhancement degree of the pixel point is directly proportional to the grayscale value, the grayscale enhancement degree and the confidence of the pixel point.
[0035] Furthermore, the neighborhood window is set to an 8-neighborhood centered on each pixel in the suspected abnormal area.
[0036] A system for detecting surface anomalies of a pig group based on visual images, the system comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the computer program, the steps of the method for detecting surface anomalies of a pig group based on visual images are implemented.
[0037] The present invention has the following beneficial effects:
[0038] The present invention collects continuous frames of pig group images and then performs surface abnormal area detection on them; obtains the degree of change of each pixel point according to the degree of position change and grayscale change of the pixel point in the continuous frames of the pig group images, and the degree of change reflects whether the part of the pig group image corresponding to the pixel point is the pig group area, thereby obtaining the pig group area of each pig group image; obtains the suspected abnormal area and the normal area according to the grayscale value of the pig group surface pixel point in the pig group area, which is convenient for subsequent image enhancement of different degrees; then firstly obtains the confidence degree according to the grayscale contrast difference between the pixel point in the suspected abnormal area and all the neighboring pixel points, which reflects the probability that the pixel point in the suspected abnormal area is the pixel point in the abnormal area; obtains the grayscale enhancement degree of each pixel point in the pig group area on the pig group image through the grayscale distribution characteristics of each pixel point in the pig group area, which reflects the influence of the grayscale characteristics of the pixel point in the pig group area on the image enhancement; then, the suspected abnormal area and the normal area are enhanced to different degrees to obtain the enhancement results of all the pixel points in the pig group area, and the enhancement results can distinguish the pixel points in different areas in the pig group area, which is convenient for detecting the abnormal area. The present invention can distinguish abnormal areas well by enhancing normal areas and abnormal areas to different degrees, thereby improving the efficiency and accuracy of detecting abnormalities on the surface of pigs. BRIEF DESCRIPTION OF THE DRAWINGS
[0039] In order to more clearly illustrate the technical solutions and advantages in the embodiments of the present invention or the prior art, the drawings required for use in the embodiments or the prior art descriptions are briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0040] Figure 1 A flow chart of a method for detecting surface anomalies of a pig group based on visual images provided by an embodiment of the present invention;
[0041] Figure 2 A schematic diagram of an abnormal area on the surface of a pig group before enhancement provided by an embodiment of the present invention;
[0042] Figure 3 A schematic diagram of abnormal areas on the surface of a pig herd after enhancement provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0043] In order to further explain the technical means and effects adopted by the present invention to achieve the predetermined invention purpose, the following is a detailed description of the specific implementation method, structure, characteristics and effects of a pig surface abnormality detection system and method based on visual images proposed by the present invention in combination with the accompanying drawings and preferred embodiments. In the following description, different "one embodiment" or "another embodiment" does not necessarily refer to the same embodiment. In addition, specific features, structures or characteristics in one or more embodiments may be combined in any suitable form.
[0044] Unless defined otherwise, all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the art to which this invention belongs.
[0045] The specific scheme of a pig surface abnormality detection system and method based on visual images provided by the present invention is described in detail below with reference to the accompanying drawings.
[0046] See also Figure 1 , which shows a flow chart of a method for detecting surface abnormalities of a pig group based on visual images provided by an embodiment of the present invention, the method comprising:
[0047] Step S1: Acquire continuous frames of pig group images.
[0048] The embodiment of the present invention provides a method for detecting abnormalities on the surface of a pig group based on visual images. Aiming at the problem of detecting abnormal areas on the surface of a pig group, an image enhancement method is used to detect abnormal areas on the surface of a pig group. In order to facilitate the subsequent analysis of interference factors such as background, it is first necessary to obtain the identification object of the embodiment of the present invention, that is, to obtain all pig group images of a certain time length.
[0049] In one embodiment of the present invention, a high-definition camera is installed directly above the pigs for shooting, and LED lights are laid directly above the pigs to evenly cover the pigs with light, thereby reducing the impact of light on the continuous pig images of the pigs. In one embodiment of the present invention, the frequency interval of collecting pig images is 0.1 seconds, the collection time is set to 3 seconds, 30 pig images of the pigs are obtained, and then the obtained pig images are subjected to image preprocessing operations such as denoising and graying.
[0050] It should be noted that the frequency interval and acquisition time of collecting pig group images can be set by the implementer according to the specific implementation scenario, and are not limited here. Image preprocessing operations such as denoising and graying are technical means well known to those skilled in the art and will not be described in detail here.
[0051] At this point, all pig group images are obtained.
[0052] Step S2: Obtain the degree of change of each pixel point according to the degree of position change and grayscale change of the pixel point in the pig herd images of consecutive frames; obtain the pig herd area of each pig herd image according to the degree of change.
[0053] When performing image enhancement on continuous pig images of a pig herd, since the background pixels in the collected images, such as the ground, are darker in the grayscale image, the abnormal area on the surface of the diseased pig skin is usually darker in the grayscale image. Figure 2 As shown, a schematic diagram of abnormal areas on the surface of a pig herd is provided. In the figure, the grayscale values of the abnormal area and the background area are similar. At this time, if the pig herd area and the background area are enhanced at the same time, the background area will cause great interference to the abnormal area on the surface of the pig herd. In order to facilitate the subsequent identification of the abnormal area, it is necessary to distinguish the pig herd area from the background area and only retain the pig herd area. Therefore, the embodiment of the present invention needs to obtain the pig herd area of each pig herd image.
[0054] Because in actual scenes, the position and grayscale of the pixels in the background area in different pig images remain relatively unchanged, while in the process of pig movement, the position of the same part of the pig in different pig images will change, and the grayscale value of the pixels in the same part of the pig skin surface will also change, and there is a significant difference between the position change degree or grayscale change degree of the pig area and the background area. Therefore, in the embodiment of the present invention, the change degree of each pixel is obtained according to the position change degree and grayscale change degree of the pixel in the pig images of consecutive frames.
[0055] Preferably, in one embodiment of the present invention, the method for obtaining the degree of change includes:
[0056] The optical flow method is used to track and match each pixel in the continuous frame pig image, and the matching pixels form a pixel sequence; the distance between two adjacent pixels in each pixel sequence in the same coordinate system is calculated, and the distance formula between the position coordinates reflects the position change of the pixels in the corresponding parts of the adjacent pig images in the same coordinate axis, so the distance between two adjacent pixels in each pixel sequence in the same coordinate system is used as the position change degree between the two pixels; the grayscale difference between two adjacent pixels in the pixel sequence reflects the difference in grayscale values of the pixels in the corresponding parts of the adjacent pig images, and the grayscale difference between two adjacent pixels in each pixel sequence is calculated as the grayscale change degree between the two pixels; the product of the position change degree and the grayscale change degree between all two adjacent pixels in each pixel sequence is accumulated to obtain the change degree of the pixel sequence.
[0057] It should be noted that, in addition to the optical flow method, in other embodiments of the present invention, algorithms such as template matching can be used to track and match all pig images to obtain pixel point sequences. Template matching is a technical means well known to those skilled in the art and will not be limited or elaborated here.
[0058] In one embodiment of the present invention, the calculation formula for the degree of change of the pixel sequence is as follows:
[0059]
[0060] In the formula, Indicates The degree of change of the pixel sequence; Indicates The pixel sequence is The horizontal coordinate of the pixel point of the pig image; Indicates The pixel sequence is The horizontal coordinate of the pixel point of the pig image; Indicates The pixel sequence is The vertical coordinate of the pixel point of the pig image; Indicates The pixel sequence is The vertical coordinate of the pixel point of the pig image; Indicates The pixel sequence is The gray value of the pixel points of the pig group image; Indicates The pixel sequence is The grayscale value of the pixel points in the pig herd image.
[0061] In the calculation formula of the degree of change, In the same coordinate system, The pixel sequence is The pig image and The distance between corresponding pixels of a pig herd image is larger, indicating that the position change between adjacent pixels in the pixel sequence is larger, that is, the larger the position change of the corresponding pixels in the adjacent pig herd images is, the greater the possibility that the pixel sequence is a pig herd area. Indicates In the pixel sequence The pixel points of the first pig image are The grayscale change degree of the pixel points in the pig herd image is larger, and the grayscale change of the adjacent pixel points in the pixel point sequence is larger. That is, the larger the grayscale change of the pixel points in the corresponding parts in the adjacent pig herd images, the more likely the pixel point sequence is the pixel points in the pig herd area.
[0062] The higher the degree of change of the pixel sequence, the greater the possibility that the pixel in the pixel sequence is a pixel in the pig region; the smaller the degree of change of the pixel sequence, the greater the possibility that the pixel in the pixel sequence is a pixel in the background region. The pig region of each pig image is obtained according to the degree of change of the pixel sequence. Preferably, in one embodiment of the present invention, the pig region of each pig image is obtained according to the degree of change, including:
[0063] Each pixel point in all pixel point sequences is clustered in the corresponding pig herd image according to the degree of change, and all pixel points in all pixel point sequences on each pig herd image are divided into pig herd area pixels and background area pixels according to the clustering results, and the pig herd area of each pig herd image is obtained. In one embodiment of the present invention, the background area in the pig herd area can also be obtained according to the clustering results, and the grayscale value of all pixel points in the background area is set to 255, and the background area pixels are suppressed, so that there is a strong contrast between the background area and the pig herd area. It should be noted that other embodiments of the present invention may adopt other background area pixel suppression methods, and the suppression methods are technical means well known to those skilled in the art and are not limited here.
[0064] It should be noted that the clustering algorithm is a technical means well known to those skilled in the art and will not be limited or elaborated herein.
[0065] At this point, the pig herd area on each pig herd image is obtained.
[0066] Step S3: Obtain the suspected abnormal area and normal area of the pig herd according to the grayscale values of the surface pixels of the pig herd in the pig herd area; obtain the confidence of the pixels in the suspected abnormal area according to the grayscale contrast difference between the pixels in the suspected abnormal area and all the neighboring pixels; obtain the grayscale enhancement degree of each pixel in the pig herd area on each pig herd image according to the grayscale distribution characteristics of the pixels in the pig herd area; enhance the pixels in the normal area according to the grayscale enhancement degree, and enhance the pixels in the suspected abnormal area according to the grayscale enhancement degree and the confidence, and obtain the enhancement results of all pixels in the pig herd area.
[0067] In the implementation scenario, the grayscale value of the normal area on the surface of the pig is higher, while the grayscale value of the abnormal area is lower. At the same time, the stains on the surface of the pig are almost consistent with the abnormal area in grayscale performance. The abnormal areas directly obtained based on the grayscale value are not all real abnormal areas, and confusion will occur during image enhancement. Therefore, all areas with obvious grayscale values from normal areas are regarded as suspected abnormal areas. The suspected abnormal areas in the pig herd area are different from the normal areas in terms of grayscale value, which is specifically manifested in that the grayscale value of the pixels in the suspected abnormal area is lower and the grayscale value of the pixels in the normal area is higher. In order to subsequently enhance the suspected abnormal areas and normal areas to different degrees, thereby improving the contrast between the suspected abnormal areas and normal areas, in an embodiment of the present invention, the suspected abnormal areas and normal areas are obtained according to the grayscale value of the pixels in the pig herd area.
[0068] Preferably, in one embodiment of the present invention, obtaining the suspected abnormal area and the normal area according to the grayscale values of the pixels in the pig group area includes:
[0069] The area composed of all pixels whose grayscale values are less than the median value of the pixels in the pig herd area is regarded as the suspected abnormal area, and the area composed of all pixels whose grayscale values are greater than the median value of the pixels in the pig herd area is regarded as the normal area.
[0070] It should be noted that the division conditions between suspected abnormal areas and normal areas can be set by the implementers themselves and are not limited here.
[0071] For the suspected abnormal area, the suspected abnormal area includes the abnormal area and the stain area. The abnormal area and the stain area on the pig both present grayscale features with low grayscale values, but the pixels in the abnormal area are usually denser and the grayscale values of the pixels are more consistent. The grayscale values of the stain pixels are more dispersed and the consistency of the grayscale values of the pixels is poor. In order to distinguish the abnormal area from the stain area, in the embodiment of the present invention, the confidence of the pixels in the suspected abnormal area is obtained according to the grayscale features of the pixels in the suspected abnormal area within the neighborhood window.
[0072] Preferably, in one embodiment of the present invention, the method for obtaining the confidence level includes:
[0073] Preset a neighborhood window with each pixel in the suspected abnormal area in the pig herd area as the center; calculate the grayscale difference between each pixel in the suspected abnormal area and each neighboring pixel in the neighborhood window as the first grayscale difference; calculate the grayscale difference between each pixel in the suspected abnormal area and the grayscale mean of all neighboring pixels in the neighborhood window as the second grayscale difference; multiply the first grayscale difference with the second grayscale difference to obtain the grayscale contrast difference of each pixel in the suspected abnormal area relative to each neighboring pixel in the neighborhood window; calculate the average grayscale contrast difference of each pixel in the suspected abnormal area relative to all pixels in the neighborhood window, and use the inverse of the average grayscale contrast difference as the confidence of each pixel in the suspected abnormal area. In one embodiment of the present invention, the confidence calculation formula is as follows:
[0074]
[0075] In the formula, Indicates The first The confidence level of each pixel; Indicates The first The number of pixels in the neighborhood window of pixels; Indicates The first The sequence number of the neighboring pixel points in the neighborhood window of pixels; Indicates The first The gray value of each pixel; Indicates The first The pixel in the neighborhood window Gray value of neighboring pixels; Indicates The first The grayscale mean of all neighboring pixels in the neighborhood window of a pixel.
[0076] In the confidence calculation formula, Indicates The first pixel and the pixel in the neighborhood window of the pixel. The smaller the difference, the gray value of the pixel is different from the gray value of the pixel in the neighborhood window. The grayscale values of the pixels are more consistent, then The higher the confidence that a pixel is a pixel in the abnormal area, the higher the confidence that the pixel is a pixel in the abnormal area. No. The first The difference between the grayscale mean of the pixel point and the pixel point in the neighborhood window of the pixel point, the smaller the difference is, the higher the grayscale mean of the pixel point is. The gray value consistency of the pixel point and all the pixels in the neighborhood window is good, then The higher the confidence that a pixel is an abnormal area pixel, the higher the confidence that it is an abnormal area pixel. Indicates The first The pixel point is relative to the pixel point in the neighborhood window of the pixel point. The grayscale contrast difference of pixels is calculated for the The grayscale contrast difference between other neighboring pixels in the neighborhood window of the pixel point is The first The grayscale contrast difference of the pixel point relative to all the neighboring window pixels of the pixel point is averaged and the inverse is taken. At this time, the smaller the grayscale contrast difference, the The better the consistency of the gray value between the pixel and the surrounding neighboring pixels, the The higher the confidence of the pixel, the higher the confidence of the pixel.
[0077] Preferably, in one embodiment of the present invention, the neighborhood window is set to an 8-neighborhood centered on each pixel in the suspected abnormal area. It should be noted that in other embodiments of the present invention, the neighborhood window setting can be set by specific implementation personnel according to the implementation scenario, and is not limited here.
[0078] When detecting abnormal areas on the surface of a pig herd, the contrast between the abnormal area and other areas is required to be very obvious for further detection, so the suspected abnormal area and the normal area in the pig herd area are enhanced to different degrees. Since the grayscale distribution characteristics of the pixels in the suspected abnormal area and the normal area relative to the pig herd area are different, the degree of enhancement of the grayscale values of the suspected abnormal area and the normal area is also different. Therefore, in the embodiment of the present invention, the grayscale enhancement degree of each pixel in the pig herd area on each pig herd image is obtained according to the grayscale distribution characteristics of each pixel in the pig herd area.
[0079] Preferably, in one embodiment of the present invention, the method for obtaining the grayscale enhancement degree includes:
[0080] The difference between each pixel point in the pig herd area and the grayscale mean value in the pig herd area is calculated as the grayscale difference degree of each pixel point in the pig herd area. The greater the grayscale difference degree, the greater the difference between the grayscale value of the pixel point and the grayscale mean value of the pixel point in the pig herd area. At this time, there is a stronger contrast between the pixel point and the pig herd area. When image enhancement is performed, the degree of enhancement is smaller; the frequency of each grayscale value in the pig herd area is taken as the grayscale display degree of the pixel point of each grayscale value in the pig herd area. The greater the grayscale display degree, the higher the number of times the grayscale value appears in the pig herd area, which means that the area formed by all pixels corresponding to the grayscale value is easier to observe, and the degree of enhancement of the grayscale value of the pixel point is smaller at this time; the grayscale enhancement degree of each pixel point in the pig herd area is obtained according to the grayscale difference degree and the grayscale display degree; the grayscale enhancement degree is negatively correlated with the grayscale difference degree and the grayscale display degree.
[0081] Preferably, in one embodiment of the present invention, the grayscale enhancement degree of each pixel in the pig group area is obtained according to the grayscale difference degree and the grayscale display degree, including:
[0082] The grayscale enhancement degree is obtained according to the grayscale enhancement degree calculation formula. The grayscale enhancement degree calculation formula is as follows:
[0083]
[0084] In the formula, Indicates The first The grayscale enhancement degree of each pixel; Indicates The first The gray value of each pixel; Indicates The number of pixels in the pig area in the pig image; Indicates The serial number of the pixel points in the pig herd area in the pig herd image; Indicated in The pig area in the pig herd image is The number of pixels with the same grayscale value; Indicates The first The grayscale difference of each pixel; Indicates The first The grayscale display degree of each pixel; Represents an exponential function with a natural constant as base.
[0085] In the grayscale enhancement degree calculation formula, The larger the The first The greater the grayscale difference of the pixels, the The stronger the contrast between the pixel and the pig area, the smaller the grayscale enhancement degree; The larger the The first The greater the grayscale display degree of the pixel point, the The area formed by the pixels is easier to observe in the pig area, and the grayscale enhancement is smaller to avoid excessive enhancement and damage to image details.
[0086] After obtaining the grayscale enhancement degree, the suspected abnormal area and the normal area in the pig herd area are enhanced to distinguish the suspected abnormal area from the normal area. The abnormal area and the stain area in the suspected abnormal area should also be enhanced to different degrees using the confidence of the pixel points in the suspected abnormal area to improve the contrast of the abnormal area. Therefore, in the embodiment of the present invention, the pixel points in the normal area are enhanced according to the grayscale enhancement degree, and the pixel points in the suspected abnormal area are enhanced according to the grayscale enhancement degree and the confidence, and the enhancement results of all the pixel points in the pig herd area are obtained.
[0087] Preferably, in one embodiment of the present invention, obtaining the enhancement results of all pixels in the pig group area includes:
[0088] When the pixel belongs to the normal area, the enhancement result of the pixel is obtained according to the grayscale value of the pixel and the grayscale enhancement degree of the pixel; the enhancement result of the pixel is directly proportional to the grayscale value and the grayscale enhancement degree; when the pixel belongs to the suspected abnormal area, the enhancement result of the pixel is obtained according to the grayscale value of the pixel, the grayscale enhancement degree of the pixel and the confidence of the pixel; the enhancement result of the pixel is directly proportional to the grayscale value, the grayscale enhancement degree and the confidence of the pixel. In one embodiment of the present invention, the calculation formula for the enhancement results of all pixels in the pig herd area is as follows:
[0089] The calculation formula for the enhancement result of the pixels in the normal area of the pig area is as follows:
[0090]
[0091] In the formula, Indicates The first The enhancement result of pixels; Indicates The first Gray value of pixels before enhancement; Indicates The first The grayscale enhancement degree of each pixel.
[0092] The calculation formula for the enhancement result of the pixel points in the suspected abnormal area in the pig herd area is as follows:
[0093]
[0094] In the formula, Indicates The first The enhancement result of pixels; Indicates The first Gray value of pixels before enhancement; Indicates The first The grayscale enhancement degree of each pixel; Indicates The first The confidence level of each pixel; Represents the normalization function.
[0095] For pixels in the normal area, the pixels in the normal area are directly enhanced by the grayscale enhancement degree to obtain the enhancement result of each pixel in the normal area; for pixels in the suspected abnormal area, the grayscale enhancement degree of the pixels in the suspected abnormal area is multiplied by the confidence and normalized, and the grayscale value of the pixels in the suspected abnormal area is enhanced after the normalized value is obtained to obtain the enhancement result of the pixels in the suspected abnormal area. At this time, the normal area and the suspected abnormal area will have a more obvious contrast after image enhancement. Since the confidence of the pixels in the abnormal area and the stain area in the suspected abnormal area is different, the calculation formula for the enhancement result of the pixels in the suspected abnormal area can distinguish the abnormal area from the stain area by the confidence, and finally form the pig area enhancement result with the normal area being the brightest, the stain area being brighter, and the abnormal area being the darkest.
[0096] At this point, the abnormal area, stain area and normal area with strong contrast are obtained.
[0097] Step S4: Detect abnormal areas on the surface of the pigs according to the enhancement results.
[0098] According to step S3, the enhancement results of different regions in the pig image are obtained. Figure 3As shown, a schematic diagram of abnormal areas on the surface of a pig herd after enhancement is provided, wherein the area with the darkest grayscale performance is the abnormal area in the pig herd area, and the enhanced pig herd image is segmented to obtain the abnormal area of the pig herd image. Observe the location of the abnormal area, and then when the detection system detects that an abnormal area appears in the pig herd area, give a timely warning prompt, and contact relevant personnel as soon as possible to further process the pigs with abnormal areas on the surface. It should be noted that the image segmentation algorithm and the detection system are both technical means well known to those skilled in the art, and are not limited or elaborated here.
[0099] At this point, the detection of abnormal areas on the surface of the pig herd is achieved.
[0100] In summary, the present invention collects multiple pig group images; obtains the degree of change of each pixel point according to the degree of position change and grayscale change of the pixel point in the pig group image of the continuous frame, thereby obtaining the pig group area of each pig group image; obtains the suspected abnormal area and the normal area according to the grayscale value of the pixel point in the pig group area; then first obtains the confidence according to the grayscale contrast difference between the pixel point in the suspected abnormal area and all the neighboring pixels; obtains the grayscale enhancement degree of each pixel point in the pig group area through the grayscale distribution characteristics of each pixel point in the pig group area; then enhances the normal area through the grayscale enhancement degree, enhances the suspected abnormal area through the grayscale enhancement degree and the confidence, obtains the enhancement result of all pixels in the pig group area, and the enhancement result can distinguish the pixels in different areas in the pig group area, and facilitates the detection of abnormal areas. The present invention can distinguish the abnormal area well by enhancing the background area, the normal area and the abnormal area to different degrees, thereby improving the efficiency and accuracy of detecting abnormal areas on the surface of the pig group.
[0101] An embodiment of the present invention also provides a pig surface abnormality detection system based on visual images, including a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, it can implement the steps of a pig surface abnormality detection method based on visual images.
[0102] An embodiment of an image enhancement method for a pig group image:
[0103] In the prior art, when enhancing the image of a herd of pigs, the pixels in the abnormal area and the background pixels in the image have a certain similarity, which leads to the technical problem that the background and the herd area are enhanced simultaneously when the image of the collected pigs is enhanced by the prior art. In order to solve this technical problem, an embodiment of an image enhancement method for herd of pigs is provided, comprising:
[0104] Step S1: Acquire continuous frames of pig group images.
[0105] Step S2: Obtain the degree of change of each pixel point according to the degree of position change and grayscale change of the pixel point in the pig herd images of consecutive frames; obtain the pig herd area of each pig herd image according to the degree of change.
[0106] Step S3: Obtain the suspected abnormal area and normal area of the pig herd according to the grayscale values of the surface pixels of the pig herd in the pig herd area; obtain the confidence of the pixels in the suspected abnormal area according to the grayscale contrast difference between the pixels in the suspected abnormal area and all the neighboring pixels; obtain the grayscale enhancement degree of each pixel in the pig herd area on each pig herd image according to the grayscale distribution characteristics of the pixels in the pig herd area; enhance the pixels in the normal area according to the grayscale enhancement degree, and enhance the pixels in the suspected abnormal area according to the grayscale enhancement degree and the confidence, and obtain the enhancement results of all pixels in the pig herd area.
[0107] Since the specific implementation of steps S1 to S3 has been mentioned in the above-mentioned system and method for detecting surface abnormalities of pigs based on visual images, they will not be described in detail here.
[0108] The technical effect of this embodiment: This embodiment collects continuous frames of pig group images and then detects the surface abnormal area; obtains the degree of change of each pixel point according to the degree of position change and grayscale change of the pixel point in the continuous frame pig group image, and the degree of change reflects whether the part of the pig group image corresponding to the pixel point is the pig group area, thereby obtaining the pig group area of each pig group image; obtains the suspected abnormal area and the normal area according to the grayscale value of the pixel point in the pig group area, which is convenient for subsequent image enhancement of different degrees; then first obtains the confidence according to the grayscale characteristics of the pixel point in the suspected abnormal area in the neighborhood window, reflecting the probability that the pixel point in the suspected abnormal area is a pathological pixel point; obtains the grayscale enhancement degree of each pixel point in the pig group area through the grayscale distribution characteristics of each pixel point in the pig group area, reflecting the influence of the grayscale characteristics of the pixel point in the pig group area on image enhancement; then enhances the suspected abnormal area and the normal area to different degrees, and obtains the enhancement results of all pixels in the pig group area. This embodiment can enhance the background area, normal area and abnormal area to different degrees, amplify the features between different types of areas in the image, and improve the image enhancement effect.
[0109] It should be noted that the sequence of the above embodiments of the present invention is only for description and does not represent the advantages and disadvantages of the embodiments. The processes depicted in the accompanying drawings do not necessarily require the specific order or continuous order shown to achieve the desired results. In some embodiments, multitasking and parallel processing are also possible or may be advantageous.
[0110] The various embodiments in this specification are described in a progressive manner, and the same or similar parts between the various embodiments can be referenced to each other, and each embodiment focuses on the differences from other embodiments.
Claims
1. A method for detecting surface abnormalities of pigs based on visual images, characterized in that: The method comprises: Acquire continuous frames of pig group images; Obtain the degree of change of each pixel point according to the degree of position change and grayscale change of the pixel point in the pig group image of continuous frames; obtain the pig group area of each pig group image according to the degree of change; Obtain suspected abnormal areas and normal areas of the pig herd according to the grayscale values of the surface pixels of the pig herd in the pig herd area; obtain the confidence of the pixels in the suspected abnormal area according to the grayscale contrast difference between the pixels in the suspected abnormal area and all the neighboring pixels; obtain the grayscale enhancement degree of each pixel in the pig herd area on each pig herd image according to the grayscale distribution characteristics of the pixels in the pig herd area; enhance the pixels in the normal area according to the grayscale enhancement degree, and enhance the pixels in the suspected abnormal area according to the grayscale enhancement degree and the confidence, and obtain the enhancement results of all pixels in the pig herd area; detecting abnormal areas on the surface of the pigs according to the enhancement results; The method for obtaining the confidence level includes: A neighborhood window is preset with each pixel point in the suspected abnormal area within the pig herd area as the center; Calculate the grayscale difference between each pixel in the suspected abnormal area and each neighboring pixel in the neighborhood window as a first grayscale difference; Calculate the grayscale difference between each pixel in the suspected abnormal area and the grayscale mean of all neighboring pixels in the neighborhood window as the second grayscale difference; Multiplying the first grayscale difference by the second grayscale difference to obtain a grayscale contrast difference of each pixel in the suspected abnormal area relative to each neighboring pixel in the neighborhood window; Calculate the average grayscale contrast difference of each pixel in the suspected abnormal area relative to all pixels in the neighborhood window, and use the reciprocal of the average grayscale contrast difference as the confidence of each pixel in the suspected abnormal area; The method for obtaining the grayscale enhancement degree includes: The difference between each pixel point in the pig herd area and the grayscale mean of all pixels in the pig herd area is calculated as the grayscale difference degree of each pixel point in the pig herd area; The frequency of each gray value in the pig herd area is used as the gray display degree of the pixel points of each gray value in the pig herd area; The grayscale enhancement degree of each pixel point in the pig group area is obtained according to the grayscale difference degree and the grayscale display degree; the grayscale enhancement degree is negatively correlated with the grayscale difference degree and the grayscale display degree; The grayscale enhancement degree of each pixel point in the pig group area is obtained according to the grayscale difference degree and the grayscale display degree, including: The grayscale enhancement degree is obtained according to the grayscale enhancement degree calculation formula, and the grayscale enhancement degree calculation formula is as follows: ; In the formula, Indicates The first The grayscale enhancement degree of each pixel; Indicates The first The gray value of each pixel; Indicates The number of pixels in the pig area in the pig image; Indicates The serial number of the pixel points in the pig herd area in the pig herd image; Indicated in The pig area in the pig herd image is The number of pixels with the same grayscale value; Indicates The first The grayscale difference of each pixel; Indicates The first The grayscale display degree of each pixel; represents an exponential function with a natural constant as base; The calculation formula for the enhancement result of the pixels in the normal area of the pig area is as follows: ; In the formula, Indicates The first The enhancement result of pixels; Indicates The first Gray value of pixels before enhancement; Indicates The first The grayscale enhancement degree of each pixel; The calculation formula for the enhancement result of the pixels in the suspected abnormal area in the pig herd area is as follows: ; In the formula, Indicates The first The enhancement result of pixels; Indicates The first Gray value of pixels before enhancement; Indicates The first The grayscale enhancement degree of each pixel; Indicates The first The confidence level of each pixel; Represents the normalization function.
2. The method for detecting surface abnormalities of pigs based on visual images according to claim 1, characterized in that: The method for obtaining the degree of change includes: The optical flow method is used to track and match each pixel in the continuous frame pig group images, and the matching pixels form a pixel sequence; Calculating the distance between two adjacent pixel points in each pixel point sequence in the same coordinate system as the position change degree between the two pixel points; Calculating the grayscale difference between two adjacent pixel points in each pixel point sequence as the grayscale change degree between the two pixel points; The product of the position change degree and the grayscale change degree between all two adjacent pixel points in each pixel point sequence is accumulated to obtain the change degree of the pixel point sequence.
3. The method for detecting surface abnormalities of pigs based on visual images according to claim 2, characterized in that: The pig group area of each pig group image is obtained according to the degree of change, including: Each pixel point in all the pixel point sequences is clustered in the corresponding pig herd image according to the degree of change, and all the pixel points in all the pixel point sequences on each pig herd image are divided into pig herd area pixels and background area pixels according to the clustering result, and the pig herd area of each pig herd image is obtained.
4. The method for detecting surface anomalies of pigs based on visual images according to claim 1, characterized in that: Obtaining suspected abnormal areas and normal areas of pigs according to the gray values of the pixels in the pig group area includes: The area composed of all pixels whose grayscale values are smaller than the median value of the pixels in the pig herd area is taken as the suspected abnormal area of the pig herd, and the area composed of all pixels whose grayscale values are larger than the median value of the pixels in the pig herd area is taken as the normal area of the pig herd.
5. The method for detecting surface abnormalities of pigs based on visual images according to claim 1, characterized in that: Obtain the enhancement results of all pixels in the pig area, including: When a pixel point belongs to the normal area of the pig image, an enhancement result of the pixel point is obtained according to the gray value of the pixel point and the gray enhancement degree of the pixel point; the enhancement result of the pixel point is in direct proportion to the gray value and the gray enhancement degree; When a pixel point belongs to the suspected abnormal area of the pig herd image, the enhancement result of the pixel point is obtained according to the grayscale value of the pixel point, the grayscale enhancement degree of the pixel point and the confidence of the pixel point; the enhancement degree of the pixel point is directly proportional to the grayscale value, the grayscale enhancement degree and the confidence of the pixel point.
6. The method for detecting surface anomalies of pigs based on visual images according to claim 1, characterized in that: The neighborhood window is set to an 8-neighborhood centered on each pixel in the suspected abnormal area.
7. A system for detecting surface anomalies of pigs based on visual images, the system comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the computer program, the steps of a method for detecting surface abnormalities of a pig group based on visual images as described in any one of claims 1 to 6 are implemented.
