Image gray processing method and device, computer equipment and storage medium

Through the depth segmentation model and image processing technology based on the multi-head attention mechanism, the problem of inaccurate acquisition of grayscale information in complex surface defects is solved, and the grayscale information extraction with higher accuracy and conforming to the human eye observation characteristics is achieved.

CN119693473APending Publication Date: 2025-03-25SHANGHAI SMARTMORE TECH CO LTD
View PDF 0 Cites 2 Cited by

Patent Information

Application Number
CN202411766143.3
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-12-03
Publication Date
2025-03-25

AI Technical Summary

Technical Problem

In the quality inspection of plastic headphone housing, accurate extraction of defect grayscale information of complex curved surfaces faces technical difficulties, resulting in inaccurate acquisition of grayscale information.

Method used

The original image is processed using a deep segmentation model based on the multi-head attention mechanism, the defect information is output and the original defect mask is determined. By expanding and optimizing the processing mask, the background and defective images are extracted, and the defective images are normalized using the grayscale information of the background image to extract the target grayscale information.

Benefits of technology

The accuracy of defect grayscale information of complex surfaces is improved, so that the extracted grayscale information is more in line with the human eye observation characteristics, and the dependence on the accuracy error of the defect detection model is reduced, thereby achieving higher precision grayscale information acquisition.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119693473A_ABST
    Figure CN119693473A_ABST
Patent Text Reader

Abstract

The invention relates to an image gray processing method and device, computer equipment and a storage medium. The method comprises the following steps: inputting a to-be-detected original image into a depth segmentation model based on a multi-head attention mechanism for processing, and outputting defect information; determining an original defect mask according to the defect information; performing expansion treatment on the original defect mask to obtain an expanded defect mask; determining a background mask according to the expanded defect mask and the original defect mask; performing edge optimization processing on the original defect mask through a caliper tool to obtain an optimized defect mask; according to the background mask and the optimized defect mask, extracting a background image and a defect image from the to-be-detected original image; and according to the gray information of the background image, carrying out normalization processing on the gray information of the defect image, and extracting target gray information from the defect image after normalization processing. By adopting the method and the device, the accuracy of obtaining the gray information of the defects of the complex curved surface can be improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the technical field of industrial defect detection, and in particular to an image grayscale processing method, device, computer equipment and storage medium. Background Art

[0002] Intelligence and automation have become new development trends in the manufacturing industry, and plastic industrial products are ideal practice objects. In the production process of plastic earphone shells, appearance quality inspection is crucial. In the process of appearance quality inspection of plastic earphone shells, it is necessary to make acceptance judgments on the detected defects to determine whether the defects of the plastic earphone shells are within an acceptable range. In this process, an important basis for judging the acceptance of defects is the grayscale information of the defects.

[0003] However, in the quality inspection of plastic earphone shells, there are many technical difficulties in accurately extracting the grayscale information of defects, making how to accurately obtain the grayscale information of defects on complex surfaces a technical problem that needs to be solved urgently. Summary of the invention

[0004] Based on this, it is necessary to provide an image grayscale processing method, device, computer equipment, computer readable storage medium and computer program product to address the above technical problems, which can improve the accuracy of grayscale information of defects on complex surfaces.

[0005] In a first aspect, the present application provides an image grayscale processing method, comprising:

[0006] The original image to be detected is input into the deep segmentation model based on the multi-head attention mechanism for processing, and the defect information is output; the original defect mask is determined according to the defect information;

[0007] Performing expansion processing on the original defect mask to obtain an expanded defect mask;

[0008] Determine a background mask according to the expanded defect mask and the original defect mask;

[0009] Using a caliper tool, edge optimization processing is performed on the original defect mask to obtain an optimized defect mask;

[0010] Extracting a background image and a defect image from the original image to be detected according to the background mask and the optimized defect mask;

[0011] According to the grayscale information of the background image, the grayscale information of the defect image is normalized, and the target grayscale information is extracted from the normalized defect image.

[0012] In a second aspect, the present application provides an image grayscale processing device, comprising:

[0013] A processing module is used to input the original image to be detected into a deep segmentation model based on a multi-head attention mechanism for processing, and output defect information; and determine the original defect mask according to the defect information;

[0014] An expansion module, used for performing expansion processing on the original defect mask to obtain an expanded defect mask;

[0015] A mask determination module, used for determining a background mask according to the expanded defect mask and the original defect mask;

