Image processing method, device, computer equipment and storage medium

CN113706440BActive Publication Date: 2024-10-15TENCENT TECHNOLOGY (SHENZHEN) CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202110269969.9
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-03-12
Publication Date
2024-10-15
Estimated Expiration
2041-03-12

Smart Images

  • Figure CN113706440B_ABST
    Figure CN113706440B_ABST
Patent Text Reader

Abstract

The present application discloses an image processing method, device, computer equipment and storage medium, belonging to the field of image processing technology. The present application utilizes a first image and a first mask image after annotating the first image, and transforms and processes the target area where the defect is located, so as to synthesize a target image with the second image as the background and the target area as the foreground on the basis of a second image that does not contain the defect. This target image not only contains the defect but also naturally carries the corresponding annotation information, namely the second mask image, so that there is no need to introduce additional manual annotation to the second image, which greatly alleviates the strict requirements for the annotation information of the second image and reduces the training cost of the defect segmentation model, thereby facilitating the improvement of the accuracy and efficiency of defect segmentation.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of image processing technology, and in particular to an image processing method, apparatus, computer equipment and storage medium. Background Art

[0002] With the development of image processing technology, pixel-level segmentation of product surface defects has gradually become a basic and challenging task in the quality inspection process of industrial products. This task can also be called the defect segmentation task of product images, that is, identifying the target area where the defects are located from the product image.

[0003] In recent years, with the development of artificial intelligence technology, semantic segmentation algorithms based on deep learning can be used to perform defect segmentation tasks in product images. However, since semantic segmentation algorithms usually require manual pre-calibration of large-scale training data, it is unrealistic to obtain defect data for all products at one time due to factory production and scheduling limitations. Therefore, for some products that lack annotations, defect segmentation has low recognition efficiency and poor accuracy. Summary of the invention

[0004] The embodiments of the present application provide an image processing method, apparatus, computer device and storage medium, which can improve the recognition efficiency and accuracy of defect segmentation. The technical solution is as follows:

[0005] In one aspect, an image processing method is provided, the method comprising:

[0006] Acquire a first image and a first mask image, wherein the first image is a surface texture image of a first product, and the first mask image is used to identify a target area where defects are located in the first image;

[0007] In the first mask image, transform the target area to obtain a second mask image;

[0008] Based on the second mask image, the target area is fused with the second image to obtain a target image, where the second image is a surface texture image of a second product;

[0009] Based on the multiple target images and the multiple second mask images, the parameters of the initial segmentation model are adjusted to obtain a defect segmentation model, and the defect segmentation model is used to identify the target area where the defects are located in the surface texture image of the second product.

[0010] In one aspect, an image processing device is provided, the device comprising:

[0011] An acquisition module, used to acquire a first image and a first mask image, wherein the first image is a surface texture image of a first product, and the first mask image is used to identify a target area where defects are located in the first image;

[0012] A transformation module, configured to transform the target area in the first mask image to obtain a second mask image;

[0013] a fusion module, configured to fuse the target area with a second image based on the second mask image to obtain a target image, wherein the second image is a surface texture image of a second product;

[0014] A parameter adjustment module is used to adjust the parameters of the initial segmentation model based on the multiple target images and the multiple second mask images to obtain a defect segmentation model, wherein the defect segmentation model is used to identify the target area where the defect is located in the surface texture image of the second product.

[0015] In a possible implementation manner, the transformation module is used to:

[0016] Randomly sample the target angle from the defect angle interval;

[0017] In the first mask image, the target area is rotated according to the target angle to obtain the second mask image.

[0018] In a possible implementation manner, the transformation module is used to:

[0019] Randomly sample the target size from the defect size range;

[0020] In the first mask image, the size of the target area is transformed into the target size to obtain the second mask image.

[0021] In a possible implementation manner, the transformation module is used to:

[0022] In response to the second image having the same size as the first mask image, randomly sampling from the first mask image to obtain a target position; in the first mask image, translating the target area to the target position to obtain the second mask image; or,

[0023] In response to the second image and the first mask image having different sizes, a target position is obtained by randomly sampling in the second image; the size of the first mask image is scaled to the same size as the second image; and in the scaled first mask image, the target area is translated to the target position to obtain the second mask image.

[0024] In a possible implementation manner, the device further includes:

[0025] A truncation module is configured to, in response to an edge of the translated target area exceeding an edge of the first mask image, truncate the translated target area based on the edge of the first mask image.

[0026] In a possible implementation, the fusion module includes:

[0027] an acquisition unit, configured to acquire a transformed target area based on the second mask image;

[0028] a superimposing unit, configured to superimpose the transformed target area onto the second image to obtain a third image;

[0029] A smoothing unit is used to perform smoothing on the third image to obtain the target image.

[0030] In a possible implementation manner, the superposition unit is used to:

[0031] Poisson image fusion is performed on the transformed target area and the second image to obtain the third image.

[0032] On the one hand, a computer device is provided, which includes one or more processors and one or more memories, wherein at least one computer program is stored in the one or more memories, and the at least one computer program is loaded and executed by the one or more processors to implement an image processing method as described in any possible implementation manner.

[0033] On the one hand, a storage medium is provided, in which at least one computer program is stored. The at least one computer program is loaded and executed by a processor to implement an image processing method as described in any possible implementation manner.

[0034] In one aspect, a computer program product or a computer program is provided, wherein the computer program product or the computer program comprises one or more program codes, wherein the one or more program codes are stored in a computer-readable storage medium. One or more processors of a computer device can read the one or more program codes from the computer-readable storage medium, and the one or more processors execute the one or more program codes, so that the computer device can perform the image processing method of any possible implementation manner described above.

[0035] The beneficial effects brought by the technical solution provided by the embodiment of the present application include at least:

[0036] By utilizing the first image and the first mask image annotated with the first image, and by transforming and processing the target area where the defect is located, it is possible to synthesize a target image with the second image as the background and the target area as the foreground on the basis of the second image that does not contain the defect. This target image not only contains the defect but also naturally carries the corresponding annotation information, namely the second mask image. Therefore, there is no need to introduce additional manual annotation to the second image, which greatly alleviates the stringent requirements on the annotation information of the second image and reduces the training cost of the defect segmentation model, which is beneficial to improving the accuracy and efficiency of defect segmentation. BRIEF DESCRIPTION OF THE DRAWINGS

[0037] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.

[0038] Figure 1 It is a schematic diagram of an implementation environment of an image processing method provided in an embodiment of the present application;

[0039] Figure 2 is a flow chart of an image processing method provided by an embodiment of the present application;

[0040] Figure 3 is a schematic diagram of a principle of synthesizing a target image provided by an embodiment of the present application;

[0041] Figure 4 is a flow chart of an image processing method provided by an embodiment of the present application;

[0042] Figure 5 is a schematic diagram of a surface texture image of a product provided in an embodiment of the present application;

[0043] Figure 6 and Figure 7 It is a structural diagram of a performance comparison experiment provided in an embodiment of the present application;

[0044] Figure 8 is a structural schematic diagram of an image processing device provided in an embodiment of the present application;

[0045] Fig. 9 is a structural schematic diagram of a computer device provided in an embodiment of the present application;

[0046] Fig.10 It is a structural diagram of a computer device provided in an embodiment of the present application. DETAILED DESCRIPTION

[0047] In order to make the objectives, technical solutions and advantages of the present application clearer, the implementation methods of the present application will be further described in detail below with reference to the accompanying drawings.

[0048] In this application, the terms "first", "second", etc. are used to distinguish identical or similar items with basically the same effects and functions. It should be understood that there is no logical or temporal dependency between "first", "second", and "nth", nor is there any limitation on quantity and execution order.

[0049] In the present application, the term "at least one" means one or more, and the meaning of "plurality" means two or more. For example, a plurality of first positions means two or more first positions.

