Defect detection method, device and storage medium
By combining grayscale enhancement, fast Fourier transform algorithm and threshold segmentation algorithm, the problem of difficulty in identifying defects on the surface of battery cells that are similar to the background in existing technologies is solved, and the accuracy and stability of battery cell defect detection are achieved.
Patent Information
- Application Number
- CN202310898153.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-07-20
- Publication Date
- 2025-11-18
- Estimated Expiration
- 2043-07-20
AI Technical Summary
Existing defect detection algorithms struggle to accurately identify cell surface defects that are similar to the background, leading to missed and over-detection, which affects cell production quality and stability.
By combining grayscale enhancement, fast Fourier transform algorithm and threshold segmentation algorithm, the background region and the foreground region are segmented, grayscale curves are generated and smoothed, and finally defect features are extracted through dynamic thresholding.
This improves the accuracy of defect detection, avoids background interference, maximizes the highlighting of defect feature areas, and enhances the quality and stability of battery cell production.
Smart Images

Figure CN117011250B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of image detection technology, and in particular to a defect detection method, apparatus and storage medium. Background Technology
[0002] Currently, in the process of visually inspecting product components, manual inspection is inefficient, labor-intensive, and lacks accuracy. Furthermore, it is significantly affected by objective factors such as the skill level of the personnel, easily causing fluctuations in the appearance quality of the carrier tape product and impacting inspection accuracy. Related technologies often require photographic acquisition of the components, which users then analyze to determine whether defects or damage exist.
[0003] In the visual inspection process, product inspection algorithms are typically used to analyze images of the product to obtain the structural state of its surface. However, some surface defects such as stains and blemishes are very similar to the background of the image, resulting in similar grayscale values across the entire image. Even when using product inspection algorithms to identify the image, it is impossible to extract the accurate defect areas, leading to missed or over-detection of poor-quality battery cells. Therefore, existing detection algorithms struggle to extract defects that are similar to the background, thus failing to improve the accuracy of surface defect detection for battery cells and reducing the quality and stability of battery cell production. Summary of the Invention
[0004] The main objective of this application is to propose a defect detection method, apparatus, and storage medium that can accurately calculate the grayscale value of a battery cell image and improve the accuracy of defect detection.
[0005] To achieve the above objectives, a first aspect of this application provides a defect detection method, the method comprising:
[0006] A grayscale enhancement operation is performed on the acquired image to be processed to obtain a feature image, wherein the image to be processed is obtained by image acquisition of the product to be tested;
[0007] The feature image is frequency-converted based on a preset fast Fourier transform algorithm to generate a first image and a grayscale curve corresponding to the first image.
[0008] A smoothing fitting operation is performed on the grayscale curve to generate a second image;
[0009] Dynamic thresholding is performed on the first image and the second image based on a preset threshold segmentation algorithm to determine defect features.
[0010] In some embodiments, performing grayscale enhancement on the acquired image to be processed to obtain a feature image includes:
[0011] The image to be processed is segmented based on the preset maximum inter-class variance method to obtain the background region and the region of interest, wherein the region of interest includes the feature region;
[0012] The region of interest is subjected to mean filtering to obtain a filtered image;
[0013] The grayscale value of the filtered image is calculated to distinguish the feature region from the background region, resulting in a feature image showing the feature region.
[0014] In some embodiments, calculating the grayscale value of the filtered image to distinguish the feature region and the background region, and obtaining a feature image showing the feature region, includes:
[0015] Calculate the grayscale value of the filtered image to obtain the first grayscale value and the second grayscale value of the filtered image;
[0016] The amplification factor and the deviation value are determined based on the first gray value and the second gray value;
[0017] The brightness of the filtered image is adjusted based on the magnification factor and the deviation value to obtain the feature image.
[0018] In some embodiments, the step of performing frequency conversion on the feature image based on a preset Fast Fourier Transform algorithm to generate a first image and a grayscale curve corresponding to the first image includes:
[0019] The feature image is smoothed by using a preset Gaussian filter;
[0020] The first image is obtained by performing spectral analysis on the smoothed feature image based on the preset fast Fourier algorithm and the Gaussian filter.
[0021] Traverse all pixels in the first image to generate a grayscale curve corresponding to the first image.
[0022] In some embodiments, the step of performing a smoothing fitting operation on the grayscale curve to generate a second image includes:
[0023] Create a fitting function based on the grayscale curve;
[0024] The fitting function is solved using the least squares method to obtain the fitting coefficients;
[0025] For each coordinate data in the grayscale curve, the fitting function value of the coordinate data is calculated based on the fitting coefficient;
[0026] The first image is fitted based on the fitting function value to generate the second image.
[0027] In some embodiments, the dynamic thresholding of the first image and the second image based on a preset threshold segmentation algorithm to determine defect features in the feature region includes:
[0028] The first and second images are binarized using a threshold segmentation algorithm to obtain the third and fourth images.
[0029] Subtract the third image from the fourth image to obtain a grayscale difference image;
[0030] For each pixel in the grayscale difference image, the grayscale difference of the pixel is compared with a preset grayscale threshold to obtain a first grayscale set and a second grayscale set, wherein the grayscale difference of the pixels in the first grayscale set is greater than the grayscale threshold, and the grayscale difference of the pixels in the second grayscale set is less than or equal to the grayscale threshold.
[0031] Based on the first grayscale set, feature extraction is performed on the feature image to obtain defect features.
[0032] In some embodiments, the dynamic thresholding of the first image and the second image based on a preset threshold segmentation algorithm to determine defect features in the feature region includes:
[0033] The first and second images are binarized using a threshold segmentation algorithm to obtain the third and fourth images.
[0034] Subtract the third image from the fourth image to obtain a grayscale difference image;
[0035] For each pixel in the grayscale difference image, the grayscale difference of the pixel is compared with a preset grayscale threshold to obtain a first grayscale set and a second grayscale set, wherein the grayscale difference of the pixels in the first grayscale set is greater than the grayscale threshold, and the grayscale difference of the pixels in the second grayscale set is less than or equal to the grayscale threshold.
[0036] Based on the first grayscale set, feature extraction is performed on the feature image to obtain defect features.
[0037] In some embodiments, the spectral analysis of the smoothed feature image based on the preset Fast Fourier algorithm and the Gaussian filter to obtain the first image includes:
[0038] The size of the smoothed feature image is adjusted.
[0039] Based on the Fast Fourier Transform algorithm, frequency analysis is performed on the size-adjusted feature image to determine the first amplitude value and the second amplitude value in the feature image;
[0040] The target spectrum is obtained by filtering the first amplitude value and the second amplitude value using the Gaussian filter.
[0041] The target spectrum is subjected to an inverse Fourier transform, and the target spectrum after the inverse Fourier transform is frequency filtered according to the Gaussian filter to obtain a first image.
[0042] A second aspect of this application provides a defect detection device, the device comprising:
[0043] The grayscale enhancement module is used to perform grayscale enhancement operations on the acquired image to be processed to obtain a feature image, wherein the image to be processed is obtained by image acquisition of the product to be tested;
[0044] The frequency conversion module is used to perform frequency conversion on the feature image based on a preset fast Fourier algorithm to generate a first image and a grayscale curve corresponding to the first image.
[0045] The smoothing fitting module is used to perform a smoothing fitting operation on the grayscale curve to generate a second image.
[0046] The defect determination module is used to perform dynamic thresholding on the first image and the second image based on a preset threshold segmentation algorithm to determine defect features.
[0047] A third aspect of this application provides a storage medium, which is a computer-readable storage medium storing a computer program. When the computer program is executed by a computer, the computer is used to perform the defect detection method as described in any one of the embodiments of the first aspect of this application.
[0048] The defect detection method, apparatus, and storage medium proposed in this application have the following beneficial effects: First, grayscale enhancement is performed on the obtained image of the product to be tested to separate the background and foreground regions of the image, highlighting the stain features of the image and obtaining a feature image. Then, frequency conversion is performed on the feature image based on the fast Fourier transform algorithm to further increase the contrast between the stain and the background, filter out other noise in the feature image, and generate a first image and a grayscale curve corresponding to the first image, thereby clearly displaying the grayscale values of the pixels in the first image. After that, a smoothing fitting operation is performed on the grayscale curve to improve the stability and accuracy of the fitted curve and correct the data. Finally, dynamic threshold processing is performed on the first image and the second image based on the threshold segmentation algorithm to determine the defect features, thereby achieving accurate extraction of defect features, avoiding the influence of the background on the defects, and maximizing the highlighting of the defect feature area. Attached Figure Description
[0049] Figure 1 This is a flowchart of a defect detection method provided in one embodiment of this application;
[0050] Figure 2 yes Figure 1 The detailed flowchart of step S101;
[0051] Figure 3 yes Figure 2 The detailed flowchart of step S203;
[0052] Figure 4 yes Figure 1 The detailed flowchart of step S102;
[0053] Figure 5 yes Figure 1 The detailed flowchart of step S103;
[0054] Figure 6 yes Figure 1 The detailed flowchart of step S104;
[0055] Figure 7 yes Figure 4 The detailed flowchart of step S403;
[0056] Figure 8 yes Figure 4 The detailed flowchart of step S402;
[0057] Figure 9 This is a schematic diagram of the defect detection device provided in the embodiments of this application;
[0058] Figure 10 This is a schematic diagram of the feature image provided in the example of this application;
[0059] Figure 11 This is a schematic diagram of the defect features in the feature image provided in the example of this application;
[0060] Figure 12 This is a schematic diagram of the hardware structure of the computer device provided in the embodiments of this application. Detailed Implementation
[0061] To make the objectives, technical solutions, and advantages of this application clearer, the following detailed description is provided in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative and not intended to limit the scope of this application.
[0062] It should be noted that although functional modules are divided in the device schematic diagram and a logical order is shown in the flowchart, in some cases, the steps shown or described may be performed in a different order than the module division in the device or the order in the flowchart. The terms "first," "second," etc., in the specification, claims, and the aforementioned drawings are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence.
[0063] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the art to which this application belongs. The terminology used herein is for the purpose of describing embodiments of this application only and is not intended to limit this application.
[0064] The defect detection method provided in this application can be applied to a terminal, a server, or software running on either a terminal or a server. In some embodiments, the terminal can be a smartphone, tablet, laptop, desktop computer, or smartwatch, etc.; the server can be configured as an independent physical server, a server cluster or distributed system composed of multiple physical servers, or a cloud server providing 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 (CDN), and big data and artificial intelligence platforms; the software can be an application implementing the above method, but is not limited to the above forms.
[0065] The embodiments of this application can be used in numerous general-purpose or special-purpose computer system environments or configurations. Examples include: personal computers, server computers, handheld or portable devices, tablet devices, multiprocessor systems, microprocessor-based systems, set-top boxes, programmable consumer computer devices, network PCs, minicomputers, mainframe computers, and distributed computing environments including any of the above systems or devices. This application can be described in the general context of computer-executable instructions executed by a computer, such as program modules. Generally, program modules include routines, programs, objects, components, data structures, etc., that perform specific tasks or implement specific abstract data types. This application can also be practiced in distributed computing environments where tasks are performed by remote processing devices connected via a communication network. In distributed computing environments, program modules can reside in local and remote computer storage media, including storage devices.
[0066] Currently, in the process of visually inspecting battery cells, manual inspection is inefficient, labor-intensive, and lacks accuracy. Furthermore, it is significantly affected by objective factors such as the skill level of the personnel, easily causing fluctuations in the appearance quality of the carrier tape and impacting the accuracy of the inspection. Related technologies often require photographic acquisition of the device, which users then analyze to determine whether the device has defects or damage.
[0067] In the process of appearance inspection, product inspection algorithms are typically used to analyze images of industrially produced products to obtain the structural state of the product surface. However, some surface defects such as stains and blemishes are very similar to the background of the image, resulting in similar grayscale values across the entire image. Even when using product inspection algorithms to identify the image, it is impossible to extract the accurate defect areas. Therefore, existing detection algorithms struggle to extract defects that are similar to the background, thus failing to improve the accuracy of surface defect detection for battery cells and reducing the quality and stability of battery cell production.
[0068] To address the aforementioned issues, this embodiment provides a defect detection method, apparatus, and storage medium. First, a grayscale enhancement operation is performed on the acquired image of the product to be tested to separate the background and foreground regions, highlighting the stain features and obtaining a feature image. Then, a frequency conversion operation is performed on the feature image based on the Fast Fourier Transform algorithm to further increase the contrast between the stains and the background, filtering out other noise in the feature image and generating a first image and a corresponding grayscale curve. This clearly displays the grayscale values of the pixels in the first image. Next, a smoothing fitting operation is performed on the grayscale curve to improve its stability and accuracy, correcting the data. Finally, a threshold segmentation algorithm is used to perform dynamic threshold processing on the first and second images to determine defect features, thereby achieving accurate extraction of defect features, avoiding the influence of the background on defects, and maximizing the highlighting of defect feature areas.
[0069] Please refer to Figure 1 , Figure 1 This is a flowchart of a specific method of the defect detection method provided in the embodiments of this application. In some embodiments, the defect detection method includes, but is not limited to, steps S101 to S104.
[0070] Step S101: Perform grayscale enhancement on the acquired image to be processed to obtain a feature image;
[0071] It should be noted that the image to be processed is obtained by image acquisition from the product under test.
[0072] In some embodiments, grayscale enhancement is performed on the acquired image to be processed to separate the background region from the foreground region of the image to be processed, thereby obtaining a feature image. Furthermore, grayscale enhancement is used to remove noise interference, making the feature image more uniform.
[0073] It should be noted that the products to be tested include, but are not limited to, battery products, silicon wafers, or other products that require differentiation of minor stains. The feature images are obtained by triggering image acquisition under uniform lighting conditions on the products to be tested, thereby avoiding the influence of uneven lighting and improving the accuracy of extracting defect features.
[0074] Step S102: Based on the preset fast Fourier transform algorithm, the feature image is frequency transformed to generate a first image and a grayscale curve corresponding to the first image.
[0075] In some embodiments, the feature image is frequency-converted based on a preset fast Fourier transform algorithm, thereby filtering out the high-frequency components of the image and retaining the low-frequency components of the image, generating a first image and a grayscale curve corresponding to the first image, which can clearly show the grayscale values of the pixels in the first image.
[0076] Step S103: Perform a smoothing fitting operation on the grayscale curve to generate a second image;
[0077] In some embodiments, a smoothing fitting operation is performed on the grayscale curve to generate a second image, thereby achieving a smooth fit of the grayscale curve, reducing the impact of noise, improving the stability and accuracy of the fitted curve, and facilitating subsequent data processing and correction.
[0078] Step S104: Perform dynamic thresholding on the first image and the second image based on a preset threshold segmentation algorithm to determine defect features.
[0079] In some embodiments, dynamic thresholding is performed on the first image and the second image based on a preset threshold segmentation algorithm to facilitate the observation and analysis of defect areas, determine defect features, and thus achieve accurate extraction of defect features.
[0080] In some embodiments, the first image and the second image are binarized based on a preset threshold segmentation algorithm to maximize the highlighting of defect feature regions, and the binarized regions are contour-dilated using a convolution dilation algorithm to determine the feature regions of the image to be processed, thereby improving boundary connectivity, eliminating noise points, and determining the feature regions of the image to be processed.
[0081] It should be noted that threshold segmentation algorithms include, but are not limited to, global fixed threshold algorithms, local adaptive threshold algorithms, and maximum inter-class variance algorithms; convolution dilation algorithms include, but are not limited to, edge extraction algorithms, grayscale reconstruction algorithms, and Boolean operation algorithms, etc., and this embodiment does not impose specific limitations.
[0082] Please refer to Figure 2 , Figure 2 This is a flowchart illustrating step S101 provided in an embodiment of this application. In some embodiments, step S101 includes, but is not limited to, steps S201 and S203.
[0083] Step S201: Perform background segmentation on the image to be processed based on the preset maximum inter-class variance method to obtain the background region and the region of interest;
[0084] It should be noted that the region of interest includes feature regions, which are stains, damage, etc. on the product to be tested.
[0085] In some embodiments, background segmentation of the image to be processed is performed based on a preset maximum inter-class variance method, thereby separating the background region and the foreground region of the image to be processed, obtaining the background region and the region of interest, which facilitates the subsequent accurate analysis of the region of interest.
[0086] It should be noted that in the process of background segmentation of the image to be processed using the Otsu's method, firstly, the image to be processed is converted to grayscale, and then the histogram of the grayscale image is calculated to count the number of pixels at each grayscale level. Next, the histogram is normalized by dividing the number of pixels at each grayscale level by the total number of pixels to obtain the pixel probability distribution. Finally, the inter-class variance of each grayscale level is calculated to divide the grayscale level into two categories: background and foreground. Finally, all grayscale levels are traversed, and the grayscale level with the largest inter-class variance value is selected as the threshold of the Otsu's method.
[0087] After obtaining the threshold of the Otsu's method, the pixel grayscale values of the image to be processed are filtered using this threshold. Those above the threshold are set as foreground regions, and those below the threshold are set as background regions. Then, the binarized image of the image to be processed is subjected to connected component analysis to obtain the region of interest of the image to be processed.
[0088] Step S202: Perform mean filtering on the region of interest to obtain the filtered image;
[0089] In some embodiments, mean filtering is performed on the region of interest based on a preset filter to obtain a filtered image, thereby removing noise from the region of interest, smoothing the image, and preserving the image details of the region of interest.
[0090] It should be noted that in the process of mean filtering the region of interest, the size of the filter is first defined, the filter is applied to each pixel of the image, the center of the filter is aligned with the current pixel, the mean value of the pixel values in the area covered by the filter is calculated, and the current pixel value is replaced by the mean value. This process is repeated until all pixels of the entire image are traversed to obtain the smoothed filtered image.
[0091] Step S203: Calculate the grayscale value of the filtered image to distinguish between the feature region and the background region, and obtain a feature image showing the feature region.
[0092] In some embodiments, the gray values of the filtered image are calculated to distinguish between the feature region and the background region, avoiding missed or false detections caused by the similarity of gray values between the background region and the feature region, thereby obtaining a feature image that shows the feature region and thus highlighting the feature region.
[0093] Please refer to Figure 3 , Figure 3 This is a flowchart illustrating step S203 provided in an embodiment of this application. In some embodiments, step S203 includes, but is not limited to, steps S301 and S303.
[0094] Step S301: Calculate the grayscale value of the filtered image to obtain the first grayscale value and the second grayscale value of the filtered image;
[0095] In some embodiments, the grayscale values of the filtered image are calculated to obtain a first grayscale value and a second grayscale value of the filtered image, wherein the first grayscale value is the minimum grayscale value of the filtered image and the second grayscale value is the maximum grayscale value of the filtered image.
[0096] Step S302: Determine the magnification factor and deviation value based on the first gray value and the second gray value;
[0097] In some embodiments, an amplification factor and a deviation value are calculated based on a first gray value and a second gray value, wherein the amplification factor is used to map the gray range of the filtered image to between 0 and 255, and the deviation value is used to adjust the overall brightness of the image.
[0098] It should be noted that the formula for calculating the magnification factor is mult = 255 / (max_gray - min_gray), and the formula for calculating the deviation value is offset = -mult * min_gray, where max_gray is the second gray value and min_gray is the first gray value.
[0099] Step S303: Adjust the brightness of the filtered image based on the magnification factor and the deviation value to obtain the feature image.
[0100] In some embodiments, the brightness of the filtered image is adjusted based on the magnification factor and the deviation value to obtain a feature image, thereby enhancing the grayscale of the image and highlighting the feature region.
[0101] It should be noted that the formula for adjusting the brightness of a filtered image is enhanced_image = mult * image + offset.
[0102] Please refer to Figure 4 , Figure 4 This is a flowchart illustrating step S102 provided in an embodiment of this application. In some embodiments, step S102 includes, but is not limited to, steps S401 and S403.
[0103] Step S401: Smooth the feature image using a preset Gaussian filter;
[0104] In some embodiments, the feature image is smoothed by a preset Gaussian filter, thereby filtering out high-frequency components of the image, retaining low-frequency components of the image, and suppressing Gaussian noise.
[0105] Step S402: Perform spectral analysis on the smoothed feature image based on the preset fast Fourier algorithm and Gaussian filter to obtain the first image;
[0106] In some embodiments, a first image is obtained by performing spectral analysis on the smoothed feature image based on a preset fast Fourier algorithm and a Gaussian filter, thereby understanding the intensity and distribution of each frequency component in the feature image, making the smoothing effect of the image more natural.
[0107] Step S403: Traverse all pixels in the first image to generate a grayscale curve corresponding to the first image.
[0108] In some embodiments, all pixels in the first image are traversed to generate a grayscale curve corresponding to the first image, thereby clearly displaying the grayscale values of the pixels in the first image.
[0109] Please refer to Figure 5 , Figure 5 This is a flowchart illustrating step S103 provided in an embodiment of this application. In some embodiments, step S103 includes, but is not limited to, steps S501 and S504.
[0110] Step S501: Create a fitting function based on the grayscale curve.
[0111] Step S502: Solve the fitting function using the least squares method to obtain the fitting coefficients;
[0112] Step S503: For each coordinate data in the grayscale curve, calculate the fitting function value of the coordinate data based on the fitting coefficient.
[0113] Step S504: Fit the first image according to the fitting function value to generate the second image.
[0114] In steps S501 to S504 of some embodiments, during the smoothing fitting operation of the grayscale curve, firstly, a fitting function is created based on the grayscale curve, such as a polynomial function, exponential function, logarithmic function, etc. Then, the fitting function is solved using the least squares method to obtain the fitting coefficients. For each coordinate data in the grayscale curve, the fitting function value of the coordinate data is calculated based on the fitting coefficients. Finally, the first image is fitted based on the fitting function to generate a second image, thereby achieving smooth fitting of the grayscale curve, reducing the influence of noise, improving the stability and accuracy of the fitted curve, and facilitating subsequent data processing and correction, such as using the fitted curve to find outliers and remove outliers.
[0115] It should be noted that when solving for you and the function using the least squares method, you can use functions from the linear algebra library to solve for them; this embodiment does not impose any specific restrictions.
[0116] Please refer to Figure 6 , Figure 6This is a flowchart illustrating step S104 as provided in an embodiment of this application. In some embodiments, step S104 may include, but is not limited to, steps S601 and S604.
[0117] Step S601: Binarize the first image and the second image based on the threshold segmentation algorithm to obtain the third image and the fourth image;
[0118] Step S602: Subtract the third image from the fourth image to obtain a grayscale difference image;
[0119] Step S603: For each pixel in the gray-level difference image, compare the gray-level difference of the pixel with a preset gray-level threshold to obtain a first gray-level set and a second gray-level set.
[0120] It should be noted that the grayscale difference of pixels in the first grayscale set is greater than the grayscale threshold, while the grayscale difference of pixels in the second grayscale set is less than or equal to the grayscale threshold.
[0121] Step S604: Extract features from the feature image based on the first grayscale set to obtain defect features.
[0122] In steps S601 to S604 of some embodiments, during the dynamic thresholding process of the first image and the second image, firstly, the first image and the second image are binarized based on a threshold segmentation algorithm to convert them into grayscale images, thereby reducing the data processing dimension and obtaining a third image and a fourth image. Then, the third image and the fourth image are subtracted to obtain a grayscale difference image, which facilitates the observation and analysis of the defect area. Afterwards, for each pixel in the grayscale difference image, the grayscale difference of the pixel is compared with a preset grayscale threshold. Pixels with grayscale differences greater than the grayscale threshold are grouped into a first grayscale set, and pixels with grayscale differences less than or equal to the grayscale threshold are grouped into a second grayscale set. Finally, feature extraction is performed on the feature image based on the first grayscale set to obtain defect features, thereby achieving accurate extraction of defect features.
[0123] Please refer to Figure 7 , Figure 7 This is a flowchart illustrating step S403 as provided in an embodiment of this application. In some embodiments, step S403 includes, but is not limited to, steps S701 and S704.
[0124] Step S701: Traverse all pixels in the first image based on a preset nested loop sequence to obtain the grayscale value of each pixel;
[0125] Step S702: Create a curve template chart, and use the column index data as the horizontal axis of the curve template chart and the grayscale value data as the vertical axis of the curve template chart;
[0126] Step S703: Summarize the gray values of all pixels to generate multiple coordinate data;
[0127] Step S704: On the curve template, mark and connect all coordinate data to generate a grayscale curve.
[0128] In steps S701 to S704 of some embodiments, during the process of generating the grayscale curve, firstly, all pixels in the first image are traversed based on a preset nested loop sequence to obtain the grayscale values of the pixels in the first image. Then, a curve template image is created, wherein the horizontal axis of the curve template image is column index data and the vertical axis is grayscale value data, which facilitates the subsequent analysis of the grayscale values of the pixels in the first image. After that, the grayscale values of all pixels are summarized to generate multiple coordinate data. Finally, all coordinate data are labeled and connected on the curve template image to generate a grayscale curve image, thereby clearly displaying the grayscale values of the pixels in the first image.
[0129] It should be noted that the loop direction of the nested loop sequence can be from top to bottom, from left to right, or from top to bottom, from right to left, etc., so as to traverse all pixels in the first image. This embodiment does not impose specific restrictions on the setting of the loop direction.
[0130] Understandably, during the creation of the curve template image, an empty list also needs to be created to store the grayscale value of each pixel. The row and column of each pixel are traversed through a nested loop sequence, and the grayscale value of the row and column is added to the empty list. After the inner loop of the nested loop ends, the grayscale value of the row is added to a two-dimensional list to represent the grayscale value summarized by row, thus completing the collection of grayscale values.
[0131] Please refer to Figure 8 , Figure 8 This is a flowchart illustrating step S402 as provided in an embodiment of this application. In some embodiments, step S402 includes, but is not limited to, steps S801 and S804.
[0132] Step S801: Adjust the size of the smoothed feature image;
[0133] In some embodiments, the smoothed feature image is resized by padding it with zeros to a suitable size, thereby facilitating the subsequent execution of the Fast Fourier Transform algorithm.
[0134] It should be noted that before resizing the smoothed feature image, it is necessary to perform zero-mean normalization on the feature image to remove the influence of the DC component.
[0135] Understandably, to perform a Fast Fourier Transform, the image size typically needs to be resized to a power of 2. Specifically, zero-value pixels can be added around the image to expand the image size to the smallest power of 2 side length.
[0136] Step S802: Perform frequency analysis on the size-adjusted feature image based on the Fast Fourier Transform algorithm to determine the first amplitude value and the second amplitude value in the feature image.
[0137] In some embodiments, frequency analysis is performed on the size-adjusted feature image based on the Fast Fourier Transform algorithm to convert the feature image from the time domain to the frequency domain, and to determine the first amplitude value and the second amplitude value in the feature image. The first amplitude value is the strong frequency component in the image, i.e., the high amplitude part, and the second amplitude value is the weak frequency component in the image, i.e., the low amplitude part. This allows for the observation of different frequency components in the image and an understanding of the intensity and distribution of each frequency component in the feature image.
[0138] Step S803: Filter the first amplitude value and the second amplitude value using a Gaussian filter to obtain the target spectrum;
[0139] In some embodiments, the first amplitude value and the second amplitude value are convolved by a Gaussian filter to obtain the target spectrum, which facilitates subsequent screening of the target spectrum.
[0140] Step S804: Perform an inverse Fourier transform on the target spectrum, and perform frequency filtering on the target spectrum after the inverse Fourier transform according to a Gaussian filter to obtain the first image.
[0141] In some embodiments, an inverse Fourier transform is performed on the target spectrum, the convolution result is converted back to spatial AND, the frequency domain image is converted back to spatial domain image, and the target spectrum after inverse Fourier transform is frequency filtered according to a Gaussian filter to retain low-frequency components and filter high-frequency components, thereby obtaining a smooth first image, making the smoothing effect of the image more natural, better preserving the edge information in the image, and improving the processing speed.
[0142] Please see Figure 9 This application also provides a defect detection device that can implement the above-described defect detection method. The device includes:
[0143] The grayscale enhancement module 901 is used to perform grayscale enhancement operations on the acquired image to be processed to obtain a feature image, wherein the image to be processed is obtained by image acquisition of the product to be tested;
[0144] The frequency conversion module 902 is used to perform frequency conversion on the feature image based on a preset fast Fourier algorithm to generate a first image and a grayscale curve corresponding to the first image.
[0145] The smoothing fitting module 903 is used to perform a smoothing fitting operation on the degree curve to generate a second image;
[0146] The defect determination module 904 is used to perform dynamic thresholding on the first image and the second image based on a preset threshold segmentation algorithm to determine defect features.
[0147] The defect detection device in this application embodiment is used to execute the defect detection method in the above embodiment. Its specific processing procedure is the same as the defect detection method in the above embodiment, and will not be described in detail here.
[0148] To illustrate the defect detection method described above more clearly, a specific example is provided below.
[0149] Example 1:
[0150] Example 1 illustrates the specific process for defect detection of the battery cell under test, including the following steps:
[0151] Step 1: Illuminate the entire area of the battery cell under test to trigger the image acquisition device to take a picture of the product under test and obtain the image to be processed;
[0152] Step 2: Perform background segmentation on the image to be processed, and then perform mean filtering on the image after background segmentation to obtain the filtered image;
[0153] Reference Figure 10 , Figure 10 This is a schematic diagram of the feature image provided in the example of this application.
[0154] Step 3: Perform grayscale enhancement on the filtered image to highlight the stain features and obtain the feature image;
[0155] It should be noted that the feature image includes feature region 100 and background region 200.
[0156] Step 4: Perform frequency conversion on the feature image based on the preset Fast Fourier Transform algorithm to generate the first image and the corresponding grayscale curve.
[0157] Step 5: Perform a smoothing fitting operation on the grayscale curve image based on the least squares method to generate the second image;
[0158] Reference Figure 11 , Figure 11 This is a schematic diagram of the defect features in the feature image provided in the example of this application.
[0159] Step 6: Perform dynamic thresholding on the first and second images based on a preset threshold segmentation algorithm to determine defect features 110.
[0160] Understandable Figure 11 The defect feature 110 is located in the feature region 100.
[0161] Reference Figure 12 , Figure 12 This is a schematic diagram of the hardware structure of the computer device provided in the embodiments of this application.
[0162] The following is combined Figure 10 The hardware structure of the computer device is described in detail. The computer device includes: a processor 1001, a memory 1002, an input / output interface 1003, a communication interface 1004, and a bus 1005.
[0163] The processor 1001 can be implemented using a general-purpose CPU (Central Processing Unit), microprocessor, application-specific integrated circuit (ASIC), or one or more integrated circuits, and is used to execute relevant programs to implement the technical solutions provided in the embodiments of this application.
[0164] The memory 1002 can be implemented as a read-only memory (ROM), static storage device, dynamic storage device, or random access memory (RAM). The memory 1002 can store the operating system and other applications. When the technical solutions provided in the embodiments of this specification are implemented through software or firmware, the relevant program code is stored in the memory 1002 and is called and executed by the processor 1001 using the defect detection method of the embodiments of this application.
[0165] Input / output interface 1003 is used to implement information input and output;
[0166] The communication interface 1004 is used to enable communication and interaction between this device and other devices. Communication can be achieved through wired means (such as USB, network cable, etc.) or wireless means (such as mobile network, WIFI, Bluetooth, etc.); and the bus 1005 is used to transmit information between the various components of the device (such as processor 1001, memory 1002, input / output interface 1003 and communication interface 1004).
[0167] The processor 1001, memory 1002, input / output interface 1003 and communication interface 1004 are connected to each other within the device via bus 1005.
[0168] This application also provides a storage medium, which is a computer-readable storage medium storing a computer program. When the computer program is executed by a computer, the computer is used to perform the defect detection method as described in the above embodiments of this application.
[0169] Memory, as a non-transitory computer-readable storage medium, can be used to store non-transitory software programs and non-transitory computer-executable programs. Furthermore, memory may include high-speed random access memory, and may also include non-transitory memory, such as at least one disk storage device, flash memory device, or other non-transitory solid-state storage device. In some embodiments, memory may optionally include memory remotely located relative to the processor, and these remote memories can be connected to the processor via a network. Examples of such networks include, but are not limited to, the Internet, intranets, local area networks, mobile communication networks, and combinations thereof.
[0170] The embodiments described in this application are for the purpose of more clearly illustrating the technical solutions of the embodiments of this application, and do not constitute a limitation on the technical solutions provided by the embodiments of this application. As those skilled in the art will know, with the evolution of technology and the emergence of new application scenarios, the technical solutions provided by the embodiments of this application are also applicable to similar technical problems.
[0171] It will be understood by those skilled in the art that Figures 1 to 8 The technical solutions shown do not constitute a limitation on the embodiments of this application, and may include more or fewer steps than shown, or combine certain steps, or different steps.
[0172] The device embodiments described above are merely illustrative. The units described as separate components may or may not be physically separate; 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 according to actual needs.
[0173] Those skilled in the art will understand that all or some of the steps in the methods disclosed above, as well as the functional modules / units in the systems and devices, can be implemented as software, firmware, hardware, or suitable combinations thereof.
[0174] The terms “first,” “second,” “third,” “fourth,” etc. (if present) in the specification and accompanying drawings of this application are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate so that the embodiments of this application described herein can be implemented in orders other than those illustrated or described herein. Furthermore, the terms “comprising” and “having,” and any variations thereof, are intended to cover non-exclusive inclusion; for example, a process, method, system, product, or apparatus that comprises a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units not explicitly listed or inherent to such processes, methods, products, or apparatus.
[0175] It should be understood that in this application, "at least one (item)" means one or more, and "more than" means two or more. "And / or" is used to describe the relationship between related objects, indicating that three relationships can exist. For example, "A and / or B" can represent three cases: only A exists, only B exists, and both A and B exist simultaneously, where A and B can be singular or plural. The character " / " generally indicates that the preceding and following related objects are in an "or" relationship. "At least one (item) of the following" or similar expressions refer to any combination of these items, including any combination of single or plural items. For example, at least one (item) of a, b, or c can represent: a, b, c, "a and b", "a and c", "b and c", or "a and b and c", where a, b, and c can be single or multiple.
[0176] In the several embodiments provided in this application, it should be understood that the disclosed apparatus and methods can be implemented in other ways. For example, the apparatus embodiments described above are merely illustrative; for instance, the division of units is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the coupling or direct coupling or communication connection shown or discussed may be through some interfaces; the indirect coupling or communication connection between apparatuses or units may be electrical, mechanical, or other forms.
[0177] The units described as separate components may or may not be physically separate. The components shown as units 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 units can be selected to achieve the purpose of this embodiment according to actual needs.
[0178] Furthermore, the functional units in the various embodiments of this application 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 as a software functional unit.
[0179] If the integrated unit is implemented as a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, or all or part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes multiple instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods of the various embodiments of this application. The aforementioned storage medium includes various media capable of storing programs, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.
[0180] The preferred embodiments of the present application have been described above with reference to the accompanying drawings, but this does not limit the scope of the claims of the present application. Any modifications, equivalent substitutions, and improvements made by those skilled in the art without departing from the scope and substance of the embodiments of the present application shall be within the scope of the claims of the present application.
Claims
1. A defect detection method, characterized in that, The method includes: A grayscale enhancement operation is performed on the acquired image to be processed to obtain a feature image, wherein the image to be processed is obtained by image acquisition of the product to be tested; The feature image is frequency-converted based on a preset fast Fourier transform algorithm to generate a first image and a grayscale curve corresponding to the first image. A smoothing fitting operation is performed on the grayscale curve to generate a second image; Dynamic thresholding is performed on the first image and the second image based on a preset threshold segmentation algorithm to determine defect features; The step of performing frequency conversion on the feature image based on a preset Fast Fourier Transform algorithm to generate a first image and a grayscale curve corresponding to the first image includes: The feature image is smoothed by using a preset Gaussian filter; The first image is obtained by performing spectral analysis on the smoothed feature image based on the preset fast Fourier algorithm and the Gaussian filter. Traverse all pixels in the first image to generate a grayscale curve corresponding to the first image; The method of performing dynamic thresholding on the first image and the second image based on a preset threshold segmentation algorithm to determine defect features includes: The first and second images are binarized using a threshold segmentation algorithm to obtain the third and fourth images. Subtract the third image from the fourth image to obtain a grayscale difference image; For each pixel in the grayscale difference image, the grayscale difference of the pixel is compared with a preset grayscale threshold to obtain a first grayscale set and a second grayscale set, wherein the grayscale difference of the pixels in the first grayscale set is greater than the grayscale threshold, and the grayscale difference of the pixels in the second grayscale set is less than or equal to the grayscale threshold. Based on the first grayscale set, feature extraction is performed on the feature image to obtain defect features.
2. The defect detection method according to claim 1, characterized in that, The step of performing grayscale enhancement on the acquired image to be processed to obtain a feature image includes: The image to be processed is segmented based on the preset maximum inter-class variance method to obtain the background region and the region of interest, wherein the region of interest includes the feature region; The region of interest is subjected to mean filtering to obtain a filtered image; The grayscale value of the filtered image is calculated to distinguish the feature region from the background region, resulting in a feature image showing the feature region.
3. The defect detection method according to claim 2, characterized in that, The step of calculating the grayscale value of the filtered image to distinguish the feature region from the background region, and obtaining a feature image showing the feature region, includes: Calculate the grayscale value of the filtered image to obtain the first grayscale value and the second grayscale value of the filtered image; The amplification factor and the deviation value are determined based on the first gray value and the second gray value; The brightness of the filtered image is adjusted based on the magnification factor and the deviation value to obtain the feature image.
4. The defect detection method according to claim 1, characterized in that, The step of smoothing and fitting the grayscale curve to generate the second image includes: Create a fitting function based on the grayscale curve; The fitting function is solved using the least squares method to obtain the fitting coefficients; For each coordinate data in the grayscale curve, the fitting function value of the coordinate data is calculated based on the fitting coefficient; The first image is fitted based on the fitting function value to generate the second image.
5. The defect detection method according to claim 1, characterized in that, The step of traversing all pixels in the first image to generate a grayscale curve corresponding to the first image includes: The grayscale value of each pixel is obtained by traversing all pixels in the first image based on a preset nested loop sequence. Create a curve template chart, and use the column index data as the horizontal axis of the curve template chart and the grayscale value data as the vertical axis of the curve template chart; The grayscale values of all the aforementioned pixels are summarized to generate multiple coordinate data; On the curve template, all the coordinate data are labeled and connected to generate a grayscale curve.
6. The defect detection method according to claim 1, characterized in that, The first image is obtained by performing spectral analysis on the smoothed feature image based on the preset Fast Fourier Transform algorithm and the Gaussian filter, including: The size of the smoothed feature image is adjusted. Based on the Fast Fourier Transform algorithm, frequency analysis is performed on the size-adjusted feature image to determine the first amplitude value and the second amplitude value in the feature image; The target spectrum is obtained by filtering the first amplitude value and the second amplitude value using the Gaussian filter. The target spectrum is subjected to an inverse Fourier transform, and the target spectrum after the inverse Fourier transform is frequency filtered according to the Gaussian filter to obtain a first image.
7. A defect detection device, characterized in that, The device includes: The grayscale enhancement module is used to perform grayscale enhancement operations on the acquired image to be processed to obtain a feature image, wherein the image to be processed is obtained by image acquisition of the product to be tested; A frequency conversion module is used to perform frequency conversion on the feature image based on a preset Fast Fourier Transform algorithm to generate a first image and a grayscale curve corresponding to the first image; including: The feature image is smoothed by using a preset Gaussian filter; The first image is obtained by performing spectral analysis on the smoothed feature image based on the preset fast Fourier algorithm and the Gaussian filter. Traverse all pixels in the first image to generate a grayscale curve corresponding to the first image; The smoothing fitting module is used to perform a smoothing fitting operation on the grayscale curve to generate a second image. The defect determination module is used to perform dynamic thresholding on the first image and the second image based on a preset threshold segmentation algorithm to determine defect features; including: The first and second images are binarized using a threshold segmentation algorithm to obtain the third and fourth images. Subtract the third image from the fourth image to obtain a grayscale difference image; For each pixel in the grayscale difference image, the grayscale difference of the pixel is compared with a preset grayscale threshold to obtain a first grayscale set and a second grayscale set, wherein the grayscale difference of the pixels in the first grayscale set is greater than the grayscale threshold, and the grayscale difference of the pixels in the second grayscale set is less than or equal to the grayscale threshold. Based on the first grayscale set, feature extraction is performed on the feature image to obtain defect features.
8. A storage medium, characterized in that, The storage medium is a computer-readable storage medium, characterized in that the computer-readable storage medium stores a computer program, and when the computer program is executed by a computer, the computer is used to perform the defect detection method as described in any one of claims 1 to 6.
Citation Information
Patent Citations
Steel plate surface defect management and control method and device and computer readable storage medium
CN113808087A
Product edge appearance defect detection method and device, medium and equipment
CN115641332A