[0016] The edge optimization module is used to perform edge optimization processing on the original defect mask through a caliper tool to obtain an optimized defect mask; the image extraction module is used to extract the background image and the defect image from the original image to be detected according to the background mask and the optimized defect mask;

[0017] The grayscale extraction module is used to normalize the grayscale information of the defect image according to the grayscale information of the background image, and extract the target grayscale information from the normalized defect image.

[0018] In a third aspect, the present application provides a computer device, the computer device comprising a memory and a processor, the memory storing a computer program, and the processor implementing the steps in the above method when executing the computer program.

[0019] In a fourth aspect, the present application provides a computer-readable storage medium having a computer program stored thereon, which implements the steps in the above method when executed by a processor.

[0020] In a fifth aspect, the present application provides a computer program product, which includes a computer program, and the computer program implements the steps in the above method when executed by a processor.

[0021] The above-mentioned image grayscale processing method, device, computer equipment, computer-readable storage medium and computer program product comprehensively consider the grayscale information of the defect and its surrounding background, and use the background information around the defect to normalize the defect, so that the extracted defect grayscale information is more accurate and more in line with the observation characteristics of the human eye; and the edge of the defect mask is optimized and modified by the caliper tool, so that the grayscale extraction method of the present application does not rely on the accuracy error of the defect detection model, and thus can obtain higher-precision grayscale information. BRIEF DESCRIPTION OF THE DRAWINGS

[0022] Figure 1 An application environment diagram of an image grayscale processing method provided in an embodiment of the present application;

[0023] Figure 2 A schematic diagram of a process flow of an image grayscale processing method provided in an embodiment of the present application;

[0024] Figure 3 A structural block diagram of an image grayscale processing device provided in an embodiment of the present application;

[0025] Figure 4 An internal structure diagram of a computer device provided in an embodiment of the present application;

[0026] Figure 5 An internal structure diagram of another computer device provided in an embodiment of the present application;

[0027] Figure 6 An internal structure diagram of a computer-readable storage medium provided in an embodiment of the present application. DETAILED DESCRIPTION

[0028] In order to make the purpose, technical solution and advantages of the present application more clearly understood, the present application is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.

[0029] The image grayscale processing method provided in the embodiment of the present application can be applied to Figure 1 In the application environment shown. Among them, the terminal 102 communicates with the server 104 through a communication network. The data storage system can store the data that the server 104 needs to process. The data storage system can be integrated on the server 104, or it can be placed on the cloud or other network servers. Among them, the terminal 102 can be but is not limited to various personal computers, laptops, smart phones, tablets, Internet of Things devices and portable wearable devices. The Internet of Things devices can be smart speakers, smart TVs, smart air conditioners, smart car-mounted devices, image acquisition devices, etc. Portable wearable devices can be smart watches, smart bracelets, head-mounted devices, etc. The server 104 can be implemented with an independent server or a server cluster consisting of multiple servers.

[0030] like Figure 2 As shown, the embodiment of the present application provides an image grayscale processing method, which is applied to Figure 1 The terminal 102 or the server 104 in the example is used for explanation. It is understandable that the computer device may include at least one of the terminal and the server. The method comprises the following steps:

[0031] S201. Input the original image to be detected into a deep segmentation model based on a multi-head attention mechanism for processing, and output defect information; determine the original defect mask based on the defect information.

[0032] The original image to be detected is an image collected from a curved material with a complex curved surface. For example, the original image to be detected is an image collected from an earphone shell, which is a plastic part. In addition, the original image to be detected can also be an image collected from a flat material, which is not specifically limited here.

[0033] In an embodiment of the present application, a deep segmentation model based on a multi-head attention mechanism is a pre-trained defect detection model used to identify defect information and positioning information from an original image to be detected; wherein the positioning information is used to describe the area where the defect is located in a curved material or a flat material.

[0034] In the embodiment of the present application, when performing defect detection, the original image to be detected can be input into the deep segmentation model based on the multi-head attention mechanism for processing, and the defect information can be output; wherein the defect information can include the defect type and the original defect mask, which is an image representation form used to identify the defect area, and records the location, shape, area and other information of the defect. Then, the original defect mask can be directly determined based on the defect information.

[0035] In the embodiment of the present application, after the original defect mask is determined according to the defect information, the original defect mask can be processed concurrently through step S202 and step S204.

[0036] S202, dilating the original defect mask to obtain an expanded defect mask.

