Image-difference-based plastic appearance defect detection method and system
By employing illumination normalization transformation, spatial registration, and multi-band texture weighted differential calculation, the problem of false alarms caused by illumination and posture deviations in the appearance inspection of plastic products was solved, achieving efficient and reliable defect detection.
Patent Information
- Application Number
- CN202611349719.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-09-02
- Publication Date
- 2026-11-24
AI Technical Summary
Existing image difference-based methods for detecting defects in plastic products struggle to effectively distinguish grayscale fluctuations caused by illumination and posture deviations from actual defect signals when the imaging environment is uncontrolled. This results in a large number of non-defect interferences being marked as suspected targets, requiring manual verification and reducing detection efficiency and reliability.
After applying illumination normalization transformation and spatial registration, a difference response map is generated by combining multi-band texture weighted difference operation. The morphological discrimination coefficient is generated by fusing edge direction distribution and grayscale jump amplitude distribution, which adaptively suppresses non-defect differences. Further discrimination is then performed based on the morphological discrimination coefficient.
It effectively eliminates false alarms caused by illumination and posture deviations, improves the purity and reliability of the difference response map, eliminates the need for manual verification, and improves the accuracy and efficiency of detection.
Smart Images

Figure CN123160495A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of machine vision technology, and in particular to a method and system for detecting defects in the appearance of plastic products based on image difference. Background Technology
[0002] Image-based defect detection methods generally follow this technical approach: acquiring a surface image of the object to be inspected; registering the acquired image with a pre-stored standard reference image of the corresponding model; performing pixel-by-pixel gray-level difference calculations; and identifying suspected defect areas based on the amplitude of the difference response. The effective operation of this type of method relies on a core premise: ideally, the image to be inspected and the reference image should only differ in gray-level in the defect area, while the remaining areas should have highly consistent gray-level responses. To achieve this premise, existing solutions typically require strictly controlled imaging environments and the use of high-precision spatial transformation models in the registration stage, making the entire detection system highly dependent on hardware conditions and preprocessing accuracy.
[0003] However, in the actual scenario of plastic product appearance inspection, the contradictions caused by the above-mentioned dependence are particularly prominent. The base texture that is common on the surface of plastic products is easily affected by factors such as illumination angle and injection molding process fluctuations during imaging, resulting in normal grayscale fluctuations. These fluctuations are superimposed on the real defect signals in differential calculations, and a single image threshold is insufficient to effectively distinguish between the two. At the same time, under continuous production line conditions, it is difficult to maintain absolutely consistent illumination and posture between the plastic products to be inspected and the standard template. Even after registration correction, residual non-rigid deformation and illumination deviations will still produce significant differential responses along the texture edges. All of these factors together cause a large number of non-defect interferences in the differential results to be marked as suspected targets, requiring a large amount of manual review and secondary screening, which restricts the overall efficiency and reliability of the inspection process. Summary of the Invention
[0004] This invention provides a method and system for detecting appearance defects in plastic products based on image difference, in order to solve the problems mentioned in the background art.
[0005] To achieve the above objectives, the present invention provides a method for detecting appearance defects in plastic products based on image difference, comprising:
[0006] Pt.1. Acquire the original image of the surface of the plastic product to be inspected, and perform illumination normalization transformation on the original image to generate an illumination correction image under standard illumination.
[0007] Pt.2. Spatial registration is performed between the illumination correction image and the preset standard reference image of the corresponding model to generate a spatially aligned floating image and reference image;
[0008] Pt.3. Perform multi-band texture weighted difference operation on the reference image and the floating image to generate a difference response image. The multi-band texture weighted difference operation is used to separate and differentially suppress non-defect differences between the floating image and the reference image from the frequency domain dimension.
[0009] Pt.4. Perform connected component search on the difference response map to extract suspected defect markers, and collect edge direction distribution and gray level jump amplitude distribution in the image area corresponding to the suspected defect markers;
[0010] Pt.5. Based on the edge direction distribution and the grayscale jump amplitude distribution, the morphological discrimination coefficient of the suspected defect mark is generated by fusion. The morphological discrimination coefficient is compared with the preset discrimination benchmark value. Based on the comparison result, it is determined whether the suspected defect mark belongs to the real defect mark.
[0011] To address the aforementioned problems, the present invention also provides a plastic product appearance defect detection system based on image difference, the system comprising:
[0012] The illumination normalization module is used to acquire the original image of the surface of the plastic product to be inspected, and to perform illumination normalization transformation on the original image to generate an illumination correction map under standard illumination.
[0013] The image registration module is used to spatially register the illumination correction image with a preset standard reference image of the corresponding model to generate a spatially aligned floating image and a reference image.
[0014] The frequency band difference module is used to perform multi-frequency band texture weighted difference operation on the reference image and the floating image to generate a difference response image. The multi-frequency band texture weighted difference operation is used to separate and differentially suppress non-defect differences between the floating image and the reference image from the frequency domain dimension.
[0015] The feature extraction module is used to perform connected component search on the difference response map to extract suspected defect markers, and to collect edge direction distribution and gray-level jump amplitude distribution in the image region corresponding to the suspected defect markers;
[0016] The defect discrimination module is used to generate a morphological discrimination coefficient of the suspected defect mark by fusing the edge direction distribution and the gray level jump amplitude distribution, compare the morphological discrimination coefficient with a preset discrimination benchmark value, and determine whether the suspected defect mark belongs to a real defect mark based on the comparison result.
[0017] Compared with the prior art, the present invention has the following beneficial effects:
[0018] 1. This invention performs multi-band texture weighted differential operations on a reference image and a floating image, decomposing image differences from a frequency domain perspective into low-frequency components representing overall brightness and batch color shift, mid-frequency components representing surface substrate texture, and high-frequency components representing abrupt changes in edge details. A regional differential tolerance weight is applied to the mid-frequency components based on local texture entropy values, adaptively suppressing normal grayscale fluctuations in texture-dense regions during the differential stage rather than superimposing them with defect signals. Furthermore, a morphological discrimination coefficient is generated by fusing edge direction distribution and grayscale jump amplitude distribution, performing secondary screening of suspected targets from a morphological perspective. Thus, this invention collaboratively eliminates the false alarm root cause of the difficulty in distinguishing texture grayscale fluctuations from defect signals, as described in the prior art, at both the differential stage and the judgment stage, eliminating the need for external manual verification for secondary screening.
[0019] 2. This invention employs grayscale mapping correction in low-frequency processing to offset overall brightness and batch color shift. In mid-frequency processing, it determines differential tolerance weights based on local texture entropy values, assigning larger tolerance weights to texture-dense regions. In high-frequency processing, it uses gradient thresholding to retain true abrupt changes. The differentially processed three-band components are then reconstructed pixel-by-pixel to generate a differential response map. This scheme ensures coordination between correction and screening strategies across different frequency bands, resulting in adaptive suppression of various non-defect differences in the final reconstructed differential response map, thus improving the purity and reliability of the differential response map as a basis for subsequent judgment. Attached Figure Description
[0020] Figure 1 This is a flowchart illustrating a method for detecting plastic product appearance defects based on image difference, according to an embodiment of the present invention.
[0021] Figure 2 This is a functional block diagram of a plastic product appearance defect detection system based on image difference provided in an embodiment of the present invention.
[0022] The realization of the objective, functional features and advantages of the present invention will be further explained in conjunction with the embodiments and with reference to the accompanying drawings. Detailed Implementation
[0023] It should be understood that the specific embodiments described herein are merely illustrative of the invention and are not intended to limit the invention.
[0024] Reference Figure 1 The diagram shown is a flowchart illustrating a method for detecting plastic product appearance defects based on image difference according to an embodiment of the present invention. In this embodiment, the method for detecting plastic product appearance defects based on image difference includes:
[0025] Pt.1. Acquire the original image of the surface of the plastic product to be inspected, and perform illumination normalization transformation on the original image to generate an illumination correction image under standard illumination.
[0026] In this embodiment of the invention, during the detection of surface defects in plastic products, the original image acquired in the image acquisition stage is inevitably affected by fluctuations in the imaging environment's lighting conditions. These fluctuations include illuminance attenuation due to light source aging, color temperature shifts introduced by changes in ambient light, and uneven local lighting caused by the curvature of the plastic product surface. These lighting factors manifest as overall shifts or local fluctuations in pixel grayscale values in the original image. If this original image is directly used for subsequent differential operations, the lighting differences will be superimposed on the actual defect signal, making it impossible for subsequent steps to distinguish whether the grayscale deviation originates from lighting changes or surface defects. Therefore, this step first acquires the original image of the surface of the plastic product to be inspected, and then performs an illumination normalization transformation on the original image to eliminate lighting condition differences, generating an illumination correction map under standard lighting conditions.
[0027] The process involves acquiring raw images of the surface of the plastic product to be inspected, and then using an image acquisition device to perform an imaging operation on the plastic product being transported on the production line. In one feasible implementation, the image acquisition device employs an industrial area scan camera combined with an LED light source array. The camera resolution is 5 megapixels to 20 megapixels, and the light source color temperature range is 5000K to 6500K. In another feasible implementation, the image acquisition device can also use a linear scan camera combined with a bar light source, suitable for continuous scanning imaging of cylindrical or elongated plastic products. Optionally, the image acquisition device can also use a 3D camera combined with a structured light projector to simultaneously acquire grayscale images and depth information of the plastic product surface. The raw image is a digital grayscale image, where each pixel position corresponds to the illumination response intensity of a spatial sampling point on the plastic product surface. This illumination response intensity is quantized and stored in the form of grayscale values, with a grayscale bit depth of 8 bits to 12 bits, i.e., the grayscale value range is 0 to 255 or 0 to 4095.
[0028] The purpose of performing illumination normalization transformation on the original image to generate an illumination correction map under standard illumination is to compensate for the differences in grayscale values in the original image caused by different illumination conditions, so that the output image is consistent with the grayscale response of the image under standard illumination conditions. Specifically, the illumination normalization transformation is implemented in the following way: First, the illumination response intensity of the pixel positions in the original image is collected, and the illumination response sequence of the original image is extracted based on the illumination response intensity of the pixel positions. This illumination response sequence is the set of grayscale values of all pixel positions or sampled pixel positions in the original image, reflecting the actual illumination distribution state of the original image at the time of acquisition. Next, the illumination response sequence is compared with the standard illumination template sequence at the pixel positions to determine the illumination correction coefficients at the pixel positions. The standard illumination template sequence is a grayscale value distribution template obtained in advance by imaging a standard reflector under standard illumination conditions, and it is stored in the storage unit of the detection system. The illumination correction coefficients are determined as follows: for pixel position coordinates of... The correction coefficient for each pixel is calculated using the following formula:
[0029] ;
[0030] in, Represents the row index of a pixel. Column index representing pixels, and All are non-negative integers. The value range is from 1 to M. The value range is from 1 to N, where M and N are the total number of row pixels and column pixels of the original image, respectively. Indicates pixel position Illumination correction factor, Represents the pixel position in the standard lighting template sequence grayscale value, Represents the pixel position in the illumination response sequence of the original image. The grayscale value. Standard lighting template sequence. The grayscale range in the image corresponds to the bit depth of the original image's grayscale values. For an 8-bit image, The value range is from 0 to 255. When and The greater the deviation of the ratio from 1, the more severe the impact of illumination deviation on the pixel location, and the greater the correction required.
[0031] Then, based on the illumination correction coefficients at the pixel locations, the grayscale values at the pixel locations in the original image are mapped and transformed to generate an illumination correction map under standard illumination. This mapping transformation applies to pixel locations ( Execute using the following formula:
[0032] ;
[0033] in, Represents the pixel position in the original image grayscale value, Indicates the pixel position in the illumination correction image The grayscale value. When When the value is greater than 1, the grayscale value at that pixel location is stretched upwards to compensate for insufficient illumination; when... When the value is less than 1, the grayscale value at that pixel location is compressed downwards to suppress excessive illumination; when... When the value is 1, the grayscale value at that pixel location remains unchanged.
[0034] In one feasible implementation, to avoid grayscale overflow or distortion caused by an excessively large or small correction coefficient, the illumination correction coefficient is adjusted. Amplitude limiting is applied to confine its value range to a preset correction coefficient range. Optionally, the lower limit of the correction coefficient is 0.3, and the upper limit is 3.0, meaning that when the calculated... When it is less than 0.3, take 0.3. When the value is greater than 3.0, use 3.0. In another feasible implementation, the correction coefficient range can be set from 0.5 to 2.0 based on the actual light fluctuation amplitude, suitable for production line scenarios with relatively stable lighting environments. In yet another feasible implementation, the correction coefficient range can be set from 0.1 to 5.0, suitable for scenarios with larger light fluctuation amplitudes.
[0035] In another feasible implementation, the illumination normalization transformation can also be implemented without relying on a standard illumination template sequence, instead employing a normalization method based on the statistical characteristics of the image itself. For example, the grayscale values of the original image can be standardized and mapped according to its overall mean and variance, so that the output image has a preset target mean and target variance. In yet another feasible implementation, a fitting method based on the illumination plane can be used. First, the illumination distribution surface of the original image is estimated, and then the inverse transformation of the illumination distribution surface is applied to the original image to achieve illumination uniformity. Regardless of which method is used, the core is to eliminate the grayscale deviation introduced by differences in illumination conditions in the original image, so that the illumination correction image can accurately reflect the intrinsic grayscale response of the plastic surface rather than the superposition result of illumination changes.
[0036] Through the above illumination normalization transformation, the illumination deviation in the original image is effectively suppressed under the action of the correction coefficient. The gray value of each pixel in the output illumination correction image corresponds to the intrinsic gray value response of the plastic surface under standard illumination conditions. This provides an input image with a consistent gray value benchmark for subsequent differential operations with the standard reference image, avoiding misjudgment of illumination differences as surface defects in the differential process.
[0037] In one feasible implementation, the frequency of illumination normalization transformation is adaptively set according to the production line conditions. Optionally, illumination normalization transformation is performed on each frame of the original image, which is suitable for dynamic scenarios where illumination conditions change in real time. In another feasible implementation, illumination normalization transformation is performed only on the first frame of the same batch of plastic products, and the correction coefficient is recorded. The remaining images in the same batch reuse the correction coefficient to improve processing efficiency and reduce computational resource consumption.
[0038] Pt.2. Spatial registration is performed between the illumination correction image and the preset standard reference image of the corresponding model to generate a spatially aligned floating image and reference image;
[0039] In this embodiment of the invention, after illumination normalization, spatial position deviations may still exist between the illumination correction image and the standard reference image. These deviations originate from changes in the posture of the plastic product during production line transport, camera installation errors, and differences in the external dimensions of different plastic product models. If the illumination correction image and the standard reference image fail to achieve pixel-level spatial alignment, pixels corresponding to the same surface position will not be correctly matched in subsequent difference calculations, causing non-defect positional offsets to be misjudged as grayscale differences, severely interfering with the accuracy of defect detection. Therefore, this step spatially registers the illumination correction image with a preset standard reference image of the corresponding model. By solving for the optimal spatial transformation parameters, the illumination correction image is precisely aligned spatially with the standard reference image, generating a spatially aligned floating image and reference image.
[0040] The preset standard reference image is a defect-free standard image pre-stored in the system for the current model of the plastic product to be inspected. Its imaging conditions are consistent with the standard lighting environment, and its spatial pose is defined as the reference pose. The standard reference image and the illumination correction image have the same pixel resolution and grayscale bit depth. The goal of spatial registration is to determine a spatial transformation model that maps each pixel position in the illumination correction image to the corresponding position in the standard reference image, so that the same physical point on the surface of the plastic product overlaps in the two images.
[0041] In one feasible implementation, edge contour extraction is first performed on the illumination correction image to obtain the edge contour point distribution. Edge contour extraction employs an edge detection operator based on gradient magnitude. In one feasible implementation, the Canny edge detection operator is used, with a low threshold set to 30-50, a high threshold set to 80-120, and a Gaussian filter standard deviation set to 1.0-1.5. In another feasible implementation, the Sobel operator combined with non-maximum suppression can also be used to extract edges, with a gradient magnitude threshold set to 20-60. The extracted edge contour point distribution includes the pixel coordinates of each edge point and the corresponding gradient direction angle. Simultaneously, the same edge contour extraction operation is performed on a standard reference image to obtain the edge contour point distribution of the standard reference image.
[0042] Then, the spatial positions of the edge contour point distribution of the illumination correction image and the edge contour point distribution of the standard reference image are compared to determine the spatial transformation parameters between the illumination correction image and the standard reference image. These spatial transformation parameters describe the deviation of the illumination correction image from the standard reference image in terms of translation, rotation, and scaling. Spatial position comparison is achieved through an iterative nearest-point algorithm or a shape context-based matching algorithm. In a preferred implementation, an iterative nearest-point algorithm is used, the steps of which include: using the edge contour points of the illumination correction image as the source point set and the edge contour points of the standard reference image as the target point set, iteratively updating the transformation parameters by minimizing the sum of squared Euclidean distances between the source and target point sets. The number of iterations is set to 50 to 200, and the convergence threshold is set to a minimum average distance change of less than 0.01 pixels in the source point set. In another feasible implementation, a feature point matching method can also be used. First, local feature points of the two images are extracted using accelerated robust feature or scale-invariant feature transformation operators, and then matching point pairs are selected using a random sampling consensus algorithm, and the homography matrix is calculated as the spatial transformation parameters. Another feasible implementation is to use a registration method based on maximizing mutual information, which solves the transformation parameters by maximizing the mutual information value of the overlapping area of the two images, without relying on edge or feature point extraction.
[0043] The spatial transformation parameters are selected based on the actual deviation type, using a transformation model. In one embodiment, the spatial transformation model employs a rigid body transformation, including three parameters: translation along the image row direction, translation along the image column direction, and rotation angle around the image center. In another embodiment, the spatial transformation model employs an affine transformation, including six parameters: row translation, column translation, rotation angle, uniform scaling factor in each direction, and shearing factors in both directions. In yet another feasible implementation, for plastic products with significant non-rigid deformation, a thin-plate spline interpolation model is used, which includes a set of control point displacement vectors capable of fitting nonlinear spatial deformation. The spatial transformation parameters are optimized using the aforementioned registration algorithm to minimize the grayscale difference or edge distance error between the registered illumination correction image and the standard reference image.
[0044] Based on the obtained spatial transformation parameters, the illumination correction image is mapped to coordinate space to generate a floating image aligned with the spatial position of the standard reference image, which is then used as the reference image. Coordinate space mapping is achieved through image resampling: for each integer pixel coordinate in the floating image, its corresponding sub-pixel coordinate in the illumination correction image is calculated using the inverse transformation of the spatial transformation parameters, and then the grayscale value at that coordinate is obtained through interpolation. In one embodiment, bilinear interpolation is used; in another, bicubic interpolation is used; and in yet another feasible implementation, nearest neighbor interpolation is used to maintain edge sharpness. The floating image output after resampling has the same pixel coordinate system as the reference image; that is, any pixel position coordinate in the floating image corresponds to the spatial position at the same coordinate in the reference image. Furthermore, to eliminate potential boundary effects introduced during coordinate mapping, the edge regions of the floating image are cropped, retaining the effective overlapping area of the two images as the range for subsequent difference operations.
[0045] Based on any of the above implementation methods, the accuracy of spatial registration is quantitatively evaluated using registration error. Registration error is defined as the root mean square error of grayscale values between the floating image and the reference image within the overlapping area. Registration is considered successful when this error is less than a preset accuracy threshold. Optionally, the accuracy threshold is set to a root mean square error of grayscale values less than 3 gray levels. In another feasible implementation, the accuracy threshold is set to an average distance between registered edge contour points less than 0.5 pixels. If the registration error exceeds the threshold, registration is re-executed or an alarm is issued prompting manual intervention.
[0046] Through the aforementioned spatial registration, the spatial position of the plastic surface in the illumination correction image is accurately mapped to the coordinate system of the reference image, achieving pixel-level alignment between the floating image and the reference image in space. This ensures that the grayscale differences at corresponding pixel positions in subsequent difference operations only reflect the intrinsic changes of the plastic surface, without including spurious differences introduced by spatial misalignment, providing a spatially consistent image pair for accurately extracting the true defect signal.
[0047] Pt.3. Perform multi-band texture weighted difference operation on the reference image and the floating image to generate a difference response image. The multi-band texture weighted difference operation is used to separate and differentially suppress non-defect differences between the floating image and the reference image from the frequency domain dimension.
[0048] In this embodiment of the invention, after spatial registration is completed, the reference image and the floating image achieve pixel-level alignment in space, but various types of inconsistencies still exist between them. Only some of these inconsistencies are due to genuine defects, while the rest originate from non-defect factors. Specifically, the differences between the reference image and the floating image can be categorized into three types. The first type is overall brightness deviation and batch-specific color deviation. This type of deviation manifests as low-frequency components in the image, covering a large pixel area with gradual grayscale changes. The second type is surface substrate texture deviation. This type of deviation originates from the subtle fluctuations in the inherent texture structure of the plastic surface between different individuals, manifesting as mid-frequency components in the image with periodic or quasi-periodic characteristics. The third type is edge and detail abrupt change deviation, which includes both grayscale abrupt changes caused by genuine defects and spurious abrupt changes caused by noise interference, manifesting as high-frequency components in the image. If the above three types of differences are uniformly subjected to differential operations without distinction, the non-defect brightness and texture deviations will be superimposed on the defect signal, resulting in a large number of responses unrelated to defects filling the difference response image, severely reducing the signal-to-noise ratio of the detection. Therefore, this step performs multi-band texture weighted differential operation on the reference map and the floating map, separates the above three types of differences into different frequency bands through frequency domain decomposition, applies differentiated suppression strategies to each frequency band, and finally reassembles the processed components to generate a difference response map.
[0049] The multi-band texture weighted difference operation first performs wavelet transform decomposition on the reference image and the floating image simultaneously. Wavelet transform, as a joint time-frequency domain analysis method, can simultaneously preserve the spatial and frequency information of the image, dividing the image into different frequency bands through multi-level decomposition. In each level of wavelet transform decomposition, the image is decomposed into four sub-bands: a horizontal low-frequency and vertical low-frequency approximate sub-band, a horizontal low-frequency and vertical high-frequency horizontal detail sub-band, a horizontal high-frequency and vertical low-frequency vertical detail sub-band, and a horizontal high-frequency and vertical high-frequency diagonal detail sub-band. In a preferred implementation, discrete wavelet transform is used, with the wavelet basis function selected as either the Db4 or Db8 wavelet from the Daubechies wavelet family, and the decomposition level set to three. In another feasible implementation, the Sym4 wavelet from the Symlets wavelet family can also be used, which has better approximate symmetry while maintaining tight support. In another feasible implementation, for plastic surfaces with rich textures or high noise levels, the Bior4.4 wavelet from the Biorthogonal wavelet family can be selected, as its linear phase characteristics help reduce phase distortion during reconstruction. After three levels of wavelet decomposition, the reference map is decomposed into one reference low-frequency coefficient map, three reference mid-frequency coefficient maps, and three reference high-frequency coefficient maps. Each mid-frequency and high-frequency coefficient map corresponds to the horizontal, vertical, and diagonal directions, respectively. The high-frequency coefficient map generated by the first-level decomposition corresponds to the highest frequency band, and the approximate coefficient map generated by the third-level decomposition corresponds to the lowest frequency band. To facilitate the expression of subsequent weighted difference operations, the mid-frequency and high-frequency coefficient maps from each level of decomposition are categorized and merged according to frequency from high to low, forming a holistic reference mid-frequency coefficient map, a reference high-frequency coefficient map, and a reference low-frequency coefficient map. Simultaneously, the floating map is subjected to the same wavelet transform decomposition, resulting in a floating low-frequency coefficient map, a floating mid-frequency coefficient map, and a floating high-frequency coefficient map. The decomposition level of the wavelet transform is determined based on the texture characteristics of the plastic surface and the expected defect size. In one embodiment, for small plastic parts with fine textures, the decomposition level is set to four levels to more fully distinguish texture fluctuations from defect signals. In another embodiment, for large plastic parts with smooth surfaces, the decomposition level is set to two levels to reduce computational overhead.
[0050] After completing the frequency band decomposition, difference components are extracted from the coefficient maps of each frequency band. Low-frequency difference components are extracted from the reference low-frequency coefficient map and the floating low-frequency coefficient map. These low-frequency difference components characterize the overall brightness deviation and batch-specific color deviation between the floating map and the reference map. The extraction method involves performing pixel-by-pixel interpolation on the corresponding coefficients of the two low-frequency coefficient maps. The amplitude of this low-frequency difference component typically exhibits an overall offset of positive or negative values, and its spatial distribution shows a large-scale continuous characteristic, fundamentally different from the local abrupt changes characteristic of defects. Mid-frequency difference components are extracted from the reference mid-frequency coefficient map and the floating mid-frequency coefficient map. These mid-frequency difference components characterize the surface substrate texture deviation between the floating map and the reference map. Texture deviation manifests as periodic gray-level fluctuations within a small range, occupying the mid-frequency band in the frequency domain. The extraction method for the mid-frequency difference component also employs pixel-by-pixel interpolation. The magnitude of this component is positively correlated with the density of the plastic surface texture and the degree of individual variation. High-frequency difference components are extracted from the reference high-frequency coefficient map and the floating high-frequency coefficient map. These high-frequency difference components characterize the edge and detail abrupt change deviation between the floating map and the reference map. The high-frequency difference components include both gray-level jumps at defect boundaries and spurious abrupt changes introduced by noise and registration residual errors. The extraction method involves performing pixel-by-pixel interpolation on the corresponding coefficients of the two high-frequency coefficient images.
[0051] After the low-frequency, mid-frequency, and high-frequency difference components are extracted, they enter the difference suppression stage, where different processing strategies are applied to the difference components of different frequency bands.
[0052] For low-frequency difference components, grayscale mapping correction is performed to cancel out the overall brightness deviation and batch color deviation in the low-frequency difference components, generating a low-frequency corrected difference map. The core idea of grayscale mapping correction is that low-frequency differences reflect a systematic shift in the overall grayscale response of two images, rather than a local anomaly, and should be eliminated as a whole. This correction is achieved by establishing a grayscale mapping function from the floating low-frequency coefficient map to the reference low-frequency coefficient map. In one feasible implementation, the grayscale mapping function uses a linear mapping, and the optimal multiplicative and additive correction coefficients are fitted using the least squares method to minimize the mean square error between the mapped floating low-frequency coefficient map and the reference low-frequency coefficient map. The typical value range of the multiplicative correction coefficient is 0.85 to 1.15, used to compensate for the contrast difference between the two images. The typical value range of the additive correction coefficient is -10 to +10 gray levels, used to compensate for the brightness shift between the two images. Then, the low-frequency difference components are replaced with the mapping residuals to obtain the low-frequency corrected difference map. In another feasible implementation, the grayscale mapping function can also employ nonlinear mapping, such as multi-segment linear mapping based on histogram matching or nonlinear transformation based on the cumulative distribution function, to adapt to scenarios with nonlinear illumination response or asymmetric grayscale distribution. After grayscale mapping correction, the overall offset in the low-frequency difference components is eliminated, retaining only the residual differences that cannot be compensated by linear or nonlinear mapping.
[0053] For the mid-frequency difference component, a regional differential tolerance weight is applied. This regional differential tolerance weight is determined based on the local texture entropy value of each pixel position in the reference mid-frequency coefficient map. The differential tolerance weight for densely textured regions is greater than that for sparsely textured regions, generating a mid-frequency weighted difference map. The local texture entropy value is used to quantify the texture complexity of the local region where the pixel position is located. The more complex the texture, the more frequent the grayscale fluctuations in the region, and the more likely the corresponding mid-frequency difference component is to originate from normal texture fluctuations rather than defects. Therefore, a larger tolerance weight needs to be assigned to allow the difference to exist without being judged as a defect. The local texture entropy value is calculated as follows: For each coefficient position in the reference mid-frequency coefficient map, a local window of size W×W is set with that position as the center. In one embodiment, the window size W is set to 5×5 pixels, in another feasible implementation it is set to 7×7 pixels, and in yet another feasible implementation it is set to 3×3 pixels. Within this window, the probability distribution of each coefficient value is statistically analyzed, and then the local texture entropy value is calculated according to the definition of Shannon entropy. When the coefficient values within the local window are evenly distributed, the local texture entropy value reaches its maximum value, indicating that the texture of that region is the most complex. When all coefficient values within a local window are identical, the local texture entropy reaches its minimum value of zero, indicating that the texture in that region is the flattest. For coefficient values with an 8-bit depth, the theoretical range of the local texture entropy is 0 to 8.
[0054] After obtaining the local texture entropy value, the differential tolerance weight at that location is determined. There is a positive correlation between the differential tolerance weight and the local texture entropy value. In one feasible implementation, a linear mapping is used, where the tolerance weight equals 1 plus the product of a weight adjustment coefficient and the local texture entropy value. The typical range of the weight adjustment coefficient is 0.05 to 0.20. When the texture entropy is zero (i.e., a textureless region), the tolerance weight equals 1, and the difference is fully preserved without any tolerance amplification. When the texture entropy reaches its maximum value (i.e., the densest texture region), a weight adjustment coefficient of 0.1 and a tolerance weight of 1.8 are used. This means that the mid-frequency difference at that location is amplified by a factor of 1.8 before subsequent processing, effectively increasing the upper limit of the allowed mid-frequency difference in that region. In another feasible implementation, a non-linear mapping relationship can also be used, where the tolerance weight equals 1 plus the product of a weight adjustment coefficient and an exponent of the local texture entropy value. The typical range of the exponent adjustment coefficient is 1.5 to 3.0, causing the tolerance weight to increase slowly in regions with low texture entropy and to increase sharply in regions with high texture entropy. In another feasible implementation, the differential tolerance weight can also be determined based on local variance, that is, the variance of the coefficients within the local window is used instead of the texture entropy as a measure of texture complexity, and the larger the variance, the larger the tolerance weight.
[0055] After determining the differential tolerance weights for each location, these weights are applied to the intermediate frequency (IF) difference components. The application method involves multiplying each difference value in the IF difference component by its corresponding tolerance weight to generate an IF-weighted difference map. When the tolerance weight in a texture-dense region is greater than 1, the original IF difference at that location is amplified, effectively increasing the IF difference tolerance threshold for that region, thereby reducing the probability of texture fluctuations being misjudged as defects. This weighted difference retains the sign information of the original difference: a positive difference indicates that the floating map coefficient is greater than the reference map coefficient, and a negative difference indicates that the floating map coefficient is less than the reference map coefficient. This sign information can be used in subsequent steps to distinguish the directionality of the difference.
[0056] For high-frequency difference components, gradient abrupt changes are filtered, retaining those with gradient magnitudes exceeding a preset threshold and filtering out those below the threshold, generating a high-frequency filtered difference map. True defect abrupt changes in high-frequency difference components typically have large gradient magnitudes, while spurious abrupt changes introduced by noise and registration errors have relatively small gradient magnitudes. Gradient magnitude calculation is performed in the spatial domain. For each pixel position in the high-frequency difference component map, its gradient components along the row and column directions are calculated, and then the gradient magnitude is synthesized. Along the row direction, the difference operator is used to calculate the grayscale change rate between the pixel and its neighboring pixels in the row direction. Along the column direction, the difference operator is used to calculate the grayscale change rate between the pixel and its neighboring pixels in the column direction. In one embodiment, the Sobel operator is used to calculate the gradient components in the row and column directions, with a convolution kernel size of 3×3. In another embodiment, the Scharr operator is used, which provides a more accurate response to gradient directions. In yet another feasible implementation, the Laplacian operator is used to calculate the second-order gradient magnitude to enhance the response to isolated abrupt change points.
[0057] A preset gradient threshold is used to distinguish between real and spurious abrupt changes. The value of the gradient threshold is determined based on the texture characteristics of the plastic surface and the image noise level. In one embodiment, the gradient threshold is set to 15 to 25. When the gradient amplitude is greater than the threshold, the high-frequency difference component at that location is retained. When the gradient amplitude is less than or equal to the threshold, the high-frequency difference component at that location is filtered out, i.e., the difference at that location is set to zero. In another feasible implementation, the gradient threshold can also be an adaptive threshold, i.e., determined based on the global gradient distribution statistics of the high-frequency difference component map, for example, setting the threshold to the mean of the global gradient amplitude plus twice the standard deviation. In yet another feasible implementation, a direction-based selective retention strategy can also be used, i.e., only high-frequency differences exceeding the threshold are retained in specific gradient directions, while higher thresholds or direct filtering are used in other directions. After gradient abrupt change screening, only real abrupt change components with larger amplitudes are retained in the high-frequency filtered difference map, while weak-amplitude noise and registration residual errors are suppressed.
[0058] After completing the differentiation processing of the three frequency bands mentioned above, the low-frequency correction difference map, the mid-frequency weighted difference map, and the high-frequency screening difference map are reconstructed pixel-by-pixel according to their spatial locations to generate a difference response map. The pixel-by-pixel difference reconstruction operation is as follows: for each pixel location, according to the inverse wavelet transform rules, the low-frequency correction difference map is used as the low-frequency sub-band, the mid-frequency weighted difference map as the mid-frequency sub-band, and the high-frequency screening difference map as the high-frequency sub-band, and inverse wavelet transform reconstruction is performed. The inverse wavelet transform is the inverse operation of the forward wavelet transform, using the same wavelet basis functions and decomposition series as the forward transform to synthesize the difference components of the three frequency bands into a grayscale difference response map with physical meaning in the spatial domain. The response value of each pixel location in the difference response map reflects the overall degree of difference at that location after frequency band differentiation suppression. The range of the response value is consistent with the grayscale bit depth of the original image; for an 8-bit image, the range is 0 to 255. Locations with higher response values are more likely to correspond to real defects.
[0059] In another feasible implementation, instead of performing the inverse wavelet transform, the difference components of the three frequency bands can be directly weighted and summed at the same pixel location to generate a difference response map. The first weight coefficient corresponds to the low-frequency difference component, the second weight coefficient corresponds to the mid-frequency difference component, and the third weight coefficient corresponds to the high-frequency difference component. The sum of the three weight coefficients equals 1. In one embodiment, the three weight coefficients are set to 0.3, 0.4, and 0.3, respectively, meaning that the contributions of the three frequency bands are balanced. In another embodiment, for scenarios where defects mainly appear as abrupt changes in grayscale, the high-frequency weight coefficient is set to 0.6, the mid-frequency weight coefficient to 0.3, and the low-frequency weight coefficient to 0.1 to highlight the role of high-frequency differences. In yet another embodiment, for scenarios where defects mainly appear as texture distortion, the mid-frequency weight coefficient is set to 0.7, the high-frequency weight coefficient to 0.2, and the low-frequency weight coefficient to 0.1 to highlight the role of mid-frequency differences. The selection of weight coefficients can be adapted and adjusted according to the type of surface defects and texture characteristics of the plastic product.
[0060] Through the multi-band texture weighted differential operation described above, non-defect differences between the reference image and the floating image are differentially suppressed within their respective frequency bands. Low-frequency overall brightness and batch color shift are offset by grayscale mapping correction. Mid-frequency texture fluctuations are adaptively allowed through a texture entropy-driven tolerance weight. High-frequency noise and residual registration errors are filtered out through gradient mutation screening. All types of non-defect differences are adaptively suppressed after separation rather than simply superimposed. The difference response map retains only differences that are difficult to eliminate through the aforementioned frequency band processing; these differences are considered valid candidates for suspected defect markers in subsequent steps.
[0061] Pt.4. Perform connected component search on the difference response map to extract suspected defect markers, and collect edge direction distribution and gray level jump amplitude distribution in the image area corresponding to the suspected defect markers;
[0062] In this embodiment of the invention, after generating the difference response map, the map contains a large number of pixel locations with response values exceeding the background level. These locations may correspond to actual defect areas or to some non-defect interference remaining after the aforementioned frequency band processing. The response of actual defects in the difference response map typically appears as spatially continuous clusters of pixels, while the response of residual interference often appears as discrete, isolated pixels or small scattered points. Directly performing subsequent judgments on each high-response pixel location independently would generate a large amount of invalid computation and introduce false alarms. Therefore, this step first performs a connected component search on the difference response map to extract suspected defect markers, aggregating spatially adjacent pixel locations with consistent response characteristics into meaningful image regions. Then, edge direction distribution and grayscale jump amplitude distribution are collected within the image regions corresponding to each suspected defect marker, providing quantitative basis for subsequent morphological discrimination.
[0063] The process of performing connected component search on the difference response map to extract suspected defect markers is implemented in the following ways. First, a pixel neighborhood connectivity determination rule is established. This rule is used to determine whether adjacent pixel positions in the difference response map belong to the same connected component. One feasible implementation uses a four-neighbor connectivity rule, meaning that pixels are considered to belong to the same connected component only if their four adjacent positions above, below, to the left, and to the right simultaneously satisfy the connectivity condition. Another feasible implementation uses an eight-neighbor connectivity rule, which includes not only the four directions of the four-neighbor rule but also the four diagonal directions (upper left, upper right, lower left, and lower right). The eight-neighbor connectivity rule has stronger connectivity aggregation capabilities than the four-neighbor rule and is suitable for detecting defects with irregular shapes or oblique extensions. In yet another feasible implementation, the pixel neighborhood connectivity determination rule can also use a custom neighborhood template, which is set as an asymmetric set of connected directions based on the typical extension direction of the plastic surface defect.
[0064] The connectivity condition is determined by whether the response values of adjacent pixel positions meet a preset connectivity threshold. In one embodiment, the connectivity condition is set such that the response values of adjacent pixel positions all exceed the preset response threshold, and the difference between their response values is less than a preset difference tolerance value. The response threshold is used to distinguish between valid responses and background noise, and its value is determined based on the overall grayscale distribution of the difference response map. In one feasible implementation, the response threshold is set to two to three times the global grayscale mean of the difference response map. In another feasible implementation, the response threshold is set to a fixed value; for an 8-bit deep difference response map, this fixed value is set to 30 to 50. The specific value of the response threshold can be adjusted according to the expected minimum contrast of the plastic surface defects. The lower the expected defect contrast, the lower the response threshold should be to avoid missed detections; the higher the expected defect contrast, the higher the response threshold should be to reduce false alarms. The difference tolerance value is used to allow a certain degree of fluctuation in response values within the same connected region, and its typical range is 10 to 20 grayscale levels.
[0065] After setting the pixel neighborhood connectivity rules and connectivity conditions, the pixel positions of the difference response map are traversed, and the response values of each pixel position are compared with preset response thresholds one by one to filter out feature pixel positions with response values exceeding the thresholds. In one embodiment, the traversal method uses a raster scanning sequence, that is, scanning line by line from the top left corner of the image to the right. After each line is scanned, the scan moves to the left end of the next line and continues until the entire difference response map has been traversed. In another feasible implementation, the traversal method can also adopt a region growing strategy starting from the current maximum response value. That is, the unlabeled pixel position with the largest response value is first found as the seed point, and then the search is expanded outwards from it to improve search efficiency.
[0066] According to the pixel neighborhood connectivity determination rule, the selected feature pixel positions are aggregated, and feature pixel positions that mutually satisfy the neighborhood connectivity determination rule are grouped into the same pixel group, generating the distribution range and spatial location parameters of the pixel group. The distribution range of the pixel group is determined by the rectangular boundary defined by the minimum row coordinate, maximum row coordinate, minimum column coordinate, and maximum column coordinate of all feature pixel positions in the pixel group. The spatial location parameters of the pixel group include the geometric center coordinates of the pixel group, which are determined by averaging the row coordinates of all feature pixel positions within the pixel group to obtain the center row coordinates, and averaging the column coordinates of all feature pixel positions to obtain the center column coordinates. The distribution range of the pixel group can also be described by the total number of pixels occupied by the pixel group, i.e., the area parameter. The image region corresponding to the above pixel group is marked as a suspected defect marker. One pixel group corresponds to one suspected defect marker, and each suspected defect marker has independent spatial location parameters and distribution range parameters.
[0067] After extracting suspected defect markers, edge direction distribution and gray-level jump amplitude distribution are acquired within the image region corresponding to each suspected defect marker. Since the difference response map is generated by recombining multi-band difference components, its pixel values reflect the overall degree of difference rather than the gray-level information of the original image. Directly acquiring edge direction and gray-level jump amplitude on this map would lose spatial details in the original image. Therefore, based on the spatial location parameters of the suspected defect markers, the image region corresponding to each suspected defect marker is first located in the illumination correction map. The location method involves mapping the distribution range of the suspected defect markers to the same coordinate range in the illumination correction map, and then extracting a sub-image within that coordinate range in the illumination correction map as the analysis object for subsequent feature acquisition. The illumination correction map, instead of the original image or the difference response map, is used for feature acquisition because it has undergone illumination normalization processing, and its gray-level values can truly reflect the intrinsic gray-level distribution of the plastic surface, avoiding interference from illumination differences on edge direction and gray-level jump amplitude.
[0068] Within the located image region, the edge orientation angles of each pixel are obtained along the pixel position arrangement direction, and an edge direction sequence is generated based on these edge orientation angles. The edge orientation angles are obtained as follows: for each pixel position within the image region, its gradient components along the row direction and column direction are calculated. Then, the principal gradient orientation angle for that pixel position is determined based on the ratio of the two gradient components; this orientation angle is the edge orientation angle. In one embodiment, the gradient components are calculated using the Sobel operator with a 3×3 convolution kernel. In another feasible implementation, the Prewitt operator is used to calculate the gradient components. In yet another feasible implementation, the Scharr operator is used, which provides a more accurate response to orientation angles. The edge orientation angle ranges from -90 degrees to +90 degrees, or equivalently from 0 degrees to 180 degrees, where 0 degrees and 180 degrees represent the horizontal direction, and ±90 degrees represent the vertical direction. The edge orientation angles of all pixel positions within the image region are arranged in spatial order to form an edge direction sequence.
[0069] Simultaneously, within the same image region, the grayscale difference between adjacent pixel positions is acquired, and a grayscale jump amplitude sequence is generated based on the grayscale difference between adjacent pixel positions. The grayscale difference is acquired as follows: for each pixel position within the image region, the difference between its grayscale value and that of its adjacent pixel positions in the row and column directions is calculated, and the larger of the absolute values of the differences in the two directions is taken as the grayscale jump amplitude at that position. In one embodiment, the adjacent pixel positions are the right-hand adjacent pixel and the bottom adjacent pixel, and the grayscale jump amplitude is the larger of the absolute values of the row-direction difference and the absolute values of the column-direction difference. In another feasible implementation, the grayscale jump amplitude is taken as the square root of the sum of the squares of the row-direction difference and the column-direction difference, i.e., the gradient magnitude, to comprehensively reflect the grayscale changes in both directions. In yet another feasible implementation, the grayscale jump amplitude is calculated using the Laplacian operator to enhance the response to grayscale abrupt change points. The grayscale jump amplitudes of all pixel positions within the image region are arranged in spatial order of pixel positions to form a grayscale jump amplitude sequence.
[0070] After generating the edge direction sequence, the edge direction angles in the sequence are categorized according to their value ranges to generate the edge direction distribution for the image region. The direction angle value range is divided into several sub-intervals. In one embodiment, the direction angle range from -90 degrees to +90 degrees is divided into 36 sub-intervals, each with a width of 5 degrees. In another feasible implementation, the direction angle range from 0 degrees to 180 degrees is divided into 18 sub-intervals, each with a width of 10 degrees. In yet another feasible implementation, for detection scenarios where the defect directionality is relatively uniform, a non-equal interval division method can be used. This involves dividing the angle range where the main defect direction is likely to occur into narrower sub-intervals to improve resolution, and dividing other angle ranges into wider sub-intervals to reduce computation. The edge direction distribution records the frequency of edge direction angle occurrence within each direction angle value range.
[0071] After generating the grayscale jump amplitude sequence, the grayscale differences in the sequence are categorized according to their ranges to generate the grayscale jump amplitude distribution for that image region. The range of possible grayscale jump amplitude values is divided into several sub-intervals. For an 8-bit grayscale image, the theoretical maximum grayscale jump amplitude is 255. Dividing this range into 16 sub-intervals results in each sub-interval having a width of approximately 16 grayscale levels. In another feasible implementation, the grayscale jump amplitude range is divided into 32 sub-intervals, each with a width of approximately 8 grayscale levels. The number of sub-intervals is determined based on the actual detection accuracy requirements; more sub-intervals result in higher statistical accuracy but increased computational load, while fewer sub-intervals result in coarser statistics but reduced computational load. The grayscale jump amplitude distribution records the frequency of grayscale jump amplitude occurrences within each sub-interval.
[0072] Based on any of the above implementation methods, when the same suspected defect mark corresponds to multiple unconnected sub-regions, the distribution range of the suspected defect mark is taken as the smallest bounding rectangle of all sub-regions. The edge direction distribution and grayscale jump amplitude distribution are collected in a unified manner at all pixel positions within the smallest bounding rectangle, rather than being collected only in a single sub-region.
[0073] Through the connected component search and feature acquisition operations described above, the discrete high-response pixel locations in the difference response map are aggregated into suspected defect markers with clear spatial ranges, each marker corresponding to an independent candidate defect region. Simultaneously, the edge orientation distribution and grayscale jump amplitude distribution acquired in each candidate region provide quantitative feature basis for subsequent morphology discrimination based on the original illumination correction map. This allows the final defect determination to integrate information from both spatial morphology and grayscale abrupt changes, improving the accuracy and reliability of the discrimination.
[0074] Pt.5. Based on the edge direction distribution and the grayscale jump amplitude distribution, the morphological discrimination coefficient of the suspected defect mark is generated by fusion. The morphological discrimination coefficient is compared with the preset discrimination benchmark value. Based on the comparison result, it is determined whether the suspected defect mark belongs to the real defect mark.
[0075] In this embodiment of the invention, after collecting the edge distribution and gray-level jump amplitude distribution within the image area corresponding to each suspected defect mark, the obtained distribution information is in the form of frequency statistics, which cannot be directly used to determine the authenticity of the suspected defect marks. Real defects and non-defect interference have fundamental differences in morphology. Real defects are usually caused by damage to the surface of the plastic product or molding defects; their boundary directions tend to be consistent, and the gray-level jump amplitude is relatively concentrated and significant. Non-defect interference mainly originates from residual texture fluctuations or registration residual errors; its boundary directions are randomly distributed, and the gray-level jump amplitude is dispersed and relatively low. If only a single distribution feature is relied upon for judgment, texture noise is easily misjudged as a defect or real defects with weak contrast are missed. Therefore, this step fuses the edge distribution and gray-level jump amplitude distribution to generate morphological discrimination coefficients for suspected defect marks, and then compares the morphological discrimination coefficients with preset discrimination benchmark values to determine whether a suspected defect mark belongs to a real defect mark based on the comparison results.
[0076] The morphological discrimination coefficient for generating suspected defect markers is first obtained by extracting the frequency of the directional angle corresponding to the main direction from the edge direction distribution. Then, the edge direction concentration component of the suspected defect marker is determined based on the ratio between the frequency of the directional angle corresponding to the main direction and the total frequency of directional angles in the edge direction distribution. The main direction is determined by traversing all directional angle value intervals in the edge direction distribution, finding the interval with the highest frequency, and taking the directional angle corresponding to that interval as the main direction. In one embodiment, the main direction is taken as the median angle of the interval with the highest frequency. In another feasible implementation, the main direction is determined by weighted averaging of the directional angles in the interval with the highest frequency and its adjacent intervals to obtain a sub-interval precision estimate of the main direction. The total frequency of directional angle occurrences is the sum of the frequencies of all directional angle value intervals, and its value is equal to the total number of pixels in the image region corresponding to the suspected defect marker.
[0077] The frequency of occurrence of the direction angle corresponding to the main direction is denoted as . The total frequency of the direction angle is denoted as Then the edge direction concentration component Calculated using the following formula:
[0078] ;
[0079] in This represents the edge direction concentration component of the suspected defect marker. When this ratio approaches 1, it indicates that the edge directions of the vast majority of pixels in the region are concentrated in the same direction, exhibiting typical characteristics of artificial or molding defects. When this ratio approaches 0, it indicates that the edge directions in the region are uniformly distributed in all directions, exhibiting typical characteristics of texture noise or random interference. The value range of the edge direction concentration component is from 0 to 1.
[0080] Then, gray-level differences and their corresponding frequencies are extracted from the gray-level jump amplitude distribution. The gray-level differences are multiplied by their corresponding frequencies and then summed. The mean gray-level jump amplitude component of the suspected defect mark is determined based on the ratio between the summed result and the total frequency of gray-level differences in the gray-level jump amplitude distribution. The total frequency of gray-level differences is the sum of the frequencies across all difference value intervals, and its value is also equal to the total number of pixels in the image region corresponding to the suspected defect mark.
[0081] For the distribution of grayscale jump amplitude, the first... The range of each difference value is denoted as the corresponding grayscale jump amplitude. Record its frequency of occurrence as . Indicates the index of the range of difference values. The value range is 1 to , This represents the total number of intervals for the difference values in the grayscale jump amplitude distribution. In one embodiment, Take the midpoint of the range of values for this difference. In another feasible implementation, The weighted average of the difference values over the specified range is taken, with the weights determined based on the actual distribution of grayscale jump amplitudes within that range. (Mean component of grayscale jump amplitude) Calculated using the following formula:
[0082] ;
[0083] in, This represents the mean grayscale jump amplitude of suspected defect markers, expressed in gray levels. A high value indicates drastic grayscale changes between pixels within the region, suggesting obvious edges or abrupt changes, consistent with the grayscale characteristics of genuine defects. A low value indicates gradual grayscale changes within the region, more closely resembling residual interference from texture fluctuations or flat areas. For an 8-bit grayscale image, the theoretical range for the mean grayscale jump amplitude component is 0 to 255.
[0084] Determine the concentration components of the edge orientation. and the mean component of grayscale jump amplitude Then, the two are fused to generate morphological discrimination coefficients for suspected defect markers. In one feasible implementation, the morphological discrimination coefficient is calculated using a weighted summation method, and the formula is as follows:
[0085] ;
[0086] in, The morphological discrimination coefficient represents the suspected defect marker. This represents the first fusion weight coefficient corresponding to the edge direction concentration component. This represents the second fusion weight coefficient corresponding to the mean component of the grayscale jump amplitude. and The sum of the values of is equal to 1. In one embodiment, The value is 0.5. A value of 0.5 indicates that the two components contribute equally. In another feasible implementation, for detection scenarios where defect directionality is obvious but grayscale contrast is low, The value is 0.7. A value of 0.3 is used to emphasize the effect of edge concentration. In another feasible implementation, for detection scenarios where defect grayscale abrupt changes are significant and directionally irregular, The value is 0.3. The value is set to 0.7 to highlight the effect of the grayscale jump amplitude. and The specific value can be adjusted according to the typical defect types on the surface of the plastic product.
[0087] This represents the preset grayscale jump amplitude normalization constant, which is used to normalize the mean component of the grayscale jump amplitude to a numerical range similar to the edge direction concentration component. The value is determined based on the image's grayscale bit depth. For an 8-bit image, In one embodiment, it is set to 50. In another possible implementation... The grayscale jump amplitude mean component is set to be the reciprocal of the statistical average value of the entire defect-free area of the plastic surface multiplied by a preset target normalization value, so that the normalized grayscale jump amplitude mean component is numerically comparable to the edge direction concentration component.
[0088] In another feasible implementation, the morphological discriminant coefficient can be fused using either product fusion or nonlinear fusion. In product fusion, the morphological discriminant coefficient equals the edge direction concentration component multiplied by the normalized mean grayscale jump amplitude component. In nonlinear fusion, the morphological discriminant coefficient equals the exponent of the edge direction concentration component multiplied by the exponent of the normalized mean grayscale jump amplitude component. In yet another feasible implementation, the morphological discriminant coefficient can be generated using a pre-trained linear discriminant analysis model or support vector machine classifier. This involves using the edge direction concentration component and the mean grayscale jump amplitude component as input features, and then using the trained classifier to output a comprehensive discriminant score as the morphological discriminant coefficient.
[0089] The preset discrimination benchmark value is used to provide a reference for judging the morphological discrimination coefficient. The discrimination benchmark value is determined as follows: A large number of sample plastic product images of known categories are pre-collected; the morphological discrimination coefficients of suspected defect markers in each sample are extracted according to the aforementioned steps; the distribution of morphological discrimination coefficients for the true defect category and the non-defect interference category is statistically analyzed; and the discrimination benchmark value is set as the optimal classification threshold for the two distributions. In one embodiment, the discrimination benchmark value is the arithmetic mean of the mean morphological discrimination coefficients of the true defect category and the mean morphological discrimination coefficients of the non-defect interference category. In another feasible implementation, the discrimination benchmark value is a threshold that balances the recall and precision of the true defect category; this threshold is determined by the optimal operating point on the receiver operating characteristic curve. The preset discrimination benchmark value is denoted as... Its numerical range is consistent with the range of values for the morphological discrimination coefficient.
[0090] After determining the discrimination benchmark value, the morphological discrimination coefficient is compared with the preset benchmark value to generate deviation direction information and deviation magnitude information of the morphological discrimination coefficient relative to the benchmark value. The deviation direction information indicates whether the morphological discrimination coefficient is greater than or less than the benchmark value. The deviation magnitude information indicates the absolute magnitude of the difference between the morphological discrimination coefficient and the benchmark value.
[0091] Based on the deviation direction and deviation magnitude information, it is determined whether the morphological discrimination coefficient falls within the acceptance interval defined by a preset discrimination benchmark value. This acceptance interval corresponds to the range of morphological discrimination coefficient values for a true defect marker. In one embodiment, the acceptance interval is defined as a one-sided interval greater than or equal to the discrimination benchmark value; that is, the higher the morphological discrimination coefficient, the more likely it is to be judged as a true defect. In another feasible implementation, the acceptance interval is defined as a two-sided interval centered on the discrimination benchmark value; that is, when the morphological discrimination coefficient falls within a specific width range near the discrimination benchmark value, it is judged as a true defect.
[0092] When the morphological discrimination coefficient falls within the acceptance range, the suspected defect marker is determined to be a true defect marker. When the morphological discrimination coefficient does not fall within the acceptance range, the suspected defect marker is determined to be a non-defect interference marker. After being determined to be a non-defect interference marker, this marker is ignored in subsequent processing and is no longer included in the output range of the defect detection results.
[0093] In one specific implementation, when the acceptance interval is a one-sided interval greater than or equal to the discrimination benchmark value, the judgment rule is: when Greater than or equal to When this happens, the suspected defect marker is determined to be a genuine defect marker. Less than When the suspected defect marker is determined to be a non-defect interference marker, it is further classified as such. In another specific implementation, when the acceptance interval is a two-sided interval centered on the discrimination benchmark value, the determination rule is: when... fall into Subtract the allowable deviation value to When the tolerance deviation value falls within the defined range, the suspected defect marker is determined to be a genuine defect marker. The typical range for the tolerance deviation value is 5% to 10% of the theoretical maximum value of the morphological discrimination coefficient. If the suspected defect marker does not fall within the specified range, it is determined to be a non-defect interference marker.
[0094] In another feasible implementation, when the morphological discrimination coefficient falls within the acceptable range but deviates too much, a confidence assessment step is required. This involves determining the confidence level of the judgment result based on the magnitude of the deviation; the larger the deviation, the higher the confidence level. When the confidence level is lower than a preset confidence threshold, the suspected defect is marked as pending review and sent to the manual review stage for final confirmation.
[0095] Through the fusion and comparison of the aforementioned morphological discrimination coefficients, each suspected defect marker is quantified into a single morphological discrimination coefficient across two feature dimensions: edge convergence and average grayscale jump amplitude. This coefficient, compared with a discrimination benchmark, distinguishes suspected defect markers into genuine defect markers and non-defect interference markers. Genuine defects, due to their concentrated boundary direction and pronounced grayscale jumps, receive higher morphological discrimination coefficients and fall within the acceptable range. Non-defect interference, due to its dispersed edge direction and gentler grayscale jumps, receives lower morphological discrimination coefficients and is excluded. This effectively identifies residual interference after frequency band differential processing, ensuring high accuracy in defect detection results.
[0096] like Figure 2 The diagram shown is a functional block diagram of a plastic product appearance defect detection system based on image difference provided in an embodiment of the present invention.
[0097] The image difference-based plastic product appearance defect detection system of the present invention can be installed in an electronic device. Depending on the functions implemented, the image difference-based plastic product appearance defect detection system may include an illumination normalization module, an image registration module, a frequency band difference module, a feature extraction module, and a defect discrimination module. The module described in this invention can also be called a unit, which refers to a series of computer program segments that can be executed by the processor of an electronic device and can perform a fixed function, and is stored in the memory of the electronic device.
[0098] In this embodiment, the functions of each module / unit are as follows:
[0099] The illumination normalization module is used to acquire the original image of the surface of the plastic product to be inspected, and to perform illumination normalization transformation on the original image to generate an illumination correction map under standard illumination.
[0100] The image registration module is used to spatially register the illumination correction image with a preset standard reference image of the corresponding model to generate a spatially aligned floating image and a reference image.
[0101] The frequency band difference module is used to perform multi-frequency band texture weighted difference operation on the reference map and the floating map to generate a difference response map. The multi-frequency band texture weighted difference operation is used to separate and differentially suppress non-defect differences between the floating map and the reference map from the frequency domain dimension.
[0102] The feature extraction module is used to perform connected component search on the difference response map to extract suspected defect markers, and to collect edge direction distribution and gray-level jump amplitude distribution in the image area corresponding to the suspected defect markers;
[0103] The defect discrimination module is used to generate a morphological discrimination coefficient of the suspected defect mark by fusing the edge direction distribution and the gray level jump amplitude distribution, compare the morphological discrimination coefficient with a preset discrimination benchmark value, and determine whether the suspected defect mark belongs to a real defect mark based on the comparison result.
[0104] This application provides a method for detecting plastic product appearance defects based on image difference. The execution entity of the image difference-based plastic product appearance defect detection method includes, but is not limited to, at least one of the following electronic devices that can be configured to execute the method provided in this application: a server, a terminal, etc. In other words, the image difference-based plastic product appearance defect detection method can be executed by software or hardware installed on a terminal device or a server device. The server includes, but is not limited to, a single server, a server cluster, a cloud server, or a cloud server cluster. The server can be an independent server or a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communication, middleware services, domain name services, security services, content delivery networks (CDNs), and big data and artificial intelligence platforms.
[0105] In the several embodiments provided by this invention, it should be understood that the disclosed methods and systems can be implemented in other ways. For example, the system embodiments described above are merely illustrative; for instance, the division of modules is only a logical functional division, and other division methods may be used in actual implementation.
[0106] The modules described as separate components may or may not be physically separate. The components shown as modules may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the modules can be selected to achieve the purpose of this embodiment, depending on actual needs.
[0107] Furthermore, the functional modules in the various embodiments of the present invention can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or in the form of hardware plus software functional modules.
[0108] It will be apparent to those skilled in the art that the present invention is not limited to the details of the exemplary embodiments described above, and that the present invention can be implemented in other specific forms without departing from the spirit or essential characteristics of the present invention.
[0109] This application embodiment can acquire and process relevant data based on artificial intelligence technology. Artificial intelligence is the theory, method, technology, and application system that uses digital computers or machines controlled by digital computers to simulate, extend, and expand human intelligence, perceive the environment, acquire knowledge, and use that knowledge to obtain optimal results.
[0110] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention and are not intended to limit it. Although the present invention has been described in detail with reference to preferred embodiments, those skilled in the art should understand that modifications or equivalent substitutions can be made to the technical solutions of the present invention without departing from the spirit and scope of the technical solutions of the present invention.
Claims
1. A method for detecting appearance defects in plastic products based on image difference, characterized in that, The method includes: Pt.
1. Acquire the original image of the surface of the plastic product to be inspected, and perform illumination normalization transformation on the original image to generate an illumination correction image under standard illumination. Pt.
2. Spatial registration is performed between the illumination correction image and the preset standard reference image of the corresponding model to generate a spatially aligned floating image and reference image; Pt.
3. Perform multi-band texture weighted difference operation on the reference image and the floating image to generate a difference response image. The multi-band texture weighted difference operation is used to separate and differentially suppress non-defect differences between the floating image and the reference image from the frequency domain dimension. Pt.
4. Perform connected component search on the difference response map to extract suspected defect markers, and collect edge direction distribution and gray level jump amplitude distribution in the image area corresponding to the suspected defect markers; Pt.
5. Based on the edge direction distribution and the grayscale jump amplitude distribution, the morphological discrimination coefficient of the suspected defect mark is generated by fusion. The morphological discrimination coefficient is compared with the preset discrimination benchmark value. Based on the comparison result, it is determined whether the suspected defect mark belongs to the real defect mark.
2. The method for detecting plastic product appearance defects based on image difference as described in claim 1, characterized in that, The process of performing illumination normalization transformation on the original image to generate an illumination correction map under standard illumination specifically includes: The illumination response intensity of pixels in the original image of the surface of the plastic product to be inspected is acquired, and the illumination response sequence of the original image is extracted based on the illumination response intensity of the pixels. The illumination response sequence is compared with the standard illumination template sequence by pixel position to determine the illumination correction coefficient of the pixel position. Based on the illumination correction coefficient at the pixel location, the grayscale values at the pixel locations in the original image are mapped and transformed to generate an illumination correction map under standard illumination.
3. The method for detecting plastic product appearance defects based on image difference as described in claim 1, characterized in that, The illumination correction image is spatially registered with a preset standard reference image of the corresponding model to generate a spatially aligned floating image and reference image, specifically including: The edge contours of the illumination correction map are extracted to obtain the distribution of edge contour points of the illumination correction map. The spatial positions of the edge contour point distribution of the illumination correction map and the edge contour point distribution of the standard reference image are compared to determine the spatial transformation parameters between the illumination correction map and the standard reference image. Based on the spatial transformation parameters, the illumination correction map is mapped to coordinate space to generate a floating map aligned with the spatial position of the standard reference image, and the standard reference image is used as the reference map.
4. The method for detecting plastic product appearance defects based on image difference as described in claim 1, characterized in that, The multi-band texture weighted difference operation between the reference image and the floating image specifically includes: Wavelet transform decomposition is performed synchronously on the reference map and the floating map, decomposing the reference map into a reference low-frequency coefficient map, a reference mid-frequency coefficient map, and a reference high-frequency coefficient map, and synchronously decomposing the floating map into a floating low-frequency coefficient map, a floating mid-frequency coefficient map, and a floating high-frequency coefficient map; Low-frequency difference components are extracted from the reference low-frequency coefficient map and the floating low-frequency coefficient map. The low-frequency difference components characterize the overall brightness deviation and batch color deviation between the floating map and the reference map. Intermediate frequency difference components are extracted from the reference intermediate frequency coefficient map and the floating intermediate frequency coefficient map, and the intermediate frequency difference components characterize the surface substrate texture deviation between the floating map and the reference map; High-frequency difference components are extracted from the reference high-frequency coefficient map and the floating high-frequency coefficient map. The high-frequency difference components characterize the edge and detail abrupt deviations between the floating map and the reference map.
5. The method for detecting plastic product appearance defects based on image difference as described in claim 4, characterized in that, The multi-band texture weighted difference operation also includes: The low-frequency difference components are corrected by grayscale mapping to cancel out the overall brightness deviation and batch color deviation in the low-frequency difference components, thereby generating a low-frequency correction difference map. A regional differential tolerance weight is applied to the intermediate frequency difference component. The regional differential tolerance weight is determined based on the local texture entropy value of each pixel position in the reference intermediate frequency coefficient map. The differential tolerance weight of the texture-dense region is greater than that of the texture-sparse region, thereby generating an intermediate frequency weighted difference map. Gradient mutation screening is performed on the high-frequency difference components, retaining high-frequency difference components whose gradient amplitude exceeds a preset gradient threshold, and filtering out high-frequency difference components that do not exceed the preset gradient threshold, thereby generating a high-frequency screening difference map. The low-frequency correction difference map, the mid-frequency weighted difference map, and the high-frequency screening difference map are spatially recombined pixel-by-pixel to generate a difference response map.
6. The method for detecting plastic product appearance defects based on image difference as described in claim 1, characterized in that, The connection domain search performed on the difference response graph to extract suspected defect markers specifically includes: A pixel neighborhood connectivity determination rule is set, which is used to determine whether adjacent pixel positions in the difference response map belong to the same connected component; The pixel positions of the difference response map are traversed, and the response values of the pixel positions are compared with the preset response threshold one by one to filter out the feature pixel positions whose response values exceed the response threshold. According to the pixel neighborhood connectivity determination rule, the selected feature pixel positions are aggregated, and the feature pixel positions that mutually satisfy the neighborhood connectivity determination rule are grouped into the same pixel group, generating the distribution range of the pixel group and the spatial position parameters of the pixel group. The image region corresponding to the pixel group is marked as a suspected defect marker.
7. The method for detecting plastic product appearance defects based on image difference as described in claim 1, characterized in that, The edge direction distribution and grayscale jump amplitude distribution within the image region corresponding to the suspected defect marker specifically include: Based on the spatial location parameters of the suspected defect marker, locate the image region corresponding to the suspected defect marker in the illumination correction map; Within the corresponding image region, the edge direction angle of each pixel position is obtained along the pixel position arrangement direction, and an edge direction sequence is generated based on the edge direction angle of each pixel position; Within the corresponding image region, the grayscale difference between adjacent pixel positions is obtained, and a grayscale jump amplitude sequence is generated based on the grayscale difference between adjacent pixel positions. The edge direction angles in the edge direction sequence are classified according to their value range to generate the edge direction distribution of the corresponding image region; The gray-level differences in the gray-level jump amplitude sequence are categorized according to their value ranges to generate the gray-level jump amplitude distribution of the corresponding image region.
8. The method for detecting plastic product appearance defects based on image difference as described in claim 1, characterized in that, The morphological discrimination coefficients for generating the suspected defect markers through fusion specifically include: Extract the frequency of the direction angle corresponding to the main direction from the edge direction distribution, and determine the edge direction concentration component of the suspected defect mark based on the ratio between the frequency of the direction angle corresponding to the main direction and the total frequency of the direction angle in the edge direction distribution; Extract the grayscale difference and the corresponding occurrence frequency from the grayscale jump amplitude distribution. Multiply the grayscale difference and its corresponding occurrence frequency and then sum them up. Based on the ratio between the summation result and the total occurrence frequency of grayscale difference in the grayscale jump amplitude distribution, determine the mean grayscale jump amplitude component of the suspected defect mark. The edge direction concentration component and the gray-level jump amplitude mean component are fused to generate the morphological discrimination coefficient of the suspected defect mark.
9. The method for detecting plastic product appearance defects based on image difference as described in claim 1, characterized in that, The morphological discrimination coefficient is compared with a preset discrimination benchmark value, and the determination of whether the suspected defect mark belongs to a real defect mark based on the comparison result specifically includes: The morphological discrimination coefficient is compared with a preset discrimination benchmark value to generate deviation direction information and deviation magnitude information of the morphological discrimination coefficient relative to the discrimination benchmark value; Based on the deviation direction information and the deviation magnitude information, it is determined whether the morphology discrimination coefficient falls within the acceptance range defined by the preset discrimination benchmark value. The acceptance range corresponds to the range of values for the morphology discrimination coefficient of the real defect mark. When the morphological discrimination coefficient falls within the acceptance range, the suspected defect marker is determined to be a real defect marker; When the morphological discrimination coefficient does not fall within the acceptance range, the suspected defect marker is determined to be a non-defect interference marker.
10. A plastic product appearance defect detection system based on image difference, characterized in that, The system for implementing the image difference-based plastic product appearance defect detection method of claim 1 includes: The illumination normalization module is used to acquire the original image of the surface of the plastic product to be inspected, and to perform illumination normalization transformation on the original image to generate an illumination correction map under standard illumination. The image registration module is used to spatially register the illumination correction image with a preset standard reference image of the corresponding model to generate a spatially aligned floating image and a reference image. The frequency band difference module is used to perform multi-frequency band texture weighted difference operation on the reference image and the floating image to generate a difference response image. The multi-frequency band texture weighted difference operation is used to separate and differentially suppress non-defect differences between the floating image and the reference image from the frequency domain dimension. The feature extraction module is used to perform connected component search on the difference response map to extract suspected defect markers, and to collect edge direction distribution and gray-level jump amplitude distribution in the image region corresponding to the suspected defect markers; The defect discrimination module is used to generate a morphological discrimination coefficient of the suspected defect mark by fusing the edge direction distribution and the gray level jump amplitude distribution, compare the morphological discrimination coefficient with a preset discrimination benchmark value, and determine whether the suspected defect mark belongs to a real defect mark based on the comparison result.