[0050] The embodiments of the present application involve machine learning technology in the field of artificial intelligence. Therefore, before introducing the embodiments of the present application, some basic concepts in the field of artificial intelligence are first introduced, which are introduced below.

[0051] Artificial Intelligence (AI): Artificial Intelligence is the theory, method, technology and application system that uses digital computers or machines controlled by digital computers to simulate, extend and expand human intelligence, perceive the environment, acquire knowledge and use knowledge to obtain the best results. In other words, artificial intelligence is a comprehensive technology in computer science that attempts to understand the essence of intelligence and produce a new intelligent machine that can respond in a similar way to human intelligence. Artificial Intelligence is to study the design principles and implementation methods of various intelligent machines so that machines have the functions of perception, reasoning and decision-making.

[0052] Artificial intelligence technology is a comprehensive discipline that covers a wide range of fields, including both hardware-level and software-level technologies. The basic technologies of artificial intelligence generally include sensors, dedicated artificial intelligence chips, cloud computing, distributed storage, big data processing technology, operation / interaction systems, mechatronics and other technologies. Artificial intelligence software technology mainly includes computer vision technology, speech processing technology, natural language processing technology, and machine learning / deep learning.

[0053] Computer vision technology (CV): In the field of AI, computer vision technology is a rapidly developing branch. Computer vision is a science that studies how to make machines "see". To put it more specifically, it refers to using machines such as cameras and computers to replace human eyes to identify, track and measure targets, and further perform graphic processing so that the machine can process images that are more suitable for human eye observation or transmission to instruments for detection. As a scientific discipline, computer vision studies related theories and technologies, and attempts to establish an artificial intelligence system that can obtain information from images or multidimensional data. Computer vision usually includes image segmentation, image recognition, image retrieval, video semantic understanding, video content / behavior recognition, three-dimensional object reconstruction, optical character recognition (OCR), video processing, 3D (3D) technology, virtual reality, augmented reality, simultaneous positioning and mapping, and of course, common biometric recognition technologies such as face recognition and fingerprint recognition.

[0054] Machine Learning (ML): Machine learning is a multi-disciplinary subject involving probability theory, statistics, approximation theory, convex analysis, algorithm complexity theory and other disciplines. It specializes in studying how computers simulate or implement human learning behavior to acquire new knowledge or skills and reorganize existing knowledge structures to continuously improve their performance. Machine learning is the core of artificial intelligence and the fundamental way to make computers intelligent. Its applications are spread across all areas of artificial intelligence. Machine learning and deep learning usually include artificial neural networks, belief networks, reinforcement learning, transfer learning, inductive learning, and self-learning.

[0055] Image segmentation: Representing an image as a collection of physically meaningful connected regions, that is, marking and locating the target and background in the image based on the prior knowledge of the target and background, and then separating the target from the background or other pseudo-targets. Image segmentation plays a connecting role in image understanding applications such as target recognition, object tracking, and behavior analysis, greatly reducing the amount of data to be processed in subsequent image analysis and recognition processes while retaining information about the image structure features. In the industrial product quality inspection process, segmenting defects (targets) from the surface texture image (background) of the product is a basic and challenging task, which can achieve pixel-level segmentation of product surface defects, thereby realizing automated quality inspection of products.

[0056] With the research and progress of artificial intelligence technology, artificial intelligence technology has been studied and applied in many fields, such as common smart homes, smart wearable devices, virtual assistants, smart speakers, smart marketing, unmanned driving, automatic driving, drones, robots, smart medical care, smart customer service, etc. It is believed that with the development of technology, artificial intelligence technology will be applied in more fields and play an increasingly important role. The solution provided in the embodiment of this application involves an image segmentation technology based on machine learning, which is used for automated quality inspection of products, which is illustrated by the following embodiment.

[0057] In the quality inspection process of industrial products, pixel-level segmentation of product surface defects has gradually become a basic and challenging task. This task can also be called the defect segmentation task of product images, that is, identifying the target area where the defects are located from the product image.

[0058] In recent years, with the development of artificial intelligence technology, semantic segmentation algorithms based on deep learning can be used to perform defect segmentation tasks in product images. However, semantic segmentation algorithms usually pre-calibrate large-scale training data manually. However, due to the limitations of factory production and scheduling, it is unrealistic to obtain defect data for all products at once. Therefore, for some products that lack annotations, defect segmentation has low recognition efficiency and poor accuracy. Although there are certain differences between the surface texture features of different products, the texture of the defect itself often has a certain stability, such as scratches and missing parts.

[0059] In view of this, an embodiment of the present application provides an image processing method. For new products that lack annotations, it can synthesize the defect data of new products with annotations (target domain) based on the defect data of labeled products (source domain), so as to train a defect segmentation model for new products, so as to achieve the surface defect segmentation of new products, which is of great significance for promoting the large-scale implementation of automated quality inspection products.

[0060] Figure 1 Schematic diagram of an implementation environment of an image processing method provided in an embodiment of the present application. Figure 1 , the implementation environment includes a terminal 101 and a server 102, which is described below:

[0061] The terminal 101 is installed and runs an application that supports automated quality inspection of products. Optionally, the terminal 101 is installed with an application, and a user inputs a surface texture image of a batch of products into the application, and the application calls a defect segmentation model to identify defects in the surface texture image and outputs a target area where defects are located in the surface texture image.

[0062] The terminal 101 may be directly or indirectly connected to the server 102 via wired or wireless communication, and the embodiment of the present application does not limit the connection method.

[0063] The server 102 is used to provide background services for the above application, and the server 102 includes at least one of a single server, multiple servers, a cloud computing platform, or a virtualization center. Optionally, the server 102 undertakes the main processing work, and the terminal 101 undertakes the secondary processing work; or, the server 102 undertakes the secondary processing work, and the terminal 101 undertakes the main processing work; or, the server 102 and the terminal 101 adopt a distributed computing architecture to perform collaborative image processing.

[0064] Optionally, the server 102 is used to train the above-mentioned defect segmentation model. For example, the server 102 adds defects to the normal (i.e., defect-free) surface texture image of the product to be identified based on the surface texture image of the labeled product and the target area where the labeled defects are located, so as to obtain the surface texture image with defects of the product to be identified, and these surface texture images carry the annotation information of the defects, so that the initial segmentation model can be trained based on the annotation information of the above-mentioned product to be identified to obtain the defect segmentation model.

[0065] In some embodiments, server 102 is an independent physical server, or a server cluster or distributed system composed of multiple physical servers, or a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, CDN (Content Delivery Network), and big data and artificial intelligence platforms.

[0066] In some embodiments, terminal 101 is a smart phone, a tablet computer, a laptop computer, a desktop computer, a smart speaker, a smart watch, an MP3 (Moving Picture Experts Group Audio Layer III) player, an MP4 (Moving Picture Experts Group Audio Layer IV) player, an e-book reader, etc., but is not limited to these.

[0067] Those skilled in the art will appreciate that the number of the terminals 101 may be more or less. For example, there may be only one terminal 101, or there may be dozens or hundreds of terminals 101, or a greater number. The embodiment of the present application does not limit the number and device type of the terminals 101.

[0068] Figure 2 is a flow chart of an image processing method provided by an embodiment of the present application. Figure 2 This embodiment is applied to a computer device. Taking the computer device as a server as an example, this embodiment includes:

[0069] 201. The server obtains a first image and a first mask image, where the first image is a surface texture image of a first product, and the first mask image is used to identify a target area where defects are located in the first image.

[0070] The server can be any computer device that supports image processing. The server is used to train the initial segmentation model to obtain a defect segmentation model. Optionally, the server maintains the defect segmentation model in the cloud, so that the terminal and the server interact to complete product quality inspection, saving the computing resources of the terminal. Alternatively, the server sends the defect segmentation model to the terminal in the form of cold update or hot update, so that the terminal can complete product quality inspection locally, saving communication overhead. The embodiments of the present application do not specifically limit this.