[0037] In the embodiment of the present application, the expansion process of the original defect mask will cause the foreground area representing the defect area in the original defect mask to expand outward. In this process, the expanded area not only includes the original defect area, but also occupies a part of the surrounding background area. This is because expansion is a morphological operation performed on the image based on the structural element. When the structural element traverses the image, any part that intersects with the area covered by the structural element will be marked as the foreground.

[0038] In the embodiment of the present application, the process of dilating the original defect mask is as follows: first, a suitable structural element is selected, and the shape of the structural element can be circular, square, etc. For example, a 3x3 or 5x5 square structural element can be selected. Further, each pixel in the original defect mask is traversed. For each pixel point, the area covered by the structural element is considered with the pixel as the center. If any pixel in the area covered by the structural element is a defective pixel (usually represented as a specific value in the original defect mask, such as a pixel with a value of 1), then the current center pixel is marked as a defective pixel. In other words, as long as the structural element and the defective area have an intersection, the center pixel is included in the expanded defective area. After traversing all pixels, the new defect mask obtained is the expanded defective mask. It can be understood that, assuming that there is a small defective area in the original defective mask, after the expansion process, the defective area will become larger, and some surrounding pixels that were originally uncertain whether they were defects are also included in the defective area. That is, the defective area in the expanded defective mask is larger than the defective area in the original defective mask.

[0039] S203: Determine a background mask according to the expanded defect mask and the original defect mask.

[0040] In an embodiment of the present application, the background mask can be obtained by subtracting the original defect mask from the expanded defect mask. It can be understood that when the original defect mask before expansion is subtracted from the expanded defect mask, the original defect area itself is actually removed, leaving only the part newly included due to expansion. And this part of the newly included area is exactly the part that originally belonged to the background around the defect but was mistakenly marked as a foreground defect during the expansion process. Therefore, after such an operation, the background mask of the defect is obtained, which accurately identifies the background area around the defect, and provides key information for subsequent operations such as extracting the background image and normalizing the defect image.

[0041] S204 , performing edge optimization processing on the original defect mask by using a caliper tool to obtain an optimized defect mask.

[0042] In the embodiment of the present application, the caliper tool is creatively used to perform edge detection using the pixel value of the image itself. Therefore, the process of edge optimization processing of the original defect mask by the caliper tool is as follows: the caliper tool analyzes the pixels in the original defect mask point by point to redefine the edge of the defect. Specifically, first determine an initial detection point (which can be any pixel point in the original defect mask), and analyze pixel by pixel starting from the initial detection point. At each pixel point, the caliper tool checks the pixel value relationship between the pixel and its surrounding pixels. When it is found that the pixel value has changed significantly (for example, the pixel value change exceeds the change threshold set by the caliper tool), it is judged that this may be the edge of the defect. For example, if the brightness value of a pixel is significantly different from the surrounding pixels, the caliper tool will mark this pixel as a potential edge point. By performing the above analysis on the entire original defect mask, the caliper tool can outline the edge contour of the defect.

[0043] It should be noted that the pixel values ​​at the junction of the defect area and the background area often change significantly. This is because the defect usually has characteristics such as color, brightness or texture that are different from the background, and these characteristics will be reflected in the pixel value. When the caliper tool detects a sudden change in the pixel value, it will determine that this may be the edge of the defect.

[0044] It is understandable that by using the caliper tool to optimize the edge of the original defect mask, the marked defect area can be made more accurate, and the problem of inaccurate defect areas in the original defect mask output due to precision problems of the deep segmentation model based on the multi-head attention mechanism can be avoided. That is, by using the caliper tool to optimize the edge of the original defect mask, it can be ensured that the defect areas in the optimized defect mask are more accurate. S205. Extract the background image and the defect image from the original image to be detected according to the background mask and the optimized defect mask.

[0045] In the embodiment of the present application, the process of determining the background image may include: traversing the original image to be detected pixel by pixel, for each pixel in the original image to be detected, if the corresponding pixel in the background mask is marked as a background area, then copying the value of the pixel to a new image, and the new image is the extracted background image. If the corresponding pixel in the background mask is not a background area, a default value may be set at the corresponding position in the new image, and the default value may be a pre-specified non-background color.

