Method for quickly identifying apparent defects of fish oil soft capsules
By obtaining the foreign object reference points in the fish oil soft capsule image and adjusting the growth threshold using the overlap coefficient, the problem of incomplete foreign object images in the traditional method is solved, and a more accurate identification of the appearance defect of the fish oil soft capsule is achieved.
Patent Information
- Application Number
- CN202510253800.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-03-05
- Publication Date
- 2025-06-24
- Estimated Expiration
- Not applicable · inactive patent
AI Technical Summary
When traditional methods identify foreign objects in fish oil soft capsules, the foreign object image is incomplete due to the interference of overlapping areas on the grayscale value, and the appearance defects of fish oil soft capsules cannot be accurately identified.
By obtaining the foreign object reference points in the non-overlapping area, and using the overlap coefficient to determine whether the pixel points are disturbed by overlap, new seed points and new growth thresholds are obtained in the overlapping area, and region growth is performed to obtain a complete foreign object image.
The interference of overlapping areas on grayscale values is reduced, the integrity and accuracy of foreign object images are improved, and the efficiency is enhanced when quickly identifying appearance defects in multiple fish oil soft capsules.
Smart Images

Figure CN120198375A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer vision technology, and particularly to a method for quickly identifying appearance defects of fish oil soft capsules. Background Art
[0002] Fish oil soft capsules usually contain rich Omega-3 fatty acids, including EPA (eicosapentaenoic acid) and DHA (docosahexaenoic acid), and these components have various benefits to human health. During the production and transportation of fish oil soft capsules, the most likely and most important appearance defect is whether there are foreign objects in the fish oil soft capsules. Due to mechanical equipment wear, improper maintenance or operation errors, poor encapsulation, and failure to effectively filter minute particles such as dust and fibers in the production environment, some fish oil soft capsules will be mixed with foreign objects, increasing health risks. Therefore, it is necessary to identify and remove fish oil soft capsules with foreign objects.
[0003] The traditional method uses the region growing method to obtain the growth region of foreign objects by a fixed threshold, and obtains the foreign object image for defect recognition. In order to quickly identify whether there are foreign objects in multiple fish oil soft capsules, multiple fish oil soft capsules need to be identified together to reduce the number of identifications. However, the stacking of multiple fish oil soft capsules will cause the color of the overlapping part to become darker, while the independent capsules without overlapping parts are lighter in color due to their inherent light transmittance. Due to the overlapping, the gray value regions of some internal pixel points of the capsules are uneven, and the gray values of foreign objects in different regions also change accordingly. Using the traditional method will result in inaccurate growth regions of the foreign objects obtained and incomplete foreign object images, making the identification of appearance defects of fish oil soft capsules inaccurate.
[0004] Therefore, how to obtain a complete growth region of foreign objects and accurately identify the appearance defects of fish oil soft capsules has become an urgent problem to be solved. Summary of the Invention
[0005] In view of this, an embodiment of the present invention provides a method for quickly identifying appearance defects of fish oil soft capsules to solve the problem of how to obtain a complete growth region of foreign objects and accurately identify the appearance defects of fish oil soft capsules.
[0006] An embodiment of the present invention provides a method for quickly identifying appearance defects of fish oil soft capsules, and the method includes the following steps:
[0007] Obtain an image of a fish oil soft capsule to be identified, process the image of the fish oil soft capsule to obtain a grayscale image, and obtain a template region in the grayscale image according to the grayscale distribution characteristics of each capsule region in the grayscale image;
[0008] Denote the region where any capsule is located in the grayscale image as the reference region, and obtain the suspected reference points in the reference region according to the grayscale difference between the pixels in the reference region and the template region;
[0009] Obtain the seed points and corresponding growth thresholds in the reference region according to the suspected reference points in the reference region and the grayscale difference between the pixels in the reference region, and perform region growing on the seed points corresponding to each growth threshold in the reference region to obtain all the foreign object reference points in the reference region;
[0010] For any non-foreign object reference point adjacent to any foreign object reference point, obtain the overlap coefficient of the any non-foreign object reference point. When the overlap coefficient of the any non-foreign object reference point is greater than the preset overlap coefficient threshold, obtain the seed point corresponding to the any foreign object reference point, denoted as the target seed point. According to the target seed point, obtain new seed points and corresponding new growth thresholds in the neighborhood of the any non-foreign object reference point, and perform region growing on the new seed points corresponding to each new growth threshold to obtain new foreign object reference points;
[0011] Obtain all the new foreign object reference points in the reference region according to all the foreign object reference points, form the foreign object region of the reference region by combining all the foreign object reference points and new foreign object reference points in the reference region, obtain the foreign object regions of the regions where each capsule is located in the grayscale image, and perform defect recognition on the fish oil soft capsule image.
[0012] The beneficial effects of the embodiments of the present invention compared with the prior art are:
[0013] The present invention obtains an image of a fish oil soft capsule to be recognized, processes the image of the fish oil soft capsule to obtain a grayscale image, and obtains a template region in the grayscale image according to the grayscale distribution characteristics of the region where each capsule is located in the grayscale image; designates the region where any capsule is located in the grayscale image as a reference region, and obtains suspected reference points in the reference region according to the grayscale differences of the pixel points in the reference region and the template region; obtains seed points and corresponding growth thresholds in the reference region according to the suspected reference points in the reference region and the grayscale differences of the pixel points in the reference region, performs region growing on the seed points corresponding thereto in the reference region according to each growth threshold, and obtains all foreign object reference points in the reference region; for any non-foreign object reference point adjacent to any foreign object reference point, obtains the overlapping coefficient of the any non-foreign object reference point, and when the overlapping coefficient of the any non-foreign object reference point is greater than a preset overlapping coefficient threshold, obtains the seed point corresponding to the any foreign object reference point, denoted as a target seed point, obtains new seed points and corresponding new growth thresholds in the neighborhood of the any non-foreign object reference point according to the target seed point, performs region growing on the new seed points corresponding thereto according to each new growth threshold, and obtains new foreign object reference points; obtains all new foreign object reference points in the reference region according to all foreign object reference points, forms the foreign object region of the reference region with all foreign object reference points and new foreign object reference points in the reference region, obtains the foreign object regions of the regions where each capsule is located in the grayscale image, and performs defect recognition on the image of the fish oil soft capsule. The present invention first obtains foreign object reference points in non-overlapping regions, and then determines whether a pixel point is interfered by overlapping by obtaining the overlapping coefficient. When the pixel point is interfered by overlapping, new seed points and new growth thresholds are obtained in the overlapping region, and new foreign object reference points in the overlapping region are obtained through the new seed points and new growth thresholds, thereby obtaining a complete foreign object image, reducing the problem of incomplete foreign object images caused by the interference of the overlapping region on the grayscale value, and making it more accurate to quickly identify appearance defects in multiple fish oil soft capsules. Description of the Drawings
[0014] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the following will briefly introduce the drawings required for use in the embodiments or the description of the prior art. Obviously, the following drawings are only some embodiments of the present invention. For those of ordinary skill in the art, other drawings can be obtained based on these drawings without creative efforts.
[0015] Figure 1 is a flowchart of a method for quickly identifying appearance defects of a fish oil soft capsule provided in Embodiment 1 of the present invention;
[0016] Figure 2 is a grayscale image of a fish oil soft capsule to be recognized provided in Embodiment 1 of the present invention. Specific Embodiments
[0017] The embodiments of the present disclosure will be described in detail below. Examples of the embodiments are shown in the accompanying drawings. The embodiments described below with reference to the accompanying drawings are exemplary and are intended to explain the present disclosure, and should not be construed as limiting the present disclosure.
[0018] It should be noted that the terms "first", "second", etc. in the specification of the present disclosure and the above-mentioned accompanying drawings are used to distinguish similar objects, and do not necessarily have to be used to describe a specific order or sequence. It should be understood that such data can be interchanged under appropriate circumstances so that the embodiments of the present disclosure described herein can be implemented in an order other than those illustrated or described herein. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with the present disclosure. On the contrary, they are merely examples of devices and methods consistent with some aspects of the present disclosure.
[0019] In order to illustrate the technical solution of the present invention, it will be described below through specific embodiments.
[0020] Refer to Figure 1 , which is a method flowchart of a method for quickly identifying appearance defects of fish oil soft capsules provided in Embodiment 1 of the present invention. As Figure 1 shown, the method may include:
[0021] Step S101, obtain an image of a fish oil soft capsule to be identified, process the image of the fish oil soft capsule to obtain a grayscale image, and obtain a template region in the grayscale image according to the grayscale distribution characteristics of each capsule region in the grayscale image.
[0022] Collect an image of a fish oil soft capsule to be identified, convert the image of the fish oil soft capsule to be identified to obtain a grayscale image of the fish oil soft capsule to be identified. As Figure 2 shown, extract the grayscale value of each pixel point in the grayscale image of the fish oil soft capsule to be identified.
[0023] Since fish oil soft capsules are produced according to a fixed format template, each produced fish oil soft capsule should be consistent with the template capsule. For multiple stacked fish oil soft capsules, due to the small grayscale difference inside the fish oil soft capsules, although there is a grayscale change, the change is gradual and the difference is small. Therefore, the grayscale values of the overall internal region of the fish oil soft capsules are relatively uniform. Therefore, a template region in the grayscale image can be obtained according to the grayscale distribution characteristics of each capsule region in the grayscale image, and then the difference between other regions in the grayscale image and the template region can be used to judge other regions in the grayscale image.
[0024] The method for obtaining the template region in the grayscale image is as follows:
[0025] Use edge detection to screen the edge points in the grayscale image, take the area enclosed by continuous and unbroken edge points as the target area, calculate the grayscale uniformity coefficient of each target area, and select the target area with the largest grayscale uniformity coefficient as the template area.
[0026] In one embodiment, through image processing technology, obtain the areas where multiple capsules are located on the periphery of the grayscale image, use edge detection to obtain the edge points of the areas where multiple capsules are located on the periphery of the grayscale image, take the area enclosed by continuous and unbroken edge points as the target area, and according to the grayscale values of the pixel points in each target area, obtain the grayscale uniformity coefficient of each target area. Select the target area with the largest grayscale uniformity coefficient among all target areas as the template area. Among them, image processing technology and edge detection belong to the prior art and will not be elaborated here.
[0027] Among them, the specific method for obtaining the grayscale uniformity coefficient of each target area according to the grayscale values of the pixel points in each target area is as follows:
[0028] For any target area in the grayscale image, obtain the average grayscale value of the pixel points other than the edge points in the any target area, calculate the absolute value of the difference between the grayscale value of each pixel point other than the edge points in the any target area and the average grayscale value, and correspondingly obtain the average value of the absolute values of the differences, denoted as the first average value of the absolute values of the differences. Obtain the addition result of the first average value of the absolute values of the differences and a preset value, denoted as the first addition result, and obtain the reciprocal of the first addition result;
[0029] Obtain the maximum grayscale value and the minimum grayscale value of the pixel points other than the edge points in the any target area, calculate the difference between the maximum grayscale value and the minimum grayscale value, denoted as the first difference, and obtain the reciprocal of the first difference;
[0030] Obtain the average value of the reciprocal of the first addition result and the reciprocal of the first difference as the grayscale uniformity coefficient of the any target area.
[0031] In one embodiment, for any target area in the grayscale image, obtain the average grayscale value of the pixel points other than the edge points in the target area, and obtain the maximum grayscale value and the minimum grayscale value of the pixel points other than the edge points in the target area, and calculate the grayscale uniformity coefficient of the target area:
[0032]
[0033] Among them, α is the grayscale uniformity coefficient of the target area; x i is the grayscale value of the i-th pixel point other than the edge points in the target area; i is the serial number of the pixel points other than the edge points in the target area; m is the number of pixel points other than the edge points in the target area; is the average gray value of the pixel points in the target area except the edge points; x max is the maximum gray value of the pixel points in the target area except the edge points; x min is the minimum gray value of the pixel points in the target area except the edge points; || is the absolute value symbol; c is a preset value.
[0034] It should be noted that the preset value c is a non-zero constant, which is used to prevent calculation errors in the formula when the denominator takes a value of 0; the greater the difference between the gray value of each pixel point in the target area except the edge points and the average gray value, the more uneven the gray values of the pixel points in the target area, and the smaller the gray uniformity coefficient of the target area; the greater the difference between the maximum gray value and the minimum gray value of the pixel points in the target area, the greater the difference in the gray values of the pixel points in the target area, the more uneven the gray values of the pixel points in the target area, and the smaller the gray uniformity coefficient of the target area.
[0035] Thus, the template area in the grayscale image is obtained.
[0036] Step S102, mark the area where any capsule is located in the grayscale image as the reference area, and obtain the suspected reference points in the reference area according to the gray difference between the pixel points in the reference area and the template area.
[0037] After obtaining the template area, the differences between other areas in the grayscale image and the template area can be used to judge other areas in the grayscale image. Mark the area where any capsule is located in the grayscale image except the template area as the reference area. When there is a gray difference between the reference area and the template area, there may be foreign objects in the reference area. According to the gray difference between the pixel points in the reference area and the template area, obtain the suspected reference points in the reference area and the template area.
[0038] Among them, obtaining the suspected reference points in the reference area according to the gray difference between the pixel points in the reference area and the template area includes:
[0039] (1) For any pixel point in the template area, use the four-neighborhood direction of the any pixel point as the traversal direction, respectively obtain the gray value sequences of all pixel points in each traversal direction of the any pixel point in the template area, respectively fit each gray value sequence, obtain the direction fitting curve of the any pixel point, obtain the direction fitting curves of each pixel point in the template area, and respectively fit the direction fitting curves belonging to the same traversal direction to obtain the template fitting curves of the template area in the four traversal directions.
[0040] In one embodiment, for any pixel point in the template region, taking the four-neighborhood direction of the pixel point as the traversal direction, in the template region, the gray values of all pixel points in each traversal direction of the pixel point are respectively obtained. The gray values of the pixel points in one traversal direction form a gray value sequence (excluding the gray value of the pixel point itself), and four gray value sequences of the pixel point are obtained. The least squares method is used to fit the four gray value sequences respectively to obtain four direction fitting curves of the pixel point. Four direction fitting curves of each pixel point in the template region are obtained, and polynomial fitting is used to fit the direction fitting curves of each pixel point in the same traversal direction respectively to obtain template fitting curves in four traversal directions, which are used as the template fitting curves of the template region in four traversal directions. Among them, the least squares method and polynomial fitting belong to the prior art and will not be elaborated here.
[0041] (2) According to the gray values of all pixel points in the four-neighborhood direction of each pixel point in the reference region, gray value change curves of each pixel point in each traversal direction are respectively constructed, and a reference window with a preset length is established on each gray value change curve.
[0042] In one embodiment, for any pixel point in the reference region, the gray values of all pixel points in each traversal direction of the pixel point are obtained. Taking the sequence numbers of all pixel points in each traversal direction as the abscissa and the gray values of all pixel points in each traversal direction as the ordinate respectively, gray value change curves of the pixel point in each traversal direction are constructed, and gray value change curves of each pixel point in the reference region in four traversal directions are obtained. A reference window with a preset length of n is established on each gray value change curve, where n is greater than or equal to 3 and less than Y is the number of gray values in the gray value change curve. In this embodiment, the preset length is set to 5, which is not limited here and can be set according to specific implementation scenarios.
[0043] (3) For any reference window, the template fitting curve with the same traversal direction as the any reference window is obtained, denoted as the target fitting curve. A template window corresponding to the position and length of the any reference window is established on the target fitting curve. According to the gray difference between the any reference window and the template window, the gray difference coefficient of the any reference window is obtained.
[0044] For any reference window, the template fitting curve with the same traversal direction as the reference window is obtained in the template region, denoted as the target fitting curve. A template window with a length of 5 and a position corresponding to the reference window is established on the target fitting curve. According to the gray difference between the reference window and the template window, the gray difference coefficient of the reference window is obtained.
[0045] Specifically, obtain the average gray value of the pixel points in the template window, denoted as the first average value, obtain the average gray value of the pixel points in the reference window, denoted as the second average value, obtain the absolute value of the difference between the first average value and the second average value, denoted as the first absolute difference value, and calculate the difference between the constant 1 and the reciprocal of the first absolute difference value, denoted as the second difference;
[0046] Calculate the gray value differences between every two adjacent pixel points in the template window respectively to obtain a first gray value difference sequence, calculate the gray value differences between every two adjacent pixel points in the reference window respectively to obtain a second gray value difference sequence, obtain the absolute value of the difference between each gray value difference in the first gray value difference sequence and the gray value difference with the corresponding serial number in the second gray value difference sequence, form an absolute difference value sequence, and obtain the ratio of each absolute difference value in the absolute difference value sequence to the gray value difference with the corresponding serial number in the first gray value difference sequence, and correspondingly obtain the average value of the ratios, denoted as the third average value;
[0047] Obtain the average value of the second difference and the third average value as the gray difference coefficient of the reference window.
[0048] In an embodiment, obtain the average gray value of the pixel points in the template window, denote the average gray value of the pixel points in the template window as the first average value, obtain the average gray value of the pixel points in the reference window, denote the average gray value of the pixel points in the reference window as the second average value, obtain the gray value differences between every two adjacent pixel points in the template window, and form a first gray value difference sequence with the obtained gray value differences in the template window, obtain the gray value differences between every two adjacent pixel points in the reference window, and form a second gray value difference sequence with the obtained gray value differences in the reference window, and calculate the gray difference coefficient of the reference window:
[0049]
[0050] where C is the gray difference coefficient of the reference window; is the first average value; is the second average value; N is the number of pixel points in the template window or the reference window; D1 q is the q-th gray value difference in the first gray value difference sequence; D2 q is the q-th gray value difference in the second gray value difference sequence; q is the serial number of the gray value differences in the first gray value difference sequence and the second gray value difference sequence; || is the absolute value symbol.
[0051] It should be noted that represents the numerical difference between the template window and the reference window. The greater the difference between the first average value and the second average value, the greater the numerical difference between the template window and the reference window, and the greater the gray difference coefficient of the reference window; It represents the average difference in gray-scale changes between each pixel point in the template window and the reference window. The greater the difference between the corresponding gray-scale value differences in the first gray-scale value difference sequence and the second gray-scale value difference sequence, the greater the difference in gray-scale changes between each pixel point in the template window and the reference window, and the greater the gray-scale difference coefficient of the reference window.
[0052] (3) Obtain the gray-scale difference coefficient of each reference window in the reference region. When the gray-scale difference coefficient of any reference window is within the preset gray-scale difference coefficient interval, mark all pixel points corresponding to the any reference window as suspected reference points.
[0053] Obtain the gray-scale difference coefficient of each reference window in the reference region. Since the gray-scale difference between foreign object pixel points and capsule pixel points is small, and the change in the gray-scale value in the overlapping region is due to the superposition of multiple capsules, resulting in a decrease in light transmittance and reflectivity, and the gray-scale value changes. The gray-scale value of the region with a gradual change in its own gray-scale value undergoes a mutation, resulting in uneven gray-scale value regions of some pixel points inside the capsule. Therefore, the gray-scale difference coefficient interval is set to (0, 0.2). This is not restricted here and can be set according to specific implementation scenarios. When the gray-scale difference coefficient of any reference window is within (0, 0.2), the difference in the reference window may be due to the presence of foreign objects. Mark all pixel points in the reference window as suspected reference points.
[0054] Thus, the suspected reference points in the reference region are obtained.
[0055] In step S103, according to the suspected reference points in the reference region and the gray-scale differences of the pixel points in the reference region, obtain the seed points and the corresponding growth thresholds in the reference region. Perform region growing on the seed points corresponding to each growth threshold in the reference region to obtain all foreign object reference points in the reference region.
[0056] After obtaining the suspected reference points in the reference region, to obtain the foreign object reference points in the reference region, it is necessary to obtain the seed points and the corresponding growth thresholds in the suspected reference points, and use the seed points and the corresponding growth thresholds to perform region growing, so as to obtain the foreign object reference points in the reference region.
[0057] Since the foreign object is inside the fish oil soft capsule and is generally in a solid state, the solid foreign object will absorb light, making the gray value of the pixel points in the foreign object area lower than that of the pixel points in the capsule itself area on the grayscale image. Therefore, there is an edge division between the pixel points in the foreign object area and the pixel points in the capsule itself area. Thus, the suspected reference edge points between the pixel points in the foreign object area and the pixel points in the capsule itself area can be obtained by obtaining the gray value difference between the suspected reference points and the pixel points in the reference area, and then the seed points and growth thresholds of the foreign object area in the reference area can be obtained through the suspected reference edge points and the suspected reference points.
[0058] Specifically, obtain a reference window with a gray value difference coefficient within a preset gray value difference coefficient interval, denoted as the target reference window. For any suspected reference point in any target reference window, obtain each pixel point in each traversal direction of the any suspected reference point in the reference area, denoted as the target pixel point. If the difference between the gradient value of any target pixel point and the gradient value of the any suspected reference point is greater than the preset gradient value difference threshold, then in the traversal direction corresponding to the any target pixel point, establish a first window centered on the any target pixel point, and obtain the gray value difference coefficient of the first window. When the gray value difference coefficient of the first window is within the preset gray value difference coefficient interval, determine the any target pixel point as a suspected edge point, and select the pixel point with the larger gradient value among the any suspected reference point and the suspected edge point as the suspected reference edge point;
[0059] Obtain all the suspected reference edge points corresponding to the any suspected reference point, obtain all the suspected reference edge points corresponding to all the suspected reference points in the any target reference window, calculate the average gray value of all the suspected reference edge points corresponding to all the suspected reference points in the any target reference window, denoted as the fourth average value, and select the suspected reference point with the same gray value as the fourth average value in the any target reference window as the seed point;
[0060] Obtain the minimum gray value among the suspected reference points and all the suspected edge points in the any target reference window, and obtain the difference between the fourth average value and the minimum gray value as the growth threshold of the seed point;
[0061] Obtain the seed points and the corresponding growth thresholds in each target reference window to form the seed points and the corresponding growth thresholds in the reference area.
[0062] In one embodiment, a reference window with a gray - scale difference coefficient within (0, 0.2) is denoted as a target reference window. Taking any target reference window as an example, and denoting it as target reference window 1, for a suspected reference point A in target reference window 1, each pixel point of the suspected reference point A in each traversal direction is obtained in the reference area. Each pixel point of the suspected reference point A in each traversal direction is denoted as a target pixel point. The gradient value of each target pixel point is obtained. The gradient value belongs to the prior art and will not be elaborated here. If there exists a target pixel point B, and the difference between the gradient value of target pixel point B and that of the suspected reference point A is greater than the gradient value difference threshold 60 (not limited here and can be set according to specific implementation scenarios), then in the traversal direction corresponding to target pixel point B, with target pixel point B as the center, a first window with a length of 5 is established. The gray - scale difference coefficient of the first window is obtained according to the calculation method of the gray - scale difference coefficient of the reference window. When the gray - scale difference coefficient of the first window is within (0, 0.2), target pixel point B is denoted as a suspected edge point B. Since the gray - scale values of the internal pixel points of the foreign object area have small differences and can be regarded as a uniform image, while the gradient value of the foreign object edge point is relatively large, the point with the larger gradient value among the suspected edge point B and the suspected reference point A is denoted as a suspected reference edge point.
[0063] According to the above method for obtaining the suspected reference edge point, the suspected reference edge points corresponding to the suspected reference point A in four traversal directions are obtained. The suspected reference edge points corresponding to all the suspected reference points in target reference window 1 in four traversal directions are obtained. The average gray - scale value of all the suspected reference edge points corresponding to all the suspected reference points in target reference window 1 is calculated. The average gray - scale value of all the suspected reference edge points corresponding to all the suspected reference points in target reference window 1 is denoted as the fourth average value. The suspected reference point with the same gray - scale value as the fourth average value in target reference window 1 is selected as the seed point in target reference window 1.
[0064] Among the suspected reference points in target reference window 1 and all the suspected edge points corresponding to all the suspected reference points in target reference window 1, the pixel point with the smallest gray - scale value is selected. The gray - scale value of the pixel point with the smallest gray - scale value is denoted as the minimum gray - scale value. The difference between the fourth average value and the minimum gray - scale value is obtained as the growth threshold of the seed points in target reference window 1. It should be noted that the growth thresholds of all the seed points in target reference window 1 are the same, all being one growth threshold.
[0065] According to the method for obtaining the seed points and the growth threshold in target reference window 1, the seed points and the corresponding growth thresholds in each target reference window in the reference area are obtained, and the seed points and the corresponding growth thresholds in the reference area are obtained.
[0066] After obtaining the seed points and corresponding growth thresholds in the reference region, region growing can be performed based on the seed points and corresponding growth thresholds to obtain the foreign object reference points in the reference region.
[0067] Specifically, for any seed point in the reference region, region growing is performed in the eight-neighborhood direction of the any seed point according to the growth threshold corresponding to the any seed point to obtain suspected foreign object reference points. The any seed point and the suspected foreign object reference points form a suspected foreign object reference region. In the suspected foreign object reference region, the suspected foreign object reference points adjacent to the non-suspected foreign object reference points are screened out and recorded as target reference points. If there are at least two target reference points whose gray values are greater than or less than the gray values of the adjacent non-suspected foreign object reference points in any traversal direction, it is determined that all the pixel points in the suspected foreign object reference region are foreign object reference points; the foreign object reference points corresponding to each seed point in the reference region are obtained to get all the foreign object reference points in the reference region.
[0068] In one embodiment, for any seed point in the reference region, with the seed point as the center and the eight-neighborhood direction of the seed point as the growth direction, region growing is performed according to the growth threshold corresponding to the seed point to obtain suspected foreign object reference points. The seed point and the obtained suspected foreign object reference points form a suspected foreign object reference region. In the suspected foreign object reference region, the suspected foreign object reference points adjacent to the non-suspected foreign object reference points (i.e., the edge points in the suspected foreign object reference region) are screened out. The suspected foreign object reference points adjacent to the non-suspected foreign object reference points are recorded as target reference points. If there are at least two target reference points whose gray values are greater than or less than the gray values of the adjacent non-suspected foreign object reference points in any traversal direction, it is determined that all the pixel points in the suspected foreign object reference region are foreign object reference points.
[0069] For example, taking the seed point D in the reference region as the center and the eight-neighborhood direction of the seed point D as the growth direction, region growing is performed according to the growth threshold corresponding to the seed point D to obtain suspected foreign object reference points. The seed point D and the obtained suspected foreign object reference points form a suspected foreign object reference region. In the suspected foreign object reference region, the suspected foreign object reference points adjacent to the non-suspected foreign object reference points (i.e., the edge points in the suspected foreign object reference region) are screened out. The suspected foreign object reference points adjacent to the non-suspected foreign object reference points are recorded as target reference points. The target reference point E is the upper edge point in the suspected foreign object reference region, and the pixel point F adjacent to the left of the target reference point E is a non-suspected foreign object reference point. The target reference point H is the lower edge point in the suspected foreign object reference region, and the pixel point I adjacent to the left of the target reference point H is a non-suspected foreign object reference point. If the gray value of the target reference point E is less than the gray value of the pixel point F, and the gray value of the target reference point H is less than the gray value of the pixel point I, it is confirmed that all the pixel points in the suspected foreign object reference region centered on the seed point D are foreign object reference points.
[0070] According to the method for obtaining foreign object reference points in the suspected foreign object reference area centered on the seed point D in the reference area, obtain the foreign object reference points corresponding to each seed point in the reference area, and obtain all the foreign object reference points in the reference area.
[0071] So far, all the foreign object reference points in the reference area have been obtained.
[0072] Step S104: For any non-foreign object reference point adjacent to any foreign object reference point, obtain the overlap coefficient of the any non-foreign object reference point. When the overlap coefficient of the any non-foreign object reference point is greater than the preset overlap coefficient threshold, obtain the seed point corresponding to the any foreign object reference point, denoted as the target seed point. According to the target seed point, obtain a new seed point and a corresponding new growth threshold in the neighborhood of the any non-foreign object reference point, and perform region growing on each new seed point according to its corresponding new growth threshold to obtain new foreign object reference points.
[0073] Since the change in the gray value of the overlapping area is due to the superposition of multiple capsules, resulting in a decrease in light transmittance and reflectivity, the gray value changes. The gray value of the area with a gradual change in its own gray value undergoes a sudden change, resulting in uneven gray values of some pixel points inside the capsule, and a large difference in gray values between different regions. Using a fixed threshold for growth will cause the growth to be interrupted forcedly, and a complete foreign object area cannot be obtained. Therefore, the foreign object reference points in the reference area cannot form a complete foreign object area.
[0074] To solve the above problems, it is necessary to obtain the overlap coefficient of the adjacent non-foreign object reference points based on the foreign object reference points in the reference area. For any non-foreign object reference point adjacent to any foreign object reference point, determine whether the adjacent non-foreign object reference point is affected by overlap. When the adjacent non-foreign object reference point is affected by overlap, it is necessary to obtain a new seed point and a new growth threshold in the overlapping area and continue the growth of the foreign object area.
[0075] Among them, the method for obtaining the overlap coefficient of the non-foreign object reference point is as follows:
[0076] Taking the any non-foreign object reference point as the center, establish a reference window with a preset length in each traversal direction of the any non-foreign object reference point. For any reference window, obtain a template window in the template area that has the same traversal direction as the any reference window and the corresponding position and length.
[0077] Obtain the absolute value of the difference between the gray value of each pixel point in the template window and the gray value of the pixel point with the corresponding serial number in any one of the reference windows, and correspondingly obtain the average value of the absolute values of the differences, which is denoted as the second average value of the absolute values of the differences. Obtain the difference between the constant 1 and the reciprocal of the second average value of the absolute values of the differences, which is denoted as the third difference. Obtain the gray difference coefficient of any one of the reference windows. Obtain the average value of the third difference and the gray difference coefficient of any one of the reference windows as the overlap coefficient of any one of the reference windows;
[0078] Obtain the overlap coefficient of the reference windows in each traversal direction of any non-foreign object reference point, and correspondingly obtain the average value of the overlap coefficients as the overlap coefficient of any non-foreign object reference point.
[0079] In one embodiment, for any non-foreign object reference point adjacent to any foreign object reference point, with the non-foreign object reference point as the center, establish a reference window with a length of 5 in the four traversal directions of any non-foreign object reference point. For any reference window in the four traversal directions of the non-foreign object reference point, obtain a template window with the same traversal direction as the reference window and a length of 5 at the corresponding position in the template area. Obtain the gray difference coefficient of the reference window and calculate the overlap coefficient of the reference window:
[0080]
[0081] where, β is the overlap coefficient of the reference window; S1 r is the gray value of the r-th pixel point in the template window; S2 r is the gray value of the r-th pixel point in the reference window; r is the serial number of the pixel points in the template window and the reference window; g is the number of pixel points in the template window and the reference window; C is the gray difference coefficient of the reference window; || is the absolute value symbol.
[0082] It should be noted that the greater the difference in the gray values of the pixel points in the template window and the reference window, the more the gray value distribution of the pixel points in the reference window does not conform to the template window, the greater the possibility that the reference window is affected by overlap, and the greater the overlap coefficient of the reference window; the greater the gray difference coefficient of the reference window, the greater the difference between the reference window and the template window, and the greater the overlap coefficient of the reference window.
[0083] Obtain the overlap coefficient of each reference window in the four traversal directions of the non-foreign object reference point, and take the average value of the overlap coefficients of each reference window in the four traversal directions of the non-foreign object reference point as the overlap coefficient of the non-foreign object reference point.
[0084] Set the overlap coefficient threshold to 0.3. There is no restriction here and it can be set according to the specific implementation scenario. When the overlap coefficient of any non-foreign object reference point adjacent to any foreign object reference point is greater than or equal to 0.3, it is determined that the non-foreign object reference point is affected by overlap interference. At this time, it is necessary to obtain the seed point corresponding to the foreign object reference point, record the seed point corresponding to the foreign object reference point as the target seed point, and according to the target seed point, obtain a new seed point and a new growth threshold in the neighborhood of the non-foreign object reference point, and continue to grow.
[0085] Among them, obtaining a new seed point in the neighborhood of the non-foreign object reference point includes:
[0086] In the reference area, obtain the overlap coefficient of the reference window in each traversal direction of each pixel point, form a first reference window set with the reference windows in each traversal direction of each pixel point, record the reference window in any traversal direction of the any non-foreign object reference point as the second window, obtain at least k reference windows with the same overlap coefficient as the second window in the first reference window set, record them as target windows, respectively obtain the difference between the mean gray value of the pixel points in each target window and the mean gray value of the pixel points in the second window, form a first difference sequence, and obtain the mean of the first difference sequence as the gray value change of the second window;
[0087] Obtain the gray value change corresponding to the reference window in each traversal direction of the any non-foreign object reference point, and correspondingly obtain the mean of the gray value changes as the gray value change of the any non-foreign object reference point;
[0088] Obtain the addition result of the gray value change of the any non-foreign object reference point and the gray value of the target seed point, record it as the second addition result, and in the eight-neighborhood of the any non-foreign object reference point, obtain the pixel points with the same gray value as the second addition result and that are not foreign object reference points as new seed points.
[0089] In one embodiment, the overlapping coefficient of the reference window in each traversal direction of each pixel point in the reference region is obtained, and the reference windows in each traversal direction of each pixel point in the reference region are formed into a first reference window set. Taking the non-foreign object reference point J as an example, the reference window in any traversal direction of the non-foreign object reference point J is denoted as the second window. Five reference windows with the same overlapping coefficient as the second window are obtained from the first reference window set and denoted as target windows. There is no limitation here and it can be set according to the specific implementation scenario. The difference between the mean gray value of the pixel points in each target window and the mean gray value of the pixel points in the second window is obtained respectively to form a first difference sequence, and the mean value of the first difference sequence is taken as the gray value change of the second window. The gray value changes corresponding to the reference windows in each traversal direction of the non-foreign object reference point J are obtained, and the mean value of the gray value changes corresponding to the reference windows in each traversal direction of the non-foreign object reference point J is taken as the gray value change of the non-foreign object reference point J. The second addition result of the gray value change of the non-foreign object reference point J and the gray value of the target seed point is obtained. In the eight-neighborhood of the non-foreign object reference point J, the pixel points with the same gray value as the second addition result and not being foreign object reference points are obtained as new seed points.
[0090] When there are no pixel points in the eight-neighborhood of the non-foreign object reference point J other than the foreign object reference points with the same gray value as the second addition result, a suspected region with a length of 4×4 centered on the foreign object reference point J is established. There is no limitation here and it can be set according to the specific implementation scenario. The pixel points with the same gray value as the second addition result and not being foreign object reference points are obtained as seed points in the suspected region. If there are no pixel points in the suspected region with the same gray value as the second addition result and not being foreign object reference points, it is determined that there are no new seed points in the region affected by overlapping interference.
[0091] Among them, obtaining the new growth threshold in the neighborhood of the non-foreign object reference point includes:
[0092] In the reference region, non-foreign-object reference points with an overlap coefficient greater than a preset overlap coefficient threshold are grouped to form an overlap region. The overlap coefficient of the reference window in each traversal direction of each non-foreign-object reference point in the overlap region is obtained. The reference windows in each traversal direction of each non-foreign-object reference point in the overlap region are grouped to form a second reference window set. In the second reference window set, a reference window with any overlap coefficient in any traversal direction is selected and denoted as the third window. The gray value difference between adjacent pixel points within the third window is obtained, and a corresponding third gray value difference sequence is obtained. The mean value of the third gray value difference sequence is calculated and denoted as the difference mean value of the third window. In the second reference window set, at least two reference windows with the same traversal direction and the same overlap coefficient as the third window are selected and denoted as new target windows. The difference mean value of each new target window is obtained correspondingly. The average value of all difference mean values is used as the gray difference value of the any overlap coefficient in the any traversal direction.
[0093] The gray difference value of the any overlap coefficient in each traversal direction is obtained, and the mean value of the gray difference values is used as the growth threshold corresponding to the any overlap coefficient. In the overlap region, growth thresholds corresponding to at least three different overlap coefficients are obtained to form a data sequence. The data sequence is fitted to obtain a fitting equation between the overlap coefficient and the growth threshold. The overlap coefficient of each new seed point is obtained, and the growth threshold corresponding to each new seed point is obtained according to the fitting equation and denoted as the new growth threshold.
[0094] In an embodiment, in the reference region, non-foreign-object reference points with an overlap coefficient greater than 0.3 are grouped to form an overlap region. The overlap coefficient of the reference window in each traversal direction of each non-foreign-object reference point in the overlap region is obtained. The reference windows in each traversal direction of each non-foreign-object reference point in the overlap region are grouped to form a second reference window set. Taking the overlap coefficient β1 as an example, the growth threshold corresponding to the overlap coefficient β1 is calculated:
[0095]
[0096] where μ is the growth threshold corresponding to the overlap coefficient β1; K d is the number of windows with the overlap coefficient β1 in the d-th traversal direction selected from the second reference window set; is the difference mean value between pixel points in the p-th window with the overlap coefficient β1 in the d-th traversal direction; d is the serial number of the traversal direction of each pixel point; p is the number of different overlap coefficients selected in the overlap region.
[0097] It should be noted that the greater the average difference between the pixel points in the windows with the overlapping coefficient β1 in the second reference window set, the greater the difference in the gray values of the pixel points in the windows with the overlapping coefficient β1 in the second reference window set, the greater the degree of interference caused by overlapping in the windows with the overlapping coefficient β1 in the second reference window set, the greater the growth threshold required for the foreign object to grow, and the greater the growth threshold corresponding to the overlapping coefficient β1.
[0098] Obtain the growth thresholds corresponding to at least three different overlapping coefficients to form a data sequence, and use the least squares method to fit the data sequence to obtain the fitting equation between the overlapping coefficient and the growth threshold. The least squares method belongs to the prior art and will not be elaborated here. Obtain the overlapping coefficient of each new seed point, and obtain the growth threshold corresponding to each new seed point according to the fitting equation between the overlapping coefficient and the growth threshold. Denote the growth threshold corresponding to each new seed point obtained according to the fitting equation between the overlapping coefficient and the growth threshold as the new growth threshold.
[0099] After obtaining the new seed points and new growth thresholds of the overlapping region, new foreign object reference points can be obtained according to the overlapping coefficient and change trend of the new seed points.
[0100] Specifically, for any new seed point, perform region growth in the eight-neighborhood directions of the new seed point according to the new growth threshold corresponding to the new seed point to obtain new suspected foreign object reference points, and form a new suspected foreign object reference region with the new seed point and the new suspected foreign object reference points.
[0101] Denote the region where the foreign object reference point is located as the initial foreign object region. In the initial foreign object region, for any foreign object reference point, take the eight-neighborhood directions of the foreign object reference point as the neighborhood directions, obtain the gray values of the pixel points of the foreign object reference point in each neighborhood direction, respectively fit the gray values of the pixel points of the foreign object reference point in each neighborhood direction to obtain the fitting equation of the foreign object reference point in each neighborhood direction, and denote the slope of each fitting equation as the gray change index of the foreign object reference point in each neighborhood direction; obtain the gray change indexes of each foreign object reference point in each neighborhood direction in the initial foreign object region, and obtain the average value of the gray change indexes of all foreign object reference points in each neighborhood direction as the overall gray change index of the initial foreign object region in each neighborhood direction.
[0102] For any pixel point in the new suspected foreign object reference area, obtain the gray-scale change index of the pixel point in each neighborhood direction. When the difference between the gray-scale change index of the pixel point in each neighborhood direction and the overall gray-scale change index of the initial foreign object area in the corresponding neighborhood direction is within a preset gray-scale change interval, determine the pixel point as a suspected foreign object point. Obtain all the suspected foreign object points in the new suspected foreign object reference area, and form a suspected foreign object area with all the suspected foreign object points in the new suspected foreign object reference area. Obtain the overall gray-scale change index of the suspected foreign object area in each neighborhood direction. When the difference between the overall gray-scale change index of the suspected foreign object area in each neighborhood direction and the overall gray-scale change index of the initial foreign object area in the corresponding neighborhood direction is within a preset gray-scale change interval, determine all the suspected foreign object points as new foreign object reference points.
[0103] If a foreign object reference point has adjacent pixel points in any one neighborhood direction and the number is greater than 3, calculate the gray-scale value change index in this direction. If the foreign object reference point does not meet the condition of having adjacent pixel points and the number being greater than 3 in a certain direction, do not calculate the gray-scale value change index in this direction.
[0104] For example, the overall gray-scale change indexes of the initial foreign object area in each neighborhood direction are K1, K2, K3, K4, K5, K6, K7, K8 respectively, and the gray-scale change indexes of the pixel point O in the new suspected foreign object reference area in each neighborhood direction are K1', K2', K3', K4', K5', K6', K7', K8'. When the difference between the gray-scale change index of the pixel point O in each neighborhood direction and the overall gray-scale change index of the initial foreign object area in the corresponding neighborhood direction is within [-0.5, 0.5], record the pixel point O as a suspected foreign object point. There is no restriction here and it can be set according to the specific implementation scenario. Obtain all the suspected foreign object points in the new suspected foreign object reference area and form a suspected foreign object area. The overall gray-scale change indexes of the suspected foreign object area in each neighborhood direction are K1'', K2'', K3'', K4'', K5'', K6'', K7'', K8''. When the difference between the overall gray-scale change index of the suspected foreign object area in each neighborhood direction and the overall gray-scale change index of the initial foreign object area in the corresponding neighborhood direction is within [-0.5, 0.5], determine all the suspected foreign object points as new foreign object reference points.
[0105] Thus, new foreign object reference points in the overlapping area where any non-foreign object reference point adjacent to any foreign object reference point is located are obtained.
[0106] Step S105: Obtain all new foreign object reference points in the reference area according to all foreign object reference points, form the foreign object area of the reference area by combining all the foreign object reference points and new foreign object reference points in the reference area, obtain the foreign object area of each capsule area in the grayscale image, and perform defect recognition on the fish oil soft capsule image.
[0107] According to the method for obtaining new foreign object reference points in the overlapping area where the above non-foreign object reference points are located, obtain all new foreign object reference points in the reference area, form the foreign object area in the reference area by combining all the foreign object reference points and new foreign object reference points in the reference area, obtain the proportion of the pixel points of the foreign object area in the reference area, divide the defects of the fish oil soft capsule into minor defects and major defects. When the proportion of the pixel points of the foreign object area in the reference area is less than or equal to 0.01 (no limit here, which can be set according to the specific implementation scenario), determine that the fish oil soft capsule corresponding to the reference area is a minor defect. At this time, single-piece manual inspection of the fish oil soft capsule corresponding to the reference area is required to prevent misjudgment; when the proportion of the pixel points of the foreign object area in the reference area is greater than 0.01, determine that the fish oil soft capsule corresponding to the reference area is a major defect, and directly remove the fish oil soft capsule corresponding to the reference area at this time. Similarly, obtain the foreign object area in the reference area where each capsule is located in the grayscale image, and perform defect recognition on the grayscale image of the fish oil soft capsule.
[0108] In summary, in this embodiment, an image of a fish oil soft capsule to be recognized is obtained, the image of the fish oil soft capsule is processed to obtain a grayscale image, and a template region in the grayscale image is obtained according to the grayscale distribution characteristics of the region where each capsule is located in the grayscale image; any region where a capsule is located in the grayscale image is denoted as a reference region, and according to the grayscale difference between the pixel points in the reference region and the template region, suspected reference points in the reference region are obtained; according to the suspected reference points in the reference region and the grayscale difference between the pixel points in the reference region, seed points in the reference region and corresponding growth thresholds are obtained, and region growing is performed on the seed points corresponding to each growth threshold in the reference region to obtain all foreign object reference points in the reference region; for any non-foreign object reference point adjacent to any foreign object reference point, an overlap coefficient of the any non-foreign object reference point is obtained, and when the overlap coefficient of the any non-foreign object reference point is greater than a preset overlap coefficient threshold, the seed point corresponding to the any foreign object reference point is obtained and denoted as a target seed point, and according to the target seed point, new seed points and corresponding new growth thresholds are obtained in the neighborhood of the any non-foreign object reference point, and region growing is performed on the new seed points corresponding to each new growth threshold to obtain new foreign object reference points; according to all foreign object reference points, all new foreign object reference points in the reference region are obtained, the foreign object regions of the reference region are composed of all foreign object reference points and new foreign object reference points in the reference region, the foreign object regions of the regions where each capsule is located in the grayscale image are obtained, and defect recognition is performed on the image of the fish oil soft capsule. In this embodiment, first, foreign object reference points in non-overlapping regions are obtained, and then by obtaining the overlap coefficient, it is judged whether pixel points are interfered by overlap. When pixel points are interfered by overlap, new seed points and new growth thresholds are obtained in the overlapping region, and new foreign object reference points in the overlapping region are obtained through the new seed points and new growth thresholds, so as to obtain a complete foreign object image, reduce the problem of incomplete foreign object images caused by the interference of the overlapping region on the grayscale value, and make the recognition of appearance defects in multiple fish oil soft capsules more accurate.
[0109] The above embodiments are only used to illustrate the technical solutions of the present invention and are not intended to limit them; although the present invention has been described in detail with reference to the foregoing embodiments, those of ordinary skill in the art should understand that they can still modify the technical solutions described in the foregoing embodiments, or perform equivalent replacements on some of the technical features; and these modifications or replacements do not make the essence of the corresponding technical solutions deviate from the spirit and scope of the technical solutions of the embodiments of the present invention, and should all be included in the protection scope of the present invention.
Claims
1. A method for quickly identifying appearance defects of fish oil soft capsules, characterized in that: The method comprises: Acquire a fish oil soft capsule image to be identified, process the fish oil soft capsule image to obtain a grayscale image, and acquire a template area in the grayscale image according to the grayscale distribution characteristics of the area where each capsule is located in the grayscale image; Recording a region where any capsule in the grayscale image is located as a reference region, and obtaining a suspected reference point in the reference region according to a grayscale difference between pixels in the reference region and the template region; According to the grayscale difference between the suspected reference point in the reference area and the pixel point in the reference area, the seed point in the reference area and the corresponding growth threshold are obtained, and according to each growth threshold, the corresponding seed point in the reference area is subjected to regional growth to obtain all the foreign body reference points in the reference area; For any non-foreign object reference point adjacent to any foreign object reference point, obtain the overlap coefficient of any non-foreign object reference point; when the overlap coefficient of any non-foreign object reference point is greater than a preset overlap coefficient threshold, obtain a seed point corresponding to any foreign object reference point and record it as a target seed point; based on the target seed point, obtain a new seed point and a corresponding new growth threshold in the neighborhood of any non-foreign object reference point; perform regional growth on the new seed point corresponding to each new growth threshold to obtain a new foreign object reference point; According to all foreign matter reference points, all new foreign matter reference points in the reference area are obtained, all foreign matter reference points and new foreign matter reference points in the reference area are combined to form the foreign matter area of the reference area, the foreign matter area of the area where each capsule is located in the grayscale image is obtained, and defects of the fish oil soft capsule image are identified.
2. The method for quickly identifying appearance defects of fish oil soft capsules according to claim 1, characterized in that: The step of acquiring the template region in the grayscale image according to the grayscale distribution characteristics of the region where each capsule is located in the grayscale image comprises: Edge detection is used to screen edge points in the grayscale image, and the area contained by continuous and uninterrupted edge points is used as the target area. The grayscale uniformity coefficient of each target area is calculated, and the target area with the largest grayscale uniformity coefficient is selected as the template area.
3. A method for quickly identifying appearance defects of fish oil soft capsules according to claim 2, characterized in that: The step of calculating the grayscale uniformity coefficient of each target area includes: For any target area in the grayscale image, obtain the grayscale value mean of the pixel points other than the edge points in the target area, calculate the absolute value of the difference between the grayscale value of each pixel point other than the edge points in the target area and the grayscale value mean, and obtain the mean of the absolute values of the differences, which is recorded as the first mean of the absolute values of the differences, obtain the addition result of the first mean of the absolute values of the differences and a preset value, which is recorded as the first addition result, and obtain the inverse of the first addition result; Obtain the maximum grayscale value and the minimum grayscale value of the pixel points other than the edge points in any target area, calculate the difference between the maximum grayscale value and the minimum grayscale value, record it as a first difference, and obtain the reciprocal of the first difference; The average of the reciprocal of the first addition result and the reciprocal of the first difference is obtained as the grayscale uniformity coefficient of any target area.
4. The method for quickly identifying appearance defects of fish oil soft capsules according to claim 1, characterized in that: The obtaining of the suspected reference point in the reference area according to the grayscale difference between the pixel points in the reference area and the template area includes: For any pixel point in the template area, the four neighborhood directions of the any pixel point are taken as traversal directions, the grayscale values of all the pixels in each traversal direction of the any pixel point in the template area are respectively obtained to form a grayscale value sequence, each of the grayscale value sequences is fitted respectively to obtain a direction fitting curve of the any pixel point, the direction fitting curve of each pixel point in the template area is obtained, the direction fitting curves belonging to the same traversal direction are respectively fitted to obtain the template fitting curves of the template area in four traversal directions; According to the grayscale values of all pixels in the four neighborhood directions of each pixel in the reference area, a grayscale value change curve of each pixel in each traversal direction is constructed respectively, and a reference window of a preset length is established on each grayscale value change curve; For any reference window, a template fitting curve having the same traversal direction as that of the any reference window is obtained, recorded as a target fitting curve, a template window corresponding to the position and length of the any reference window is established on the target fitting curve, and a grayscale difference coefficient of the any reference window is obtained according to the grayscale difference between the any reference window and the template window; The grayscale difference coefficient of each reference window in the reference area is obtained, and when the grayscale difference coefficient of any reference window is within a preset grayscale difference coefficient interval, all pixel points corresponding to the any reference window are recorded as suspected reference points.
5. A method for quickly identifying appearance defects of fish oil soft capsules according to claim 4, characterized in that: The step of obtaining a grayscale difference coefficient of any reference window according to a grayscale difference between any reference window and the template window includes: Obtaining the mean grayscale value of the pixels in the template window, recorded as the first mean, obtaining the mean grayscale value of the pixels in the reference window, recorded as the second mean, obtaining the absolute value of the difference between the first mean and the second mean, recorded as the first absolute value of the difference, calculating the difference between a constant 1 and the reciprocal of the first absolute value of the difference, recorded as the second difference; The grayscale value difference of each two adjacent pixels in the template window is calculated respectively to obtain a first grayscale value difference sequence, the grayscale value difference of each two adjacent pixels in the reference window is calculated respectively to obtain a second grayscale value difference sequence, the absolute value of the difference between each grayscale value difference in the first grayscale value difference sequence and the grayscale value difference of the corresponding sequence number in the second grayscale value difference sequence is obtained to form a difference absolute value sequence, the ratio of each difference absolute value in the difference absolute value sequence to the grayscale value difference of the corresponding sequence number in the first grayscale value difference sequence is obtained, and the ratio mean is obtained accordingly, which is recorded as the third mean; An average value of the second difference and the third mean value is obtained as the grayscale difference coefficient of the reference window.
6. A method for quickly identifying appearance defects of fish oil soft capsules according to claim 4, characterized in that: The step of obtaining a seed point in the reference area and a corresponding growth threshold value according to a grayscale difference between a suspected reference point in the reference area and a pixel point in the reference area includes: A reference window whose grayscale difference coefficient is within a preset grayscale difference coefficient interval is obtained, which is recorded as a target reference window. For any suspected reference point in any target reference window, each pixel point in each traversal direction of any suspected reference point is obtained in the reference area, which is recorded as a target pixel point. If there is any target pixel point whose gradient value difference with the gradient value of any suspected reference point is greater than a preset gradient value difference threshold, a first window is established in the traversal direction corresponding to any target pixel point with the any target pixel point as the center, and the grayscale difference coefficient of the first window is obtained. When the grayscale difference coefficient of the first window is within the preset grayscale difference coefficient interval, the any target pixel point is determined to be a suspected edge point, and a pixel point with a larger gradient value between any suspected reference point and the suspected edge point is selected as a suspected reference edge point. Obtain all suspected reference edge points corresponding to any suspected reference point, obtain suspected reference edge points corresponding to all suspected reference points in any target reference window, calculate the gray value mean of the suspected reference edge points corresponding to all suspected reference points in any target reference window, record it as a fourth mean, and select a suspected reference point in any target reference window whose gray value is the same as the fourth mean as a seed point; Obtaining the minimum grayscale value of the suspected reference points and all the suspected edge points in any target reference window, and obtaining the difference between the fourth mean value and the minimum grayscale value as the growth threshold of the seed point; The seed points and the corresponding growth threshold in each of the target reference windows are obtained to form the seed points and the corresponding growth threshold in the reference area.
7. The method for quickly identifying appearance defects of fish oil soft capsules according to claim 1, characterized in that: The step of performing region growth on the seed point corresponding to each growth threshold in the reference region to obtain all foreign body reference points in the reference region includes: For any seed point in the reference area, regional growth is performed in the eight-neighborhood direction of any seed point according to the growth threshold corresponding to the any seed point to obtain a suspected foreign body reference point, and the any seed point and the suspected foreign body reference point form a suspected foreign body reference area, and the suspected foreign body reference points adjacent to the non-suspected foreign body reference points are screened in the suspected foreign body reference area and recorded as target reference points. If there are at least two target reference points whose grayscale values are greater than or less than the grayscale values of the non-suspected foreign body reference points adjacent to them in any traversal direction, it is determined that all the pixel points in the suspected foreign body reference area are foreign body reference points; The foreign body reference point corresponding to each seed point in the reference area is obtained to obtain all foreign body reference points in the reference area.
8. The method for quickly identifying appearance defects of fish oil soft capsules according to claim 5, characterized in that: The obtaining the overlap coefficient of any non-foreign object reference point includes: Taking any non-foreign object reference point as the center, a reference window of preset length is established in each traversal direction of any non-foreign object reference point, and for any reference window, a template window having the same traversal direction and corresponding position and length as any reference window is obtained in the template area; Respectively obtain the absolute value of the difference between the grayscale values of each pixel in the template window and the pixel of the corresponding serial number in any reference window, obtain the mean of the absolute values of the differences, record it as the second mean of the absolute values of the differences, obtain the difference between a constant 1 and the reciprocal of the mean of the absolute values of the second differences, record it as the third difference, obtain the grayscale difference coefficient of any reference window, obtain the mean of the grayscale difference coefficient of the third difference and any reference window, as the overlap coefficient of any reference window; The overlapping coefficient of the reference window in each traversal direction of any non-foreign object reference point is obtained, and the corresponding average of the overlapping coefficients is obtained as the overlapping coefficient of any non-foreign object reference point.
9. A method for quickly identifying appearance defects of fish oil soft capsules according to claim 8, characterized in that: The step of acquiring a new seed point and a corresponding new growth threshold in a neighborhood of any non-foreign object reference point according to the target seed point includes: In the reference area, the overlap coefficient of the reference window in each traversal direction of each pixel point is obtained, and the reference windows in each traversal direction of each pixel point are combined into a first reference window set, and the reference window in any traversal direction of any non-foreign object reference point is recorded as a second window. At least k reference windows with the same overlap coefficient as the second window are obtained in the first reference window set and recorded as target windows, and the difference between the mean grayscale value of the pixel point in each target window and the mean grayscale value of the pixel point in the second window is obtained to form a first difference sequence, and the mean of the first difference sequence is obtained as the grayscale change value of the second window; Obtaining the grayscale change value corresponding to the reference window in each traversal direction of any non-foreign object reference point, and obtaining the average of the grayscale change values as the grayscale change value of any non-foreign object reference point; Obtaining the addition result of the grayscale change value of any non-foreign object reference point and the grayscale value of the target seed point, recorded as the second addition result, and obtaining, in the eight neighborhoods of any non-foreign object reference point, a pixel point whose grayscale value is the same as the second addition result and is not a foreign object reference point as a new seed point; In the reference area, non-foreign object reference points whose overlapping coefficients are greater than a preset overlapping coefficient threshold value are formed into an overlapping area, the overlapping coefficients of the reference windows in each traversal direction of each non-foreign object reference point in the overlapping area are obtained, and the reference windows in each traversal direction of each non-foreign object reference point in the overlapping area are formed into a second reference window set. In the second reference window set, a reference window with any overlapping coefficient in any traversal direction is selected and recorded as a third window, and the grayscale value difference between adjacent pixel points in the third window is obtained to obtain a corresponding third grayscale value difference sequence, and the mean of the third grayscale value difference sequence is calculated and recorded as the difference mean of the third window. In the second reference window set, at least two reference windows with the same traversal direction and the same overlapping coefficient as the third window are selected and recorded as new target windows, and the difference mean of each new target window is obtained, and the average value of all difference means is obtained as the grayscale difference of any overlapping coefficient in any traversal direction. Obtain the grayscale difference of any overlapping coefficient in each traversal direction, and obtain the corresponding mean of the grayscale difference as the growth threshold corresponding to any overlapping coefficient. In the overlapping area, obtain the growth thresholds corresponding to at least three different overlapping coefficients to form a data sequence. Fit the data sequence to obtain the fitting equation of the overlapping coefficient and the growth threshold, obtain the overlapping coefficient of each new seed point, and obtain the growth threshold corresponding to each new seed point according to the fitting equation, which is recorded as the new growth threshold.
10. A method for quickly identifying appearance defects of fish oil soft capsules according to claim 9, characterized in that: The step of performing regional growth on the new seed point corresponding to each new growth threshold to obtain a new foreign body reference point includes: For any new seed point, perform regional growth in the eight-neighborhood direction of any new seed point according to the new growth threshold corresponding to the any new seed point to obtain a new suspected foreign body reference point, and form a new suspected foreign body reference area with the any new seed point and the new suspected foreign body reference point; The area where the foreign body reference point is located is recorded as the initial foreign body area. In the initial foreign body area, for any foreign body reference point, the eight neighborhood directions of the any foreign body reference point are taken as neighborhood directions, the grayscale values of the pixels of the any foreign body reference point in each neighborhood direction are obtained, and the grayscale values of the pixels of the any foreign body reference point in each neighborhood direction are fitted respectively to obtain the fitting equation of the any foreign body reference point in each neighborhood direction, and the slope of each fitting equation is recorded as the grayscale change index of the any foreign body reference point in each neighborhood direction; the grayscale change index of each foreign body reference point in the initial foreign body area in each neighborhood direction is obtained, and the average of the grayscale change indexes of all foreign body reference points in each neighborhood direction is obtained as the overall grayscale change index of the initial foreign body area in each neighborhood direction; For any pixel point in the new suspected foreign body reference area, obtain the grayscale change index of any pixel point in each neighborhood direction. When the difference between the grayscale change index of any pixel point in each neighborhood direction and the overall grayscale change index of the initial foreign body area in the corresponding neighborhood direction is within the preset grayscale change interval, determine that the any pixel point is a suspected foreign body point, obtain all the suspected foreign body points in the new suspected foreign body reference area, form a suspected foreign body area with all the suspected foreign body points in the new suspected foreign body reference area, obtain the overall grayscale change index of the suspected foreign body area in each neighborhood direction, and when the difference between the overall grayscale change index of the suspected foreign body area in each neighborhood direction and the overall grayscale change index of the initial foreign body area in the corresponding neighborhood direction is within the preset grayscale change interval, determine that all the suspected foreign body points are new foreign body reference points.
Citation Information
Cited By
Foamed silicone rubber surface detection method based on image visual identification
CN120894286A