[0071] The first image refers to a surface texture image of a first product. For example, the first product includes but is not limited to: a mobile phone, a monitor, a computer, a television, a radio, etc.

[0072] In some embodiments, after the server obtains the first image uploaded by the user, a technician annotates the first image to mark the target area where the defect is located in the first image. Further, based on the position and shape of the target area, the first mask image is generated. Optionally, the first mask image is a binary image. In the binary image, the target area where the defect is located and the background area of ​​the rest have different pixel values. For example, the pixel value of the target area is 1, and the pixel value of the background area is 0, or the pixel value of the target area is 0, and the pixel value of the background area is 1. The embodiments of the present application do not specifically limit this.

[0073] 202. The server transforms the target area in the first mask image to obtain a second mask image.

[0074] In some embodiments, the server may transform the target area based on at least one of the following methods, which are described below respectively.

[0075] Method 1: Target Angle Change

[0076] Optionally, the server randomly samples a target angle from the defect angle interval; in the first mask image, the target area is rotated according to the target angle to obtain the second mask image.

[0077] In some embodiments, the defect angle interval can be a fixed numerical interval, which is set by a technician. Optionally, the defect angle interval can change according to the characteristics of the second product. For example, different characteristics of the second product will result in different values ​​of the defect angle interval. The embodiments of the present application do not specifically limit this.

[0078] Optionally, assuming that the defect angle interval is [-θ, θ], the server randomly samples an angle from the defect angle interval [-θ, θ) as the target angle, and then rotates the target area by the target angle in the first mask image to obtain the second mask image. Wherein θ is any angle value greater than 0.

[0079] In the above process, since the same type of defects are usually presented at different angles in the surface texture image of the product, the diversity of defect angles in the synthesized target image can be enriched by rotating the target area.

[0080] Method 2: Target scaling transformation

[0081] Optionally, the server randomly samples from the defect size interval to obtain a target size; in the first mask image, the size of the target area is transformed into the target size to obtain the second mask image.

[0082] In some embodiments, the defect size interval can be a fixed numerical interval, which is set by a technician. Optionally, the defect size interval can change according to the characteristics of the second product. For example, different characteristics of the second product will result in different values ​​of the defect size interval. The embodiments of the present application do not specifically limit this.

[0083] Optionally, assuming that the defect size interval is [s1, s2], the server randomly samples a size from the defect size interval [s1, s2] as the target size, and then scales the target area in the first mask image to the target size to obtain the second mask image. Wherein, s1 is any size value greater than 0, and s2 is any size value greater than s1.

[0084] In the above process, since the same type of defects usually have different sizes in the surface texture image of the product, the diversity of defect sizes in the synthesized target image can be enriched by scaling the size of the target area.

[0085] Method 3: Target Position Randomization

[0086] In some embodiments, in response to the second image being the same size as the first mask image, the server randomly samples the target position from the first mask image; in the first mask image, the target area is translated to the target position to obtain the second mask image.

[0087] Since the target area needs to be migrated to the second image, optionally, when the second image has the same size as the first mask image, the server can directly randomly sample a position from the first mask image as the target position, obtain the position coordinates of the target position, and translate the target area in the first mask image so that the center coordinates of the translated target area coincide with the position coordinates of the target position, thereby obtaining the second mask image.

[0088] In some embodiments, in response to the second image and the first mask image having different sizes, the server randomly samples the target position in the second image; scales the size of the first mask image to the same size as the second image; and translates the target area to the target position in the scaled first mask image to obtain the second mask image.

[0089] Optionally, when the size of the second image is different from that of the first mask image, the server may randomly sample a position from the second image as the target position and obtain the position coordinates of the target position. Further, the size of the first mask image may be scaled to the same size as that of the second image, the center coordinates of the target area may be obtained, and the target area may be translated in the first mask image so that the center coordinates of the translated target area coincide with the position coordinates of the target position, thereby obtaining the second mask image.

[0090] In the above process, since the defect may appear at any position in the second image, the diversity of the positions where the defects appear in the synthesized target image can be enriched by randomizing the positions of the target areas.

[0091] Method 4: Target Truncation

[0092] Optionally, after the server translates the target area, in response to an edge of the translated target area exceeding an edge of the first mask image, the server truncates the translated target area based on the edge of the first mask image.

[0093] In some embodiments, after the server translates the target area, since the position coordinates of the target position may be any position in the first mask image, when the distance between the target position and the edge of the first mask image is smaller than the size of the target area, the edge of the translated target area may exceed the edge of the first mask image. In this case, it is necessary to truncate the translated target area to avoid uneven edges of the second mask image.

[0094] In some embodiments, the server sets the following truncation condition: the area of ​​the target area after truncation is at least greater than or equal to one third of the area of ​​the target area before truncation, so as to ensure the discernibility of defects; optionally, the following truncation condition can also be set: the area of ​​the target area after truncation is at least greater than or equal to one half of the area of ​​the target area before truncation, which can also ensure the discernibility of defects. Of course, other truncation conditions can also be set, and the embodiments of the present application do not specifically limit this.

[0095] In the above process, it is a common phenomenon that defects are not fully displayed in the second image. For example, in a half-length portrait in a natural scene, by setting the target position close to the edge, vertex, etc. of the first mask image, a target image with truncated defects can be synthesized.

[0096] It should be noted that the server can adopt any one of the above-mentioned methods 1 to 4 to transform the target area, or can adopt a combination of at least two of the above-mentioned methods 1 to 4 to transform the target area. The embodiment of the present application does not specifically limit this.

[0097] 203. The server fuses the target area with the second image based on the second mask image to obtain a target image, where the second image is a surface texture image of the second product.

[0098] In some embodiments, the server obtains a transformed target area based on the second mask image; superimposes the transformed target area on the second image to obtain a third image; and smoothes the third image to obtain the target image.

[0099] Optionally, since the second mask image actually indicates the position, size and shape of the target area in the second image, the server can transform the target area accordingly based on the size and shape indicated by the second mask image to obtain the transformed target area, and based on the position indicated by the second mask image, superimpose the transformed target area to the corresponding position in the second image to obtain a preliminary synthesized third image, and then smooth the third image to obtain the target image.

[0100] In some embodiments, when acquiring the third image, the server may perform Poisson image fusion on the transformed target area and the second image to obtain the third image. Optionally, Poisson image fusion is a method for solving the optimal value of pixels based on the Poisson equation, which fuses the transformed target area and the second image while retaining the gradient information of the second image. The Poisson image fusion method solves a Poisson equation according to the boundary conditions specified by the user, realizes continuity in the gradient domain, and thus achieves seamless fusion at the boundary. In Poisson image fusion, the boundary smoothing equation can be expressed as the following formula:

[0101]

[0102] Wherein, Ω represents the area covered by the transformed target area in the third image, f is the pixel representation function within the covered area Ω in the third image, The pixel represents the gradient field of the function f, and v represents the gradient field of the target area after the transformation.

[0103] The condition for maintaining boundary consistency can be expressed as the following formula:

[0104]

[0105] Wherein, Ω represents the area covered by the transformed target area in the third image, represents the boundary of the covered area Ω, f is the pixel representation function within the covered area Ω in the third image, and f * is the pixel representation function outside the covered area Ω in the third image.

[0106] In discrete space, when the boundary consistency condition is met, the third image f can be obtained by minimizing the boundary smoothing equation.