[0046] In the embodiment of the present application, the process of determining the defect image may include: traversing the original image to be detected pixel by pixel, for each pixel in the original image to be detected, if the corresponding pixel in the optimized defect mask is marked as a defect area, then copying the value of the pixel to another new image, and the new image is the extracted defect image. If the corresponding pixel in the optimized defect mask is not a defect area, the corresponding position in the new image can be set to a default value (such as black or other colors indicating non-defects).

[0047] S206 , normalizing the grayscale information of the defect image according to the grayscale information of the background image, and extracting target grayscale information from the normalized defect image.

[0048] In the embodiment of the present application, the normalization process may include: first, analyzing the grayscale information of each pixel in the background image, calculating the grayscale mean, standard deviation and other statistical information of the background image, and these statistical information will be used as a reference for subsequent normalization. Further, determine the normalization formula, for example, the normalization formula adopts a linear normalization formula, so that the normalized value = (defective image pixel grayscale value - background image grayscale mean) / background image grayscale standard deviation. Further, traverse each pixel in the defective image one by one. For each pixel, according to the determined normalization formula, the reference information (such as grayscale mean and standard deviation) in the background image corresponding to the pixel is used for calculation. The calculated normalized value is used as the new grayscale value of the pixel, and the corresponding pixel in the defective image is updated. After processing all pixels, a defective image after normalization is obtained. It can be understood that through the above-mentioned normalization operation, the grayscale value of the defective image can be standardized to a certain extent, eliminating the influence of factors such as different lighting on the grayscale value, which is more conducive to the subsequent defect analysis and acceptance judgment based on grayscale information.

[0049] When extracting target grayscale information from the normalized defect image, each pixel in the normalized defect image can be traversed row by row and column by column. For each pixel, its grayscale value is read and recorded to obtain the target grayscale information. In addition, statistical operations can be performed on the extracted grayscale values, such as calculating the sum, mean, median, etc. of the grayscale values, and the statistical operation results are used as the target grayscale information. It should be noted that the target grayscale information extracted by the present application is essentially the relative grayscale information of the defect relative to its surrounding background, which conforms to the observation characteristics of the human eye, and this information can be used to make the next step of defect acceptance rule judgment.

[0050] The embodiment of the present application takes into account the grayscale information of the defect and its surrounding background, and uses the background information around the defect to normalize the defect, so that the extracted defect grayscale information is more consistent with the observation characteristics of the human eye; and the edge of the defect mask is optimized and modified by a caliper tool, so that the grayscale extraction method of the present application does not rely on the accuracy error of the defect detection model, and thus can obtain higher-precision grayscale information.

[0051] In some embodiments, after determining the original defect mask according to the defect information, the method further includes:

[0052] Determine the coordinate information of the region of interest according to the edge coordinates of the defect in the original defect mask and a preset compensation threshold;

[0053] The original defect mask is expanded to obtain an expanded defect mask, including:

[0054] According to the coordinate information of the region of interest, a defect mask of the region of interest ROI is extracted from the original defect mask;

[0055] The ROI defect mask is expanded to obtain an expanded defect mask.

[0056] Specifically, the edge coordinates of the defect in the original defect mask can be the coordinates of the upper left corner of the defect and the coordinates of the lower right corner of the defect, and the preset compensation threshold is 10 pixels. Subtract 10 from the two values ​​of the coordinates of the upper left corner of the defect, and add 10 to the two values ​​of the coordinates of the lower right corner of the defect, so that the adjusted coordinates of the upper left corner of the defect and the adjusted coordinates of the lower right corner of the defect can be used as the coordinate information of the region of interest (i.e., ROI region).

[0057] After obtaining the coordinate information of the region of interest, start traversing each pixel in the original defect mask. For each pixel point traversed, check whether its position in the original image to be detected is within the region of interest. If the position of a pixel in the original image to be detected is within the region of interest, record the pixel and record whether the pixel is marked as a defective pixel in the original defect mask. Create a new blank mask image based on the coordinate information of the region of interest. According to whether the recorded pixels in the region of interest are defective pixels, mark the corresponding positions in the newly created mask image accordingly to obtain the ROI defect mask.

[0058] In the embodiment of the present application, the process of dilating the ROI defect mask is similar to the process of dilating the original defect mask described above, and will not be repeated here.

[0059] It should be noted that, since the naked eye only observes the surroundings of a defect and does not observe the entire image, this application introduces a region of interest (i.e., a small area including the defect), and determines the region of interest ROI defect mask based on the coordinate information of the region of interest, so that the size of the ROI defect mask is smaller than the original defect mask. In this way, the ROI defect mask is expanded, which can reduce the amount of calculation compared to directly expanding the entire original defect mask, thereby improving the overall grayscale information extraction efficiency.