[0107] In some embodiments, when the server performs smoothing on the third image, the following smoothing method can be adopted: the server performs smoothing on the third image based on a two-dimensional Gaussian filter function to obtain the target image. It should be noted that the "smoothing" or "smoothing" involved in the embodiments of the present application refers to the smoothing operation performed on the image, that is, modifying the pixel values ​​of some pixels in an image to be processed to make the image smoother and continuous, or reducing or deleting noise points (or outliers) in the image, for example, modifying the boundary pixels of the transformed target area in the third image to make the transition between the transformed target area and the background area of ​​the rest smoother and more natural. The above-mentioned smoothing is equivalent to the process of low-pass filtering, which will highlight the wide area, low-frequency components, and main trunk of the image, and will also suppress image noise and high-frequency interference components, which can make the image brightness tend to be gentle and gradual, reduce sudden gradients, and improve image quality, but usually lead to blurred image edges.

[0108] Optionally, the two-dimensional Gaussian filter function G (x,y) The expression is as follows:

[0109]

[0110] Among them, x and y represent the distance between the horizontal and vertical coordinates of a pixel in the convolution kernel and the center point of the convolution kernel. σ controls the smoothness of the curve. The larger the value of σ, the smoother the curve and the lower the highest point. By setting the size of σ, the blurriness of the target image can be controlled. The larger the value of σ, the blurrier the target image. It can be seen from the above two-dimensional Gaussian filter function that the value is the largest when x=0 and y=0, that is, the weight of the center point of the convolution kernel is the largest.

[0111] In the above process, the two-dimensional Gaussian filter function is equivalent to fusing the transformed target area (foreground) with the second image (background) to obtain a third image, and then using a Gaussian filter to perform noise processing on the distorted edges in the third image to blur the edges of the foreground in the third image to reduce the negative impact of image distortion.

[0112] In some embodiments, in addition to the above-mentioned Gaussian blur method, the server can also adopt the following smoothing methods: neighborhood averaging method (mean filtering method), over-limit pixel smoothing method, edge-preserving filtering method, median filtering method, convolution method, etc. The embodiments of the present application do not specifically limit this.

[0113] In an exemplary embodiment, the server can call the seamlessClone function in the OpenCV library to perform Poisson image fusion, and then call the GaussianBlur function in the OpenCV library to perform Gaussian blur processing. Of course, related functions in other native libraries can also be used, and the embodiment of the present application does not specifically limit this.

[0114] Figure 3 is a schematic diagram of a principle of synthesizing a target image provided by an embodiment of the present application, such as Figure 3 As shown, after the server obtains the first image 300 and the first mask image 301, it performs defect synthesis on the defect-free second image 302, and migrates the target area where the defects in the first image 300 are located to the second image 302, to obtain the target image 303 and the second mask image 304. In other words, the defects in the surface texture image of the first product can be migrated to the surface texture image of the defect-free second product, thereby synthesizing a target image of the second product with defects, and the positions, sizes, and shapes of these defects are all carried by the product itself, without the need for additional manpower for additional labeling.

[0115] 204. The server adjusts parameters of the initial segmentation model based on the multiple target images and the multiple second mask images to obtain a defect segmentation model, where the defect segmentation model is used to identify a target area where defects are located in the surface texture image of the second product.

[0116] In some embodiments, the server repeatedly executes the above steps 201-203 to obtain multiple target images and corresponding multiple second mask images, which can constitute a training sample set. The server inputs the multiple target images into the initial segmentation model, performs semantic segmentation on the multiple target images through the initial segmentation model, and outputs multiple semantic segmentation images, which are equivalent to the prediction results of the initial segmentation model for the multiple target images, and the multiple second mask images are equivalent to the annotation results of the multiple target images. The loss function value of this iteration process is obtained through the difference between the multiple semantic segmentation images and the multiple second mask images. In response to the loss function value not meeting the stop condition, the parameters of the initial segmentation model are adjusted, and the above steps of obtaining the loss function value are iteratively performed until the loss function value in any iteration meets the stop condition, and the training is stopped to obtain the defect segmentation model.

[0117] In some embodiments, the defect segmentation model includes but is not limited to: FCN (Fully Convolutional Networks), SegNet (semantic segmentation network), Dilated Convolutions, DeepLab series semantic segmentation networks (v1&v2&v3), PSPNet (Pyramid Scene Parsing Network), UperNet (Unified Perceptual Networks), etc. The embodiment of the present application does not specifically limit the structure of the defect segmentation model.

[0118] In an exemplary scenario, the source domain defect image set (a data set consisting of multiple first images and corresponding multiple first mask images) is recorded as {(S1, Y1), (S2, Y2), ..., (S n , Y n )}, the target domain synthetic image set (a data set consisting of multiple target images and corresponding multiple second mask images) is recorded as {(T1, Z1), (T2, Z2), ..., (T n , Z n )}.

[0119] Optionally, the server can use the source domain defect image set {(S1, Y1), (S2, Y2), ..., (Sn , Y n )} to obtain the initial segmentation model, and then based on the initial segmentation model, the target domain synthetic image set {(T1, Z1), (T2, Z2), ..., (T n , Z n )}The defect segmentation model is obtained by training through fine-tuning, which is more targeted and can improve the defect recognition accuracy of the surface texture image of the second product.

[0120] Optionally, the server can also directly send the source domain defect image set {(S1, Y1), (S2, Y2), ..., (S n , Y n )} and the target domain synthetic image set {(T1, Z1), (T2, Z2), ..., (T n , Z n )} are merged into a unified training sample set, and based on the initialized initial segmentation model, the defect segmentation model is trained from scratch. This approach makes the defect segmentation model have good generalization ability, and the management work in the model deployment stage is simple and practical.

[0121] All the above optional technical solutions can be arbitrarily combined to form optional embodiments of the present disclosure, and will not be described in detail here.

[0122] The method provided in the embodiment of the present application, by utilizing the first image and the first mask image after annotating the first image, and by transforming and processing the target area where the defect is located, can synthesize a target image with the second image as the background and the target area as the foreground on the basis of a second image that does not contain the defect. This target image not only contains the defect but also naturally carries the corresponding annotation information, namely the second mask image, so that there is no need to introduce additional manual annotation to the second image, which greatly alleviates the strict requirements on the annotation information of the second image and reduces the training cost of the defect segmentation model, which is beneficial to improving the accuracy and efficiency of defect segmentation.

[0123] Figure 4 This is a flowchart of an image processing method provided in an embodiment of the present application. Please refer to Figure 4 This embodiment is applied to a computer device. Taking the computer device as a server as an example, this embodiment includes:

[0124] 401. The server obtains a first image and a first mask image, where the first image is a surface texture image of a first product, and the first mask image is used to identify a target area where defects are located in the first image.

[0125] The above step 401 is similar to the above step 201 and will not be described in detail here.

[0126] Figure 5 It is a schematic diagram of a surface texture image of a product provided in an embodiment of the present application, as shown in 500, which shows the surface texture images of products obtained after processing four different products at two different sites (i.e., factories). It can be seen that not only are there large differences in the surface texture images of different products in the same factory, but there are also large differences in the surface texture images of the same product after processing in different factories.

[0127] 402. The server randomly samples the target angle from the defect angle interval.

[0128] In some embodiments, the defect angle interval can be a fixed numerical interval, which is set by a technician. Optionally, the defect angle interval can change according to the characteristics of the second product. For example, different characteristics of the second product will result in different values ​​of the defect angle interval. The embodiments of the present application do not specifically limit this.

[0129] Optionally, assuming that the defect angle interval is [-θ, θ], the server randomly samples an angle from the defect angle interval [-θ, θ) as the target angle, where θ is any angle value greater than 0.

[0130] 403. The server performs a rotation transformation on the target area in the first mask image according to the target angle to obtain a second mask image.

[0131] Optionally, the server rotates the target area by the target angle in the first mask image to obtain the second mask image.

[0132] In the above process, since the same type of defects are usually presented at different angles in the surface texture image of the product, the diversity of defect angles in the synthesized target image can be enriched by rotating the target area.

[0133] In some embodiments, the above steps 402-403 may also be replaced in the following manner: the server randomly samples the target size from the defect size interval; in the first mask image, the size of the target area is transformed into the target size to obtain the second mask image.

[0134] In some embodiments, the defect size interval can be a fixed numerical interval, which is set by a technician. Optionally, the defect size interval can change according to the characteristics of the second product. For example, different characteristics of the second product will result in different values ​​of the defect size interval. The embodiments of the present application do not specifically limit this.

[0135] Optionally, assuming that the defect size interval is [s1, s2], the server randomly samples a size from the defect size interval [s1, s2] as the target size, and then scales the target area in the first mask image to the target size to obtain the second mask image. Wherein, s1 is any size value greater than 0, and s2 is any size value greater than s1.

[0136] In the above process, since the same type of defects usually have different sizes in the surface texture image of the product, the diversity of defect sizes in the synthesized target image can be enriched by scaling the size of the target area.

[0137] In some embodiments, the above steps 402-403 can also be replaced in the following manner: in response to the second image being the same size as the first mask image, the server randomly samples the target position from the first mask image; in the first mask image, the target area is translated to the target position to obtain the second mask image.

[0138] Since the target area needs to be migrated to the second image, optionally, when the second image has the same size as the first mask image, the server can directly randomly sample a position from the first mask image as the target position, obtain the position coordinates of the target position, and translate the target area in the first mask image so that the center coordinates of the translated target area coincide with the position coordinates of the target position, thereby obtaining the second mask image.

[0139] In some embodiments, the above steps 402-403 can also be replaced in the following manner: in response to the second image being different in size from the first mask image, the server randomly samples the target position in the second image; scales the size of the first mask image to the same size as the second image; and in the scaled first mask image, translates the target area to the target position to obtain the second mask image.

[0140] Since the target area needs to be migrated to the second image, optionally, when the size of the second image is different from that of the first mask image, the server can randomly sample a position from the second image as the target position and obtain the position coordinates of the target position. Further, the size of the first mask image is scaled to the same size as the second image, the center coordinates of the target area are obtained, and the target area is translated in the first mask image so that the center coordinates of the translated target area coincide with the position coordinates of the target position, thereby obtaining the second mask image.

[0141] In the above process, since the defect may appear at any position in the second image, the diversity of the positions where the defects appear in the synthesized target image can be enriched by randomizing the positions of the target areas.

[0142] In some embodiments, after the server translates the target area, in response to an edge of the translated target area exceeding an edge of the first mask image, the server truncates the translated target area based on the edge of the first mask image.

[0143] In some embodiments, after the server translates the target area, since the position coordinates of the target position may be any position in the first mask image, when the distance between the target position and the edge of the first mask image is smaller than the size of the target area, the edge of the translated target area may exceed the edge of the first mask image. In this case, it is necessary to truncate the translated target area to avoid uneven edges of the second mask image.

[0144] In some embodiments, the server sets the following truncation condition: the area of ​​the target area after truncation is at least greater than or equal to one third of the area of ​​the target area before truncation, so as to ensure the discernibility of defects; optionally, the following truncation condition can also be set: the area of ​​the target area after truncation is at least greater than or equal to one half of the area of ​​the target area before truncation, which can also ensure the discernibility of defects. Of course, other truncation conditions can also be set, and the embodiments of the present application do not specifically limit this.

[0145] In the above process, it is a common phenomenon that defects are not fully displayed in the second image. For example, in a half-length portrait in a natural scene, by setting the target position close to the edge, vertex, etc. of the first mask image, a target image with truncated defects can be synthesized.

[0146] In the above process, it is shown that the server transforms the target area in the first mask image to obtain multiple transformation methods of the second mask image, including angle transformation, scaling transformation, position randomization, target truncation, etc., which is not specifically limited in the embodiments of the present application.

[0147] 404. The server obtains a transformed target area based on the second mask image.

[0148] Optionally, since the second mask image actually indicates the position, size and shape of the target area in the second image, the server may perform corresponding transformation on the target area based on the size and shape indicated by the second mask image to obtain a transformed target area.

[0149] 405. The server performs Poisson image fusion on the transformed target area and the second image to obtain a third image, where the second image is a surface texture image of the second product.

[0150] Poisson image fusion is a method for solving the optimal pixel value based on the Poisson equation. It fuses the transformed target area with the second image while retaining the gradient information of the second image. The Poisson image fusion method solves a Poisson equation according to the boundary conditions specified by the user, realizes the continuity in the gradient domain, and thus achieves seamless fusion at the boundary. In Poisson image fusion, the boundary smoothing equation can be expressed as the following formula:

[0151]

[0152] Wherein, Ω represents the area covered by the transformed target area in the third image, f is the pixel representation function within the covered area Ω in the third image, The pixel represents the gradient field of the function f, and v represents the gradient field of the target area after the transformation.

[0153] The condition for maintaining boundary consistency can be expressed as the following formula:

[0154]

[0155] Wherein, Ω represents the area covered by the transformed target area in the third image, represents the boundary of the covered area Ω, f is the pixel representation function within the covered area Ω in the third image, and f * is the pixel representation function outside the covered area Ω in the third image.

[0156] In discrete space, when the boundary consistency condition is met, the third image f can be obtained by minimizing the boundary smoothing equation.

[0157] In an exemplary embodiment, the server may call the seamlessClone function in the OpenCV library to perform Poisson image fusion.

[0158] In the above process, that is, the server superimposes the transformed target area on the second image to obtain a possible implementation of the third image, Poisson fusion can enhance the natural fusion of the third image and reduce the distortion of the synthesized target image. Optionally, the server can superimpose the transformed target area on the corresponding position in the second image based on the position indicated by the second mask image to obtain a preliminary synthesized third image.

[0159] In other embodiments, the server may not perform Poisson fusion, but instead directly cover the transformed target area to the corresponding position in the second image based on the position indicated by the second mask image to obtain a third image, thereby simplifying the image fusion process.

[0160] 406. The server performs smoothing processing on the third image to obtain a target image.

[0161] When the server performs smoothing on the third image, the following smoothing method can be adopted: the server performs smoothing on the third image based on a two-dimensional Gaussian filter function to obtain the target image. It should be noted that the "smoothing" or "smoothing" involved in the embodiments of the present application refers to the smoothing operation performed on the image, that is, modifying the pixel values ​​of some pixels in an image to be processed to make the image smoother and continuous, or reducing or deleting noise points (or outliers) in the image, for example, modifying the boundary pixels of the transformed target area in the third image to make the transition between the transformed target area and the background area of ​​the rest smoother and more natural. The above-mentioned smoothing is equivalent to the process of low-pass filtering, which will highlight the wide area, low-frequency components, and main trunk of the image, and will also suppress image noise and high-frequency interference components, which can make the image brightness tend to change gently, reduce sudden gradients, and improve image quality, but usually leads to blurred image edges.

[0162] Optionally, the two-dimensional Gaussian filter function G (x,y) The expression is as follows:

[0163]

[0164] Among them, x and y represent the distance between the horizontal and vertical coordinates of a pixel in the convolution kernel and the center point of the convolution kernel. σ controls the smoothness of the curve. The larger the value of σ, the smoother the curve and the lower the highest point. By setting the size of σ, the blurriness of the target image can be controlled. The larger the value of σ, the blurrier the target image. It can be seen from the above two-dimensional Gaussian filter function that the value is the largest when x=0 and y=0, that is, the weight of the center point of the convolution kernel is the largest.

[0165] In the above process, the two-dimensional Gaussian filter function is equivalent to fusing the transformed target area (foreground) with the second image (background) to obtain a third image, and then using a Gaussian filter to perform noise processing on the distorted edges in the third image to blur the edges of the foreground in the third image to reduce the negative impact of image distortion.