[0060] In some embodiments, determining a background mask according to the expanded defect mask and the original defect mask includes:

[0061] The background mask is obtained by subtracting the ROI defect mask from the dilated defect mask.

[0062] It is understandable that since the expanded defect mask is obtained based on the ROI defect mask, the expanded defect mask can be directly subtracted from the ROI defect mask to obtain the background mask. When the expanded defect mask is subtracted from the ROI defect mask, the original defect area itself is actually removed, leaving only the part newly included due to expansion. This newly included area is exactly the part that originally belonged to the background around the defect but was mistakenly marked as a foreground defect during the expansion process. Therefore, after such an operation, the background mask of the defect is obtained, which accurately identifies the background area around the defect, and provides key information for subsequent operations such as extracting the background image and normalizing the defect image.

[0063] In some embodiments, edge optimization processing is performed on the original defect mask by using a caliper tool to obtain an optimized defect mask, including:

[0064] According to the coordinate information of the region of interest, a defect mask of the region of interest ROI is extracted from the original defect mask;

[0065] The ROI defect mask is edge optimized by using a caliper tool to obtain an optimized defect mask.

[0066] Specifically, the process of extracting the ROI defect mask from the original defect mask according to the coordinate information of the ROI can be referred to the above description, which will not be repeated here. The process of edge optimization of the ROI defect mask by the caliper tool is similar to the process of directly optimizing the edge of the original defect mask by the caliper tool, which will not be repeated here.

[0067] It can be understood that after obtaining the ROI defect mask, edge optimization processing is performed on the ROI defect mask through a caliper tool. Compared with directly performing edge optimization processing on the original defect mask, this can reduce the amount of calculation and improve the efficiency of extracting the overall grayscale information.

[0068] In some embodiments, extracting a background image and a defect image from an original image to be detected according to the background mask and the optimized defect mask includes:

[0069] According to the coordinate information of the region of interest, the ROI image to be detected is extracted from the original image to be detected;

[0070] According to the background mask and the optimized defect mask, the background image and the defect image are extracted from the ROI image to be detected.

[0071] Specifically, the original image to be detected is traversed pixel by pixel, and for each pixel in the original image to be detected, its coordinates are checked to see if they are within the region of interest. If the coordinates of a pixel are within the region of interest, the value of the pixel is copied to the new image; if not, the pixel is ignored. After processing all pixels, the new image obtained is the ROI image to be detected. It can be understood that the ROI image to be detected is an image that includes the defect area and is smaller in size than the original image to be detected.

[0072] After obtaining the ROI image to be detected, the background image and defect image are extracted from the ROI image to be detected according to the background mask and the optimized defect mask. The specific extraction process is similar to the process of extracting the background image and defect image from the original image to be detected, and will not be repeated here. It should be noted that extracting the background image and defect image from the ROI image to be detected can reduce the amount of calculation and improve the overall efficiency of obtaining grayscale information.

[0073] In some embodiments, the original image to be detected is an image captured from an earphone housing with a complex curved surface, and the earphone housing is a plastic part.

[0074] For a plastic earphone shell, due to its complex surface, in the same captured image, the visible plane area is brighter, the visible curved area is darker, and the intersection of the plane area and the curved area presents a gradient trend, that is, defects with the same grayscale value will present different grayscale characteristics in different areas, so that the extracted grayscale value will be affected by the surrounding background. In order to avoid this situation, the present application scheme, for the original image to be detected is an image of an earphone shell with a complex curved surface, comprehensively considers the grayscale information of the defect and its surroundings, and uses the background information around the defect to normalize the defect, so that the grayscale information subsequently extracted is actually the relative grayscale information of the defect relative to its surrounding background, thereby avoiding the extracted grayscale value from being affected by the surrounding environment.

[0075] In some embodiments, before extracting target grayscale information from the normalized defect image, the method further includes:

[0076] The original image to be inspected is input into the deep segmentation model based on the multi-head attention mechanism for processing, and the defect location information is output.

[0077] The defect location information is used to describe the area where the defect is located in the earphone shell.

[0078] After extracting target grayscale information from the normalized defect image, the method further includes:

[0079] According to the defect location information, determine the target area where the defect is located; wherein the target area is the charging pocket area of ​​the earphone housing (including the edge area of ​​the charging pocket and the inner area of ​​the charging pocket) or the material area (referring to the area where the plastic material constituting the main part of the earphone housing is located);

[0080] Determine the defect acceptance result according to the defect acceptance rules and target grayscale information corresponding to the target area.

[0081] In the embodiment of the present application, the same type of defect has different corresponding acceptance rules in different areas. For example, if the defect type is the crush area, the acceptance rule in the edge area of ​​the charging pocket is: the crush area is accepted if it is less than 0.005, otherwise it will be reported; the acceptance rule in the inner area of ​​the charging pocket is: the crush area is accepted if it is less than 0.01, otherwise it will be reported. In this way, after determining the acceptance rule of the charging pocket area where the defect is located, the crush area is calculated based on the extracted target grayscale information, and then it is determined whether the calculated crush area meets the corresponding defect acceptance rule to obtain the defect acceptance result.

[0082] It should be understood that, although the steps in the flowcharts involved in the above-mentioned embodiments are displayed in sequence according to the indications of the arrows, these steps are not necessarily executed in sequence according to the order indicated by the arrows. Unless there is a clear description in this article, there is no strict order restriction on the execution of these steps, and these steps can be executed in other orders. Moreover, at least a part of the steps in the flowcharts involved in the above-mentioned embodiments may include multiple steps or multiple stages, and these steps or stages are not necessarily executed at the same time, but can be executed at different times, and the execution order of these steps or stages is not necessarily to be carried out in sequence, but can be executed in turn or alternately with other steps or at least a part of the steps or stages in other steps.

[0083] Based on the same inventive concept, the embodiment of the present application also provides an image grayscale processing device. The implementation solution provided by the device to solve the problem is similar to the implementation solution recorded in the above method, so the specific limitations in one or more image grayscale processing device embodiments provided below can refer to the limitations of the image grayscale processing method above, and will not be repeated here.

[0084] like Figure 3 As shown, the embodiment of the present application provides an image grayscale processing device 300, including:

[0085] The processing module 301 is used to input the original image to be detected into the deep segmentation model based on the multi-head attention mechanism for processing, and output defect information; determine the original defect mask according to the defect information;

[0086] An expansion module 302 is used to expand the original defect mask to obtain an expanded defect mask;

[0087] The mask determination module 303 is used to determine the background mask according to the expanded defect mask and the original defect mask;

[0088] The edge optimization module 304 is used to perform edge optimization processing on the original defect mask by using a caliper tool to obtain an optimized defect mask;

[0089] An image extraction module 305 is used to extract a background image and a defect image from an original image to be detected according to the background mask and the optimized defect mask;

[0090] The grayscale extraction module 306 is used to normalize the grayscale information of the defect image according to the grayscale information of the background image, and extract target grayscale information from the normalized defect image.

[0091] In some embodiments, the apparatus further comprises:

[0092] An area of ​​interest determination module, used to determine the coordinate information of the area of ​​interest according to the edge coordinates of the defect in the original defect mask and a preset compensation threshold;

[0093] Accordingly, in terms of performing expansion processing on the original defect mask to obtain the expanded defect mask, the expansion module 302 is specifically used for:

[0094] According to the coordinate information of the region of interest, a defect mask of the region of interest ROI is extracted from the original defect mask;

[0095] The ROI defect mask is expanded to obtain an expanded defect mask.

[0096] In some embodiments, in determining the background mask according to the expanded defect mask and the original defect mask, the mask determination module 303 is specifically configured to:

[0097] The background mask is obtained by subtracting the ROI defect mask from the dilated defect mask.

[0098] In some embodiments, in performing edge optimization processing on the original defect mask by using a caliper tool to obtain an optimized defect mask, the edge optimization module 304 is specifically used to:

[0099] According to the coordinate information of the region of interest, a defect mask of the region of interest ROI is extracted from the original defect mask;

[0100] The ROI defect mask is edge optimized by using a caliper tool to obtain an optimized defect mask.

[0101] In some embodiments, in extracting the background image and the defect image from the original image to be detected according to the background mask and the optimized defect mask, the image extraction module 305 is specifically used to:

[0102] According to the coordinate information of the region of interest, the ROI image to be detected is extracted from the original image to be detected;

[0103] According to the background mask and the optimized defect mask, the background image and the defect image are extracted from the ROI image to be detected.