[0166] In some embodiments, in addition to the above-mentioned Gaussian blur method, the server can also adopt the following smoothing methods: neighborhood averaging method (mean filtering method), over-limit pixel smoothing method, edge-preserving filtering method, median filtering method, convolution method, etc. The embodiments of the present application do not specifically limit this.

[0167] In an exemplary embodiment, the server may call the GaussianBlur function in the OpenCV library to perform Gaussian blur processing.

[0168] In the above steps 404-406, the server fuses the target area with the second image based on the second mask image to obtain a target image. In some embodiments, the server may not perform Poisson fusion and Gaussian blur, but directly cover the transformed target area to the corresponding position in the second image based on the position indicated by the second mask image to obtain a third image, and use the third image as the target image, thereby simplifying the image synthesis process.

[0169] 407. The server adjusts parameters of the initial segmentation model based on the multiple target images and the multiple second mask images to obtain a defect segmentation model, where the defect segmentation model is used to identify a target area where defects are located in the surface texture image of the second product.

[0170] The above step 407 is similar to the above step 204 and will not be described in detail here.

[0171] All the above optional technical solutions can be arbitrarily combined to form optional embodiments of the present disclosure, and will not be described in detail here.

[0172] The method provided in the embodiment of the present application, by utilizing the first image and the first mask image after annotating the first image, and by transforming and processing the target area where the defect is located, can synthesize a target image with the second image as the background and the target area as the foreground on the basis of a second image that does not contain the defect. This target image not only contains the defect but also naturally carries the corresponding annotation information, namely the second mask image, so that there is no need to introduce additional manual annotation to the second image, which greatly alleviates the strict requirements on the annotation information of the second image and reduces the training cost of the defect segmentation model, which is beneficial to improving the accuracy and efficiency of defect segmentation.

[0173] In an exemplary scenario, the defect segmentation model is tested as UperNet, the source domain defect data (i.e., the data set composed of multiple first images and corresponding multiple first mask images) is kept fixed, and three different target domain defect data are used for comparative experiments, wherein the three different target domain defect data include: normal images, defect composite images provided by the embodiment of the present application, and fully annotated images (manually annotated images). The evaluation index used is MIOU (mean Intersection Over Union), which is a semantic segmentation metric, which is the average of the ratio of the intersection and union of all categories. The following is an explanation of the four groups of comparative experiments:

[0174] (1) Benchmark experiment: The defect segmentation model is trained using source domain defect data.

[0175] (2) Normal samples: Normal images are used as target domain defect data. Since the target domain normal images themselves do not have defects, the corresponding defect masks are background classes, so no manual labeling is required. The source domain defect data and the target domain normal images are mixed to train the defect segmentation model.

[0176] (3) Defect synthesis (technical solution of the embodiment of the present application): Based on the image processing method provided in the embodiment of the present application, the source domain defect data and the target domain normal image are used to synthesize the target domain defect data. Since the defect position of the synthesized target domain defect data (i.e., the target image) is determined, manual labeling is not required. The source domain defect data and the synthesized target domain defect data are mixed to train the defect segmentation model.

[0177] (4) Target domain defect data: Use real (manually annotated) target domain defect data and source domain defect data to train the defect segmentation model. The performance of this experiment is the upper limit of the performance of the defect synthesis method to achieve domain transfer segmentation method.

[0178] After the defect segmentation model is trained, an evaluation comparison is performed based on the same target domain test set.

[0179] Figure 6 and Figure 7 This is a structural diagram of a performance comparison experiment provided in an embodiment of the present application. Please refer to 600 and 700. It can be seen that the method for synthesizing target domain defect data provided in an embodiment of the present application significantly improves the defect segmentation performance of the target domain. Moreover, between different products at the same site, compared with the benchmark experiment and using only normal images in the target domain, the defect synthesis method is close to the performance of using the full amount of target domain defect data. This fully verifies the huge advantages of the defect synthesis method in domain migration segmentation. In addition, there is also a more obvious improvement compared to the benchmark experiment on the same product across sites.

[0180] Figure 8 This is a schematic diagram of the structure of an image processing device provided in an embodiment of the present application. Please refer to Figure 8 , the device comprises:

[0181] An acquisition module 801 is used to acquire a first image and a first mask image, wherein the first image is a surface texture image of a first product, and the first mask image is used to identify a target area where defects are located in the first image;

[0182] A transformation module 802, configured to transform the target area in the first mask image to obtain a second mask image;

[0183] A fusion module 803 is used to fuse the target area with the second image based on the second mask image to obtain a target image, where the second image is a surface texture image of the second product;

[0184] The parameter adjustment module 804 is used to adjust the parameters of the initial segmentation model based on the multiple target images and the multiple second mask images to obtain a defect segmentation model, which is used to identify the target area where the defect is located in the surface texture image of the second product.

[0185] The device provided in the embodiment of the present application, by utilizing the first image and the first mask image after annotating the first image, and by transforming and processing the target area where the defect is located, can synthesize a target image with the second image as the background and the target area as the foreground on the basis of a second image that does not contain the defect. This target image not only contains the defect but also naturally carries the corresponding annotation information, namely the second mask image, so that there is no need to introduce additional manual annotation to the second image, which greatly alleviates the strict requirements on the annotation information of the second image and reduces the training cost of the defect segmentation model, which is beneficial to improving the accuracy and efficiency of defect segmentation.

[0186] In a possible implementation manner, the transformation module 802 is used to:

[0187] Randomly sample the target angle from the defect angle interval;

[0188] In the first mask image, the target area is rotated according to the target angle to obtain the second mask image.

[0189] In a possible implementation manner, the transformation module 802 is used to:

[0190] Randomly sample the target size from the defect size range;

[0191] In the first mask image, the size of the target area is transformed into the target size to obtain the second mask image.

[0192] In a possible implementation manner, the transformation module 802 is used to:

[0193] In response to the second image having the same size as the first mask image, randomly sampling the first mask image to obtain the target position; in the first mask image, translating the target area to the target position to obtain the second mask image; or,

[0194] In response to the second image and the first mask image having different sizes, a target position is obtained by random sampling in the second image; the size of the first mask image is scaled to the same size as the second image; and in the scaled first mask image, the target area is translated to the target position to obtain the second mask image.

[0195] In one possible implementation, based on Figure 8 The device is composed of:

[0196] The truncation module is configured to, in response to an edge of the translated target area exceeding an edge of the first mask image, truncate the translated target area based on the edge of the first mask image.

[0197] In one possible implementation, based on Figure 8 The fusion module 803 comprises:

[0198] an acquisition unit, configured to acquire a transformed target area based on the second mask image;

[0199] A superimposing unit, used for superimposing the transformed target area onto the second image to obtain a third image;

[0200] The smoothing unit is used to perform smoothing on the third image to obtain the target image.

[0201] In one possible implementation, the superposition unit is used to:

[0202] The transformed target area and the second image are subjected to Poisson image fusion to obtain the third image.

[0203] All the above optional technical solutions can be arbitrarily combined to form optional embodiments of the present disclosure, and will not be described in detail here.

[0204] It should be noted that: the image processing device provided in the above embodiment only uses the division of the above functional modules as an example to illustrate when processing images. In actual applications, the above functions can be assigned to different functional modules as needed, that is, the internal structure of the computer device is divided into different functional modules to complete all or part of the functions described above. In addition, the image processing device provided in the above embodiment and the image processing method embodiment belong to the same concept, and the specific implementation process is detailed in the image processing method embodiment, which will not be repeated here.

[0205] Fig. 9 This is a schematic diagram of the structure of a computer device provided in an embodiment of the present application. Please refer to Fig. 9 , the terminal 900 is taken as an example for explanation. Optionally, the device type of the terminal 900 includes: a smart phone, a tablet computer, an MP3 player (Moving Picture Experts Group Audio Layer III), an MP4 (Moving Picture Experts Group Audio Layer IV), a laptop or a desktop computer. The terminal 900 may also be called a user device, a portable terminal, a laptop terminal, a desktop terminal, or other names.