[0104] In some embodiments, the original image to be detected is an image captured from an earphone housing with a complex curved surface, and the earphone housing is a plastic part.

[0105] In some embodiments, the apparatus further comprises:

[0106] The defect location module is used to input the original image to be detected into the deep segmentation model based on the multi-head attention mechanism for processing and output the defect location information;

[0107] An area determination module is used to determine a target area where the defect is located according to the defect location information; wherein the target area is a charging pocket area or a material area of ​​the earphone housing;

[0108] The acceptance module is used to determine the defect acceptance result according to the defect acceptance rule corresponding to the target area and the target grayscale information.

[0109] Each module in the above-mentioned image grayscale processing device can be implemented in whole or in part by software, hardware or a combination thereof. Each module can be embedded in or independent of a processor in a computer device in the form of hardware, or can be stored in a memory in a computer device in the form of software, so that the processor can call and execute operations corresponding to each module.

[0110] In some embodiments, a computer device is provided, which may be a server, and its internal structure diagram may be as follows: Figure 4As shown. The computer device includes a processor, a memory, an input / output interface (Input / Output, referred to as I / O) and a communication interface. The processor, the memory and the input / output interface are connected through a system bus, and the communication interface is connected to the system bus through the input / output interface. The processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, a computer program and a database. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The database of the computer device is used to store data related to the implementation of the image grayscale processing method. The input / output interface of the computer device is used to exchange information between the processor and an external device. The communication interface of the computer device is used to communicate with an external terminal through a network connection. When the computer program is executed by the processor, the steps in the above-mentioned image grayscale processing method are implemented.

[0111] In some embodiments, a computer device is provided. The computer device may be a terminal, and its internal structure diagram may be as follows: Figure 5 As shown. The computer device includes a processor, a memory, an input / output interface, a communication interface, a display unit and an input device. Among them, the processor, the memory and the input / output interface are connected through a system bus, and the communication interface, the display unit and the input device are connected to the system bus through the input / output interface. Among them, the processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system and a computer program. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The input / output interface of the computer device is used to exchange information between the processor and an external device. The communication interface of the computer device is used to communicate with an external terminal in a wired or wireless manner, and the wireless manner can be implemented through WIFI, a mobile cellular network, NFC (near field communication) or other technologies. When the computer program is executed by the processor, the steps in the above-mentioned image grayscale processing method are implemented. The display unit of the computer device is used to form a visually visible picture, which can be a display screen, a projection device or a virtual reality imaging device. The display screen can be a liquid crystal display screen or an electronic ink display screen; the input device of the computer device can be a touch layer covering the display screen, or a key, trackball or touchpad provided on the computer device housing, or an external keyboard, touchpad or mouse, etc.

[0112] Those skilled in the art will understand that Figure 4 or Figure 5The structure shown in the figure is only a block diagram of a part of the structure related to the solution of the present application, and does not constitute a limitation on the computer device to which the solution of the present application is applied. The specific computer device may include more or fewer components than those shown in the figure, or combine certain components, or have a different arrangement of components.

[0113] In some embodiments, a computer device is provided. The computer device includes a memory and a processor. The memory stores a computer program. When the processor executes the computer program, the steps in the above method embodiments are implemented.

[0114] In some embodiments, Figure 6 The figure shows an internal structure diagram of a computer-readable storage medium, which stores a computer program. When the computer program is executed by a processor, the steps in the above-mentioned method embodiments are implemented.

[0115] In some embodiments, a computer program product is provided. The computer program product includes a computer program. When the computer program is executed by a processor, the steps in the above method embodiments are implemented.

[0116] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, stored data, displayed data, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties, and the collection, use and processing of relevant data must comply with relevant laws, regulations and standards of relevant countries and regions.

[0117] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiments can be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to the memory, database or other medium used in the embodiments provided in the present application can include at least one of non-volatile and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory, optical memory, high-density embedded non-volatile memory, resistive random access memory (ReRAM), magnetoresistive random access memory (MRAM), ferroelectric random access memory (FRAM), phase change memory (PCM), graphene memory, etc. Volatile memory can include random access memory (RAM) or external cache memory, etc. As an illustration and not limitation, RAM can be in various forms, such as static random access memory (SRAM) or dynamic random access memory (DRAM). The database involved in each embodiment provided in this application may include at least one of a relational database and a non-relational database. Non-relational databases may include distributed databases based on blockchains, etc., but are not limited to this. The processor involved in each embodiment provided in this application may be a general-purpose processor, a central processing unit, a graphics processor, a digital signal processor, a programmable logic device, a data processing logic device based on quantum computing, etc., but are not limited to this.

[0118] The technical features of the above embodiments may be combined arbitrarily. To make the description concise, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.

[0119] The above embodiments only express several implementation methods of the present application, and the descriptions thereof are relatively specific and detailed, but they cannot be understood as limiting the scope of the present application. It should be pointed out that, for a person of ordinary skill in the art, several variations and improvements can be made without departing from the concept of the present application, and these all belong to the protection scope of the present application. Therefore, the protection scope of the present application shall be subject to the attached claims.

Claims

1. A method for image grayscale processing, characterized in that: include: The original image to be inspected is input into the deep segmentation model based on the multi-head attention mechanism for processing, and the defect information is output; determining an original defect mask according to the defect information; Performing expansion processing on the original defect mask to obtain an expanded defect mask; Determining a background mask according to the expanded defect mask and the original defect mask; Performing edge optimization processing on the original defect mask by using a caliper tool to obtain an optimized defect mask; Extracting a background image and a defect image from the original image to be detected according to the background mask and the optimized defect mask; According to the grayscale information of the background image, the grayscale information of the defect image is normalized, and target grayscale information is extracted from the normalized defect image.

2. The method according to claim 1, characterized in that After determining the original defect mask according to the defect information, the method further includes: Determining the coordinate information of the region of interest according to the edge coordinates of the defect in the original defect mask and a preset compensation threshold; The step of performing expansion processing on the original defect mask to obtain an expanded defect mask includes: Extracting a region of interest ROI defect mask from the original defect mask according to the region of interest coordinate information; The ROI defect mask is expanded to obtain an expanded defect mask.

3. The method according to claim 2, characterized in that The determining of a background mask according to the expanded defect mask and the original defect mask comprises: The background mask is obtained by subtracting the ROI defect mask from the expanded defect mask.

4. The method according to claim 2, characterized in that: The method of performing edge optimization processing on the original defect mask by using a caliper tool to obtain an optimized defect mask includes: Extracting a region of interest ROI defect mask from the original defect mask according to the region of interest coordinate information; The caliper tool is used to perform edge optimization processing on the ROI defect mask to obtain an optimized defect mask.

5. The method according to claim 2, characterized in that: The extracting the background image and the defect image from the original image to be detected according to the background mask and the optimized defect mask comprises: Extracting a ROI image to be detected from the original image to be detected according to the coordinate information of the region of interest; A background image and a defect image are extracted from the ROI image to be detected according to the background mask and the optimized defect mask.

6. The method according to any one of claims 1 to 5, characterized in that The original image to be detected is an image acquired from an earphone housing with a complex curved surface, and the earphone housing is a plastic part.

7. The method according to claim 6, characterized in that Before extracting target grayscale information from the normalized defect image, the method further includes: Inputting the original image to be detected into the deep segmentation model based on the multi-head attention mechanism for processing, and outputting defect location information; After extracting the target grayscale information from the normalized defect image, the method further includes: Determine a target area where the defect is located according to the defect location information; wherein the target area is a charging pocket area or a material area of ​​the earphone housing; A defect acceptance result is determined according to the defect acceptance rule corresponding to the target area and the target grayscale information.

8. An image grayscale processing device, characterized in that: include: A processing module is used to input the original image to be detected into a deep segmentation model based on a multi-head attention mechanism for processing and output defect information; determining an original defect mask according to the defect information; An expansion module, used for performing expansion processing on the original defect mask to obtain an expanded defect mask; A mask determination module, configured to determine a background mask according to the expanded defect mask and the original defect mask; An edge optimization module, used to perform edge optimization processing on the original defect mask by using a caliper tool to obtain an optimized defect mask; An image extraction module, used for extracting a background image and a defect image from the original image to be detected according to the background mask and the optimized defect mask; The grayscale extraction module is used to normalize the grayscale information of the defect image according to the grayscale information of the background image, and extract target grayscale information from the defect image after the normalization.

9. A computer device, comprising a memory and a processor, wherein the memory stores a computer program, wherein: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 7 are implemented.

10. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 7 are implemented.

Citation Information

Cited By

  • Defect detection method and device, computer equipment and computer readable storage medium

    CN120912590A

  • Defect detection method and device, computer device and computer readable storage medium

    CN120912590B