[0206] Typically, the terminal 900 includes a processor 901 and a memory 902 .

[0207] Optionally, the processor 901 includes one or more processing cores, such as a 4-core processor, an 8-core processor, etc. Optionally, the processor 901 is implemented in at least one hardware form of DSP (Digital Signal Processing), FPGA (Field-Programmable Gate Array), and PLA (Programmable Logic Array). In some embodiments, the processor 901 includes a main processor and a coprocessor. The main processor is a processor for processing data in the awake state, also known as a CPU (Central Processing Unit); the coprocessor is a low-power processor for processing data in the standby state. In some embodiments, the processor 901 is integrated with a GPU (Graphics Processing Unit), which is responsible for rendering and drawing the content to be displayed on the display screen. In some embodiments, the processor 901 also includes an AI (Artificial Intelligence) processor, which is used to process computing operations related to machine learning.

[0208] In some embodiments, the memory 902 includes one or more computer-readable storage media, and optionally, the computer-readable storage medium is non-transitory. Optionally, the memory 902 also includes a high-speed random access memory, and a non-volatile memory, such as one or more disk storage devices, flash memory storage devices. In some embodiments, the non-transitory computer-readable storage medium in the memory 902 is used to store at least one program code, and the at least one program code is used to be executed by the processor 901 to implement the image processing method provided in each embodiment of the present application.

[0209] In some embodiments, the terminal 900 may further optionally include: a peripheral device interface 903 and at least one peripheral device. The processor 901, the memory 902 and the peripheral device interface 903 may be connected via a bus or a signal line. Each peripheral device may be connected to the peripheral device interface 903 via a bus, a signal line or a circuit board. Specifically, the peripheral device includes: at least one of a radio frequency circuit 904, a display screen 905, a camera assembly 906, an audio circuit 907 and a power supply 909.

[0210] The peripheral device interface 903 may be used to connect at least one peripheral device related to I / O (Input / Output) to the processor 901 and the memory 902. In some embodiments, the processor 901, the memory 902, and the peripheral device interface 903 are integrated on the same chip or circuit board; in some other embodiments, any one or two of the processor 901, the memory 902, and the peripheral device interface 903 are implemented on a separate chip or circuit board, which is not limited in this embodiment.

[0211] The radio frequency circuit 904 is used to receive and transmit RF (Radio Frequency) signals, also known as electromagnetic signals. The radio frequency circuit 904 communicates with communication networks and other communication devices through electromagnetic signals. The radio frequency circuit 904 converts electrical signals into electromagnetic signals for transmission, or converts received electromagnetic signals into electrical signals. Optionally, the radio frequency circuit 904 includes: an antenna system, an RF transceiver, one or more amplifiers, a tuner, an oscillator, a digital signal processor, a codec chipset, a user identity module card, and the like. Optionally, the radio frequency circuit 904 communicates with other terminals through at least one wireless communication protocol. The wireless communication protocol includes, but is not limited to: a metropolitan area network, various generations of mobile communication networks (2G, 3G, 4G and 5G), a wireless local area network and / or a WiFi (Wireless Fidelity) network. In some embodiments, the radio frequency circuit 904 also includes circuits related to NFC (Near Field Communication), which is not limited in this application.

[0212] The display screen 905 is used to display a UI (User Interface). Optionally, the UI includes graphics, text, icons, videos, and any combination thereof. When the display screen 905 is a touch display screen, the display screen 905 also has the ability to collect touch signals on the surface or above the surface of the display screen 905. The touch signal can be input to the processor 901 as a control signal for processing. Optionally, the display screen 905 is also used to provide virtual buttons and / or virtual keyboards, also known as soft buttons and / or soft keyboards. In some embodiments, the display screen 905 is one, and the front panel of the terminal 900 is set; in other embodiments, the display screen 905 is at least two, which are respectively set on different surfaces of the terminal 900 or are folded; in some other embodiments, the display screen 905 is a flexible display screen, which is set on the curved surface or folded surface of the terminal 900. Even, optionally, the display screen 905 is set to a non-rectangular irregular shape, that is, a special-shaped screen. Optionally, the display screen 905 is made of materials such as LCD (Liquid Crystal Display) and OLED (Organic Light-Emitting Diode).

[0213] The camera assembly 906 is used to capture images or videos. Optionally, the camera assembly 906 includes a front camera and a rear camera. Typically, the front camera is arranged on the front panel of the terminal, and the rear camera is arranged on the back of the terminal. In some embodiments, there are at least two rear cameras, which are any one of a main camera, a depth of field camera, a wide-angle camera, and a telephoto camera, so as to realize the fusion of the main camera and the depth of field camera to realize the background blur function, the fusion of the main camera and the wide-angle camera to realize panoramic shooting and VR (Virtual Reality) shooting function or other fusion shooting functions. In some embodiments, the camera assembly 906 also includes a flash. Optionally, the flash is a monochrome temperature flash, or a dual-color temperature flash. A dual-color temperature flash refers to a combination of a warm light flash and a cold light flash, which is used for light compensation at different color temperatures.

[0214] In some embodiments, the audio circuit 907 includes a microphone and a speaker. The microphone is used to collect sound waves from the user and the environment, and convert the sound waves into electrical signals and input them into the processor 901 for processing, or input them into the radio frequency circuit 904 to achieve voice communication. For the purpose of stereo acquisition or noise reduction, there are multiple microphones, which are respectively arranged at different parts of the terminal 900. Optionally, the microphone is an array microphone or an omnidirectional acquisition microphone. The speaker is used to convert the electrical signal from the processor 901 or the radio frequency circuit 904 into sound waves. Optionally, the speaker is a traditional film speaker, or a piezoelectric ceramic speaker. When the speaker is a piezoelectric ceramic speaker, it can not only convert the electrical signal into sound waves audible to humans, but also convert the electrical signal into sound waves inaudible to humans for purposes such as ranging. In some embodiments, the audio circuit 907 also includes a headphone jack.

[0215] The power supply 909 is used to power various components in the terminal 900. Optionally, the power supply 909 is an alternating current, a direct current, a disposable battery, or a rechargeable battery. When the power supply 909 includes a rechargeable battery, the rechargeable battery supports wired charging or wireless charging. The rechargeable battery is also used to support fast charging technology.

[0216] In some embodiments, the terminal 900 further includes one or more sensors 910 . The one or more sensors 910 include, but are not limited to: an acceleration sensor 911 , a gyroscope sensor 912 , a pressure sensor 913 , an optical sensor 915 , and a proximity sensor 916 .

[0217] In some embodiments, the acceleration sensor 911 detects the magnitude of acceleration on the three coordinate axes of the coordinate system established by the terminal 900. For example, the acceleration sensor 911 is used to detect the components of gravity acceleration on the three coordinate axes. Optionally, the processor 901 controls the display screen 905 to display the user interface in a horizontal view or a vertical view according to the gravity acceleration signal collected by the acceleration sensor 911. The acceleration sensor 911 is also used to collect motion data of games or users.

[0218] In some embodiments, the gyroscope sensor 912 detects the body direction and rotation angle of the terminal 900, and the gyroscope sensor 912 cooperates with the acceleration sensor 911 to collect the user's 3D actions on the terminal 900. The processor 901 implements the following functions based on the data collected by the gyroscope sensor 912: motion sensing (such as changing the UI according to the user's tilt operation), image stabilization during shooting, game control, and inertial navigation.

[0219] Optionally, the pressure sensor 913 is arranged on the side frame of the terminal 900 and / or the lower layer of the display screen 905. When the pressure sensor 913 is arranged on the side frame of the terminal 900, it can detect the user's holding signal of the terminal 900, and the processor 901 performs left and right hand recognition or shortcut operation according to the holding signal collected by the pressure sensor 913. When the pressure sensor 913 is arranged on the lower layer of the display screen 905, the processor 901 controls the operability controls on the UI interface according to the user's pressure operation on the display screen 905. The operability controls include at least one of a button control, a scroll bar control, an icon control, and a menu control.

[0220] The optical sensor 915 is used to collect the ambient light intensity. In one embodiment, the processor 901 controls the display brightness of the display screen 905 according to the ambient light intensity collected by the optical sensor 915. Specifically, when the ambient light intensity is high, the display brightness of the display screen 905 is increased; when the ambient light intensity is low, the display brightness of the display screen 905 is decreased. In another embodiment, the processor 901 also dynamically adjusts the shooting parameters of the camera assembly 906 according to the ambient light intensity collected by the optical sensor 915.

[0221] The proximity sensor 916, also called a distance sensor, is usually arranged on the front panel of the terminal 900. The proximity sensor 916 is used to collect the distance between the user and the front of the terminal 900. In one embodiment, when the proximity sensor 916 detects that the distance between the user and the front of the terminal 900 is gradually decreasing, the processor 901 controls the display screen 905 to switch from the screen-on state to the screen-off state; when the proximity sensor 916 detects that the distance between the user and the front of the terminal 900 is gradually increasing, the processor 901 controls the display screen 905 to switch from the screen-off state to the screen-on state.

[0222] Those skilled in the art will understand that Fig. 9 The structure shown in the figure does not constitute a limitation on the terminal 900, and the terminal 900 may include more or less components than those shown in the figure, or combine some components, or adopt a different component arrangement.

[0223] Fig.101 is a schematic diagram of the structure of a computer device provided in an embodiment of the present application. The computer device 1000 may have relatively large differences due to different configurations or performances. The computer device 1000 includes one or more processors (Central Processing Units, CPU) 1001 and one or more memories 1002, wherein the memory 1002 stores at least one computer program, and the at least one computer program is loaded and executed by the one or more processors 1001 to implement the image processing methods provided in the above-mentioned embodiments. Optionally, the computer device 1000 also has components such as a wired or wireless network interface, a keyboard, and an input and output interface for input and output. The computer device 1000 also includes other components for implementing device functions, which will not be described in detail here.

[0224] In an exemplary embodiment, a computer-readable storage medium is also provided, such as a memory including at least one computer program, and the at least one computer program can be executed by a processor in a terminal to complete the image processing method in each of the above embodiments. For example, the computer-readable storage medium includes ROM (Read-Only Memory), RAM (Random-Access Memory), CD-ROM (Compact Disc Read-Only Memory), magnetic tape, floppy disk, and optical data storage device.

[0225] In an exemplary embodiment, a computer program product or computer program is also provided, including one or more program codes, which are stored in a computer-readable storage medium. One or more processors of a computer device can read the one or more program codes from the computer-readable storage medium, and the one or more processors execute the one or more program codes, so that the computer device can execute to complete the image processing method in the above embodiment.

[0226] A person of ordinary skill in the art will understand that all or part of the steps to implement the above embodiments can be completed by hardware, or can be completed by instructing related hardware through a program. Optionally, the program is stored in a computer-readable storage medium. Optionally, the above-mentioned storage medium is a read-only memory, a disk or an optical disk, etc.

[0227] The above description is only an optional embodiment of the present application and is not intended to limit the present application. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of the present application shall be included in the protection scope of the present application.

Claims

1. An image processing method, characterized in that: The method comprises: Acquire a first image and a first mask image, wherein the first image is a surface texture image of a first product, and the first mask image is used to identify a target area where defects are located in the first image; In response to the second image having the same size as the first mask image, a target position is obtained by randomly sampling from the first mask image; in the first mask image, the target area is translated to the target position, and the second image is a surface texture image of a second product; In response to the second image and the first mask image having different sizes, randomly sampling the second image to obtain a target position; scaling the size of the first mask image to the same size as the second image; and translating the target area to the target position in the scaled first mask image; In response to an edge of the translated target area exceeding an edge of the first mask image, truncating the translated target area based on the edge of the first mask image to obtain a second mask image; wherein an area of ​​the target area after truncation is greater than or equal to one third of an area of ​​the target area before truncation; Based on the second mask image, fusing the target area with the second image to obtain a target image; Based on the multiple target images and the multiple second mask images, the parameters of the initial segmentation model are adjusted to obtain a defect segmentation model, and the defect segmentation model is used to identify the target area where the defects are located in the surface texture image of the second product.

2. The method according to claim 1, characterized in that Before obtaining the second mask image, the method further includes: Randomly sample the target angle from the defect angle interval; In the first mask image, the target area is rotationally transformed according to the target angle.

3. The method according to claim 1, characterized in that: Before obtaining the second mask image, the method further includes: Randomly sample the target size from the defect size range; In the first mask image, the size of the target area is transformed into the target size.

4. The method according to claim 1, characterized in that The step of fusing the target area with the second image based on the second mask image to obtain the target image comprises: Based on the second mask image, obtaining a transformed target area; superimposing the transformed target area onto the second image to obtain a third image; The third image is smoothed to obtain the target image.

5. The method according to claim 4, characterized in that The step of superimposing the transformed target area onto the second image to obtain a third image comprises: Poisson image fusion is performed on the transformed target area and the second image to obtain the third image.

6. An image processing device, characterized in that: The device comprises: An acquisition module, used to acquire a first image and a first mask image, wherein the first image is a surface texture image of a first product, and the first mask image is used to identify a target area where defects are located in the first image; a transformation module, configured to, in response to the second image having the same size as the first mask image, randomly sample the target position from the first mask image; in the first mask image, translate the target area to the target position, wherein the second image is a surface texture image of the second product; in response to the second image having a different size from the first mask image, randomly sample the target position in the second image; scale the size of the first mask image to the same size as the second image; and in the scaled first mask image, translate the target area to the target position; a truncation module, configured to, in response to an edge of the translated target area exceeding an edge of the first mask image, truncate the translated target area based on the edge of the first mask image to obtain a second mask image; wherein an area of ​​the target area after truncation is greater than or equal to one third of an area of ​​the target area before truncation; a fusion module, configured to fuse the target area with a second image based on the second mask image to obtain a target image, wherein the second image is a surface texture image of a second product; A parameter adjustment module is used to adjust the parameters of the initial segmentation model based on the multiple target images and the multiple second mask images to obtain a defect segmentation model, wherein the defect segmentation model is used to identify the target area where the defect is located in the surface texture image of the second product.

7. The device according to claim 6, characterized in that The transformation module is further used for: Randomly sample the target angle from the defect angle interval; In the first mask image, the target area is rotationally transformed according to the target angle.

8. The device according to claim 6, characterized in that The transformation module is further used for: Randomly sample the target size from the defect size range; In the first mask image, the size of the target area is transformed into the target size.

9. The device according to claim 6, characterized in that The fusion module includes: an acquisition unit, configured to acquire a transformed target area based on the second mask image; a superimposing unit, configured to superimpose the transformed target area onto the second image to obtain a third image; A smoothing unit is used to perform smoothing on the third image to obtain the target image.

10. The device according to claim 9, characterized in that The superposition unit is used for: Poisson image fusion is performed on the transformed target area and the second image to obtain the third image.

11. A computer device, characterized in that: The computer device includes one or more processors and one or more memories, wherein at least one computer program is stored in the one or more memories, and the at least one computer program is loaded and executed by the one or more processors to implement the image processing method according to any one of claims 1 to 5.

12. A storage medium, characterized in that: The storage medium stores at least one computer program, and the at least one computer program is loaded and executed by the processor to implement the image processing method according to any one of claims 1 to 5.