An AI logic drawing method based on artificial intelligence
By analyzing the local diffusion area and texture feature values of the image in AI logic drawing, and adaptively adding noise, the problem of the diffusion model's insufficient recognition ability of image data is solved, and the quality and efficiency of AI drawing are improved.
Patent Information
- Application Number
- CN202410422544.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-04-09
- Publication Date
- 2024-10-29
- Estimated Expiration
- 2044-04-09
AI Technical Summary
The existing diffusion model has low ability to identify main information in image data, resulting in low quality AI logic drawing and poor calculation efficiency.
By obtaining the images to be diffused in the training set, determining the adaptive sliding window, analyzing the texture feature values of the local diffusion area, classifying it into high information areas and low information areas, and determining the probability of pixels being added with noise based on the local complexity. Noise processing improves the feature learning ability of the diffusion model.
It improves the diffusion model's ability to identify main information, improves the accuracy and calculation efficiency of AI drawing results, and enhances the model's robustness and drawing quality.
Smart Images

Figure CN118537423B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of image generation, and in particular to an AI logic drawing method based on artificial intelligence. Background Art
[0002] AI (Artificial Intelligence) drawing technology has made significant progress in recent years, especially with the development of generative adversarial networks and diffusion models, which enable AI to generate high-quality images or artworks. In the process of using AI drawing technology related products, users hope to accurately generate target images, but the feature learning ability of diffusion models in the training phase of existing AI drawing is low, resulting in poor quality of AI logic drawing.
[0003] In the diffusion model, noise processing is the core part of the forward diffusion process. In the forward diffusion stage, the simulated data gradually transforms from an ordered state to a disordered state, that is, noise is gradually added to the data until the data becomes pure noise, thereby completing the addition of noise in the forward diffusion stage. However, the existing diffusion model lacks an attention mechanism when extracting and generating features, resulting in low recognition of the main information in the data in the forward diffusion stage, weak feature learning ability of the diffusion model, poor computational efficiency of diffusion model training, and further resulting in poor quality of AI logic drawing results. Summary of the invention
[0004] In order to solve the technical problem that the existing diffusion model has a low ability to identify the main information in the image data, resulting in low quality of AI logic drawing generation results, the purpose of the present invention is to provide an AI logic drawing method based on artificial intelligence, and the technical solution adopted is as follows:
[0005] An embodiment of the present invention provides an AI logic drawing method based on artificial intelligence, the method comprising the following steps:
[0006] Obtaining a training set corresponding to the diffusion model of the AI drawing, wherein the training data in the training set is an image to be diffused;
[0007] Determine an adaptive sliding window according to different gray levels and image resolutions corresponding to the image to be diffused, wherein the adaptive sliding window slides on the image to be diffused to obtain each local diffusion area;
[0008] Determine the texture feature value of the local diffusion area according to the grayscale difference between each pixel point in the local diffusion area and its surrounding pixels and the number of all grayscale levels in the local diffusion area; classify all local diffusion areas into high information areas and low information areas according to the texture feature value;
[0009] Determine the local complexity of the image to be diffused according to the texture feature values of each high-information region and each low-information region;
[0010] Determine the probability of adding noise to each pixel in the image to be diffused according to the local complexity; obtain the diffused image according to the probability of adding noise to each pixel and the image to be diffused;
[0011] All diffused images are combined for model training to obtain a trained AI drawing model, and specific drawing requirements are input into the trained AI drawing model to generate AI drawing results.
[0012] Furthermore, the step of determining the adaptive sliding window according to different gray levels and image resolutions corresponding to the image to be diffused includes:
[0013] Grayscale processing is performed on the image to be diffused to obtain the grayscale image to be diffused, and then each grayscale level in the grayscale image to be diffused is determined;
[0014] Analyze the complexity of the image according to each gray level in the gray image to be diffused, and determine the first window size index of the gray image to be diffused;
[0015] First, perform square root processing on the image resolution, then calculate the ratio of the square root value to the hyperparameter, and use the ratio as the second window size indicator of the grayscale image to be diffused;
[0016] The size of the adaptive sliding window of the grayscale image to be diffused is determined by combining the first window size index and the second window size index, thereby obtaining the adaptive sliding window.
[0017] Furthermore, analyzing the image complexity according to each gray level in the gray image to be diffused and determining the first window size index of the gray image to be diffused includes:
[0018] The number of all gray levels in the gray image to be diffused is determined, the number of all gray levels is normalized to obtain normalized values, and then negative correlation processing is performed on the normalized values to obtain a first window size index of the gray image to be diffused.
[0019] Furthermore, the step of combining the first window size index and the second window size index to determine the size of the adaptive sliding window of the grayscale image to be diffused includes:
[0020] The product of the first window size index and the second window size index is calculated, and the product of the two window size indexes is rounded up to obtain the size of the adaptive sliding window.
[0021] Furthermore, the determining of the texture feature value of the local diffusion area according to the grayscale difference between each pixel point in the local diffusion area and its surrounding pixels and the number of all grayscale levels in the local diffusion area includes:
[0022] Determine the pixels within the eight neighborhoods of each pixel in the local diffusion area as neighborhood pixels;
[0023] For each pixel in the local diffusion area, the average value of the grayscale difference between the pixel and its corresponding neighboring pixels is calculated as the texture factor;
[0024] The average value of the texture factors of all pixels in the local diffusion area is calculated, and then the product of the average value of the texture factors of all pixels and the number of all gray levels in the local diffusion area is calculated, the product is normalized, and the normalized value is used as the texture feature value of the local diffusion area.
[0025] Furthermore, the classification of all local diffusion areas into high-information areas and low-information areas according to texture feature values includes:
[0026] A texture feature threshold is set. When the texture feature value of the local diffusion area is greater than the texture feature threshold, the local diffusion area is determined to be a high-information area; when the texture feature value of the local diffusion area is not greater than the texture feature threshold, the local diffusion area is determined to be a low-information area.
[0027] Furthermore, determining the local complexity of the image to be diffused according to the texture feature values of each high-information region and each low-information region includes:
[0028]
[0029] Where F is the local complexity of the image to be diffused, Norm is the linear normalization function, K is the number of high-information regions, k is the serial number of the high-information region, U is the preset number of local diffusion regions around the high-information region, u is the serial number of the local diffusion region around the high-information region, and C is the default value of the local diffusion region. 1,k is the texture feature value of the kth high information area, C 1,k,u is the texture feature value of the uth local diffusion area around the kth high information area, R is the number of low information areas, r is the serial number of the low information area, C 1,r is the texture feature value of the rth low information area, || is the absolute value function.
[0030] Furthermore, determining the probability of adding noise to each pixel in the image to be diffused according to the local complexity includes:
[0031] Determine the noise density level of the high information area in the image to be diffused according to the local complexity;
[0032] According to the preset ratio of the noise density level of the high-information area and the preset ratio of the low-information area, the probability of adding noise to each pixel in each high-information area and each low-information area of the image to be diffused is determined.
[0033] Further, the method of determining the probability of adding noise to each pixel in each high-information area and each low-information area of the image to be diffused according to the preset ratio of the noise density level in the high-information area and the preset ratio in the low-information area includes:
[0034] For each pixel in any high-information area, the preset ratio of the noise density level in the high-information area is used as the numerator of the first ratio, the value obtained by adding the preset ratio of the noise density level in the high-information area and the preset ratio in the low-information area is used as the denominator of the first ratio, and the first ratio is used as the probability that noise is added to each pixel in the high-information area;
[0035] For each pixel in any low-information area, the preset ratio of the noise density level in the low-information area is used as the numerator of the second ratio, the sum of the preset ratio of the noise density level in the high-information area and the preset ratio in the low-information area is used as the denominator of the second ratio, and the second ratio is used as the probability of noise being added to each pixel in the low-information area.
[0036] Furthermore, obtaining the diffused image according to the probability of adding noise to each pixel and the image to be diffused includes:
[0037] A random number matrix of the same size as the image to be diffused is generated by a random generator, and the random number matrix is compared with a noise probability map; wherein the noise probability map is composed of the probability of adding noise to each pixel in the image to be diffused;
[0038] For each pixel, if the random number is less than the probability of adding noise to the pixel at the corresponding position, noise is added to the pixel at the corresponding position, otherwise noise is not added to the pixel at the corresponding position to obtain a noise mask, and the noise mask is added to the image to be diffused to obtain the diffused image.
[0039] The present invention has the following beneficial effects:
[0040] The present invention provides an AI logic drawing method based on artificial intelligence. The method improves the noise adding process in the forward diffusion stage of the diffusion model required for AI drawing, adds an attention mechanism in the forward diffusion stage, and adaptively adds a suitable amount of noise to regions with different information complexity, which is beneficial to enhance the ability to distinguish the main information in the diffused image, thereby improving the feature learning ability of the diffusion model and further improving the computational efficiency of the AI drawing model training. The efficient training process can make better use of limited data sets, and improve the generalization ability and drawing quality of the model through transfer learning, data enhancement and other technologies, thereby further improving the accuracy of the image generation results. First, the image to be diffused is divided into different local diffusion areas, and the recognition and analysis of the model training data is performed based on the local areas, which is conducive to the subsequent distinction of the attention size of different local areas in the overall image; secondly, the texture complexity of the local diffusion area is quantified by the grayscale difference between the pixel and its surrounding pixels and the number of all grayscale levels, which improves the numerical accuracy of the determined texture eigenvalues and provides data support for the subsequent calculation of local complexity. At the same time, the reference value of high-information areas and low-information areas classified by texture eigenvalues with better accuracy is higher; then, the probability of adding noise to each pixel in the image to be diffused is determined by the local complexity, which can achieve different added noise densities for the images to be diffused with different local complexities, which is conducive to learning more features in high-information areas, enhancing the robustness of the diffusion model and the overall quality of the generated diffusion image; finally, model training is performed based on diffused images with richer and more accurate feature information, which can effectively improve the drawing effect of the AI drawing model and the accuracy of the AI logical drawing results. BRIEF DESCRIPTION OF THE DRAWINGS
[0041] In order to more clearly illustrate the technical solutions and advantages in the embodiments of the present invention or the prior art, the drawings required for use in the embodiments or the prior art descriptions are briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0042] Figure 1 This is a flow chart of an AI logic drawing method based on artificial intelligence according to an embodiment of the present invention;
[0043] Figure 2 Flow chart of a process for determining a texture feature value of a local diffusion region in an embodiment of the present invention. DETAILED DESCRIPTION
[0044] In order to further explain the technical means and effects adopted by the present invention to achieve the predetermined invention purpose, the specific implementation methods, structures, features and effects of the technical solutions proposed by the present invention are described in detail below in conjunction with the accompanying drawings and preferred embodiments. In the following description, different "one embodiment" or "another embodiment" does not necessarily refer to the same embodiment. In addition, specific features, structures or characteristics in one or more embodiments may be combined in any suitable form.
[0045] Unless defined otherwise, all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the art to which this invention belongs.
[0046] The diffusion model is a key technology used in the training stage of AI drawing. By improving the diffusion model required for the training stage of AI drawing, that is, processing the data of the training set during the diffusion model training, improving the diffusion model's ability to recognize key information, and enhancing the accuracy of obtaining the feature information contained in the diffused image, it helps to improve the drawing quality of AI logic drawing.
[0047] Specifically, an embodiment of the present invention provides an AI logic drawing method based on artificial intelligence, such as Figure 1 As shown, the following steps are included:
[0048] S1, obtain the training set corresponding to the diffusion model of AI drawing.
[0049] In this embodiment, the training data in the training set are images to be diffused, which can be a set of high-quality image data. High-quality image data means that the images are diverse, that is, images covering a wide range of themes, styles and scenes. The purpose of obtaining high-quality image data is to ensure that the diffusion model can learn rich features and patterns. The number of images to be diffused in the training set can be set by the implementer according to the actual situation, and is not specifically limited.
[0050] So far, this embodiment has completed the acquisition of image data required for diffusion model training.
[0051] S2, determining an adaptive sliding window according to different gray levels and image resolutions corresponding to the image to be diffused, and sliding the adaptive sliding window on the image to be diffused to obtain various local diffusion areas.
[0052] It should be noted that this embodiment mainly performs preprocessing on the image to be diffused, and needs to perform data analysis on the image to be diffused to determine the area in the image to be diffused that needs additional noise addition. Additional noise addition is a relative concept. The attention size is used as the evaluation standard. The density of noise added to the area with large attention is greater than the density of noise added to the area with small attention. Therefore, it is necessary to quantify the attention size, that is, to determine the texture feature value of the local area.
[0053] Before distinguishing the texture feature values of different local areas in the image to be diffused, it is necessary to set a sliding window to determine the local area. The local screen contents of different images to be diffused may be different, and the resolutions of different images to be diffused may also be different, so the size of the sliding window needs to be adaptively adjusted according to the pixel features and resolution of the image to be diffused.
[0054] In this embodiment, the process of determining each local diffusion area of each image to be diffused is the same. For ease of understanding, taking any image to be diffused in the training set as an example, the specific implementation process of determining each local diffusion area may include:
[0055] The first step is to grayscale the image to be diffused to obtain the grayscale image to be diffused, and then determine each gray level in the grayscale image to be diffused.
[0056] In this embodiment, the implementation method of converting the image to be diffused into a grayscale image includes but is not limited to a weighted average method, an average method, a maximum method, and a minimum method. The implementation process of grayscale processing is a prior art and will not be elaborated in detail here.
[0057] It should be noted that the grayscale image has only one channel. Grayscale processing of the diffusion image can reduce the amount of data that the model needs to process, which is conducive to reducing computational complexity and memory requirements.
[0058] The second step is to analyze the complexity of the image according to each gray level in the gray image to be diffused, and determine the first window size index of the gray image to be diffused.
[0059] In this embodiment, the number of all gray levels in the gray image to be diffused is determined, the number of all gray levels is normalized to obtain normalized values, and then negative correlation processing is performed on the normalized values to obtain a first window size index of the gray image to be diffused.
[0060] Among them, grayscale refers to each grayscale value in the grayscale image to be diffused; the implementation method of normalization processing includes but is not limited to linear normalization, mean normalization, nonlinear normalization and decimal calibration normalization, etc. The implementation process of normalization processing is a prior art and will not be elaborated in detail here; the negative correlation relationship indicates that the dependent variable will decrease as the independent variable increases, and the dependent variable will increase as the independent variable decreases. It can be a subtraction relationship, a division relationship, etc., which is determined by actual application.
[0061] In the third step, the image resolution is first squared, and then the ratio of the squared value to the hyperparameter is calculated, and the ratio is used as the second window size indicator of the grayscale image to be diffused.
[0062] In this embodiment, the square root processing and the division by the hyperparameter are both for reducing the size of the adaptive sliding window to make the size of the sliding window more reasonable.
[0063] Among them, the hyperparameter can be set to 10, and the implementer can set the size of the hyperparameter according to the actual situation.
[0064] The fourth step is to determine the size of the adaptive sliding window of the grayscale image to be diffused by combining the first window size index and the second window size index, thereby obtaining the adaptive sliding window.
[0065] In this embodiment, since the first window size index and the second window size index are both positively correlated with the size of the adaptive sliding window, the size of the adaptive sliding window can be obtained by calculating the product of the first window size index and the second window size index and rounding up the product of the two window size indexes.
[0066] Among them, the positive correlation relationship means that the dependent variable will increase as the independent variable increases, and the dependent variable will decrease as the independent variable decreases. The specific relationship can be a multiplication relationship, an addition relationship, or the power of an exponential function, which is determined by actual application.
[0067] As an example, the calculation formula for the size of the adaptive sliding window may be:
[0068] Where W is the size of the adaptive sliding window, is the rounding function, exp is the exponential function with the natural constant as the base, n is the number of all gray levels in the gray image to be diffused, 256 is the number of gray levels from 0 to 255, To normalize the number of all gray levels, In order to perform negative correlation processing on the normalized values, is the first window size index of the grayscale image to be diffused, K1×K2 is the image resolution of the grayscale image to be diffused, 10 is the hyperparameter, is the second window size index of the grayscale image to be diffused.
[0069] In the calculation formula of the size of the adaptive sliding window, because the size of the sliding window is determined by the side length, and the unit of the side length is the number of pixels, the larger the image resolution is, the more pixels the grayscale image to be diffused contains. Increasing the size of the sliding window can make the window contain more local information, which is beneficial to the subsequent analysis of local image feature information. Therefore, the larger the image resolution K1×K2 of the grayscale image to be diffused is, the larger the size W of the adaptive sliding window should be; for the texture performance of the overall picture of the image to be diffused, it can be analyzed by the distribution of grayscale values. The more the number of different grayscale values in the image, the more details the image has, and the more complex the texture performance corresponding to the more details is, the smaller the adaptive sliding window should be, so as to more finely traverse the grayscale image to be diffused and obtain more accurate local feature information, so as to better analyze the complex texture of the grayscale image to be diffused. Therefore, the more the number n of all gray levels in the grayscale image to be diffused is, the larger the size W of the adaptive sliding window should be; since the unit of the size of the adaptive sliding window is the number of pixels, it is necessary to Rounding is performed, and this embodiment chooses to round up.
[0070] After obtaining the size of the adaptive sliding window, an adaptive sliding window of size W×W is constructed, and the adaptive sliding window is made to slide on the image to be diffused. The starting point of the sliding can be the upper left corner of the image to be diffused, and the sliding path can be S-shaped. The sliding step length of each time is the size of an adaptive sliding window. When the adaptive sliding window traverses the entire grayscale image to be diffused, the sliding area of each sliding can be obtained, and the sliding area of each sliding is used as the local diffusion area, thereby obtaining each local diffusion area.
[0071] The image property of each local diffusion area is a grayscale image; the sliding starting point, sliding path and sliding step size of the adaptive sliding window can be set by the implementer according to the actual situation, without specific limitation.
[0072] So far, this embodiment obtains each local diffusion area corresponding to the image to be diffused by analyzing the image resolution and gray value distribution of the image to be diffused.
[0073] S3, determining the texture feature value of the local diffusion area according to the grayscale difference between each pixel point in the local diffusion area and its surrounding pixels and the number of all grayscale levels in the local diffusion area; and classifying all local diffusion areas into high-information areas and low-information areas according to the texture feature values.
[0074] It should be noted that each local diffusion area shows different picture content. By analyzing the grayscale distribution differences in local diffusion areas, the complexity of the local diffusion areas can be quantified. The complexity is defined as the texture eigenvalue. The larger the texture eigenvalue, the higher the amount of information contained in the corresponding local diffusion area, and the greater the possibility that the corresponding local diffusion area is a high-information area. Therefore, all local diffusion areas can be classified and processed by texture eigenvalues.
[0075] In the first step, the texture feature value of the local diffusion area is determined according to the grayscale difference between each pixel in the local diffusion area and its surrounding pixels and the number of all grayscale levels in the local diffusion area.
[0076] The size of the texture eigenvalue is related to the complexity of the information reflected in the local diffusion area. The higher the information complexity, the more different gray levels are needed to constitute the image information. Therefore, when there are more gray levels in the local diffusion area, the larger the texture eigenvalue; the content of the image is roughly divided into foreground and background, and the main information is mostly concentrated in the foreground part. There are more textures in the foreground part, and the distribution of pixels around the pixels on the edge of the texture has obvious regionality; when the more pixels with edge characteristics are distributed in the local diffusion area, it means that there are more edges in the local diffusion area, and the more edges, the more textures. Therefore, when the grayscale difference between a pixel and its neighboring pixels is greater, the more pixels with edge characteristics are, and the larger the texture eigenvalue of the local diffusion area is.
[0077] In this embodiment, the calculation process of the texture feature value of each local diffusion area is consistent. For ease of understanding, any local diffusion area is taken as an example to determine the texture feature value of the local diffusion area, such as Figure 2 As shown, the specific implementation process may include:
[0078] In the first sub-step, pixels within the eight neighborhoods of each pixel in the local diffusion area are determined as neighborhood pixels.
[0079] In order to facilitate the analysis of the distribution of pixels around a pixel, it is necessary to obtain the pixels around the pixel. In this embodiment, the pixels within the eight neighborhoods of the pixel are taken as neighborhood pixels. Each pixel has its corresponding neighborhood pixels, and the maximum number of neighborhood pixels corresponding to a single pixel is 8.
[0080] In the second sub-step, for each pixel point in the local diffusion area, the average value of the grayscale difference between the pixel point and its corresponding neighboring pixels is calculated as the texture factor.
[0081] In this embodiment, the grayscale difference between a pixel point and its corresponding neighboring pixel points can be calculated by the absolute value of the difference between the grayscale values. The greater the grayscale difference between a pixel point and its surrounding adjacent pixel points, the more obvious the edge characteristics of the pixel point, and the greater the texture factor of the pixel point.
[0082] It is worth noting that the existing edge detection algorithm cannot accurately detect all edges. For example, the same edge parameters can detect all edges in a local diffusion area, but the edge detection effect in another local diffusion area is not ideal. Therefore, this sub-step directly uses the edge characteristics to analyze the edge characteristics of each pixel to determine the texture factor.
[0083] The third sub-step is to calculate the average value of the texture factors of all pixels in the local diffusion area, calculate the product of the average value of the texture factors of all pixels and the number of all gray levels in the local diffusion area, normalize the product, and use the normalized value as the texture feature value of the local diffusion area.
[0084] In this embodiment, the texture factor, the number of gray levels and the information complexity of the local diffusion area are positively correlated, so the two indicators can be combined by multiplication. In order to facilitate the subsequent classification of local areas with different information levels, the product needs to be normalized to ensure that the value range of the texture feature value is between 0 and 1, which helps to determine the high-information area and the low-information area through the threshold judgment method.
[0085] As an example, the calculation formula of the texture feature value of the local diffusion area can be:
[0086] Where C1 is the texture feature value of the local diffusion area, Norm is the linear normalization function, M is the number of pixels in the local diffusion area, m is the serial number of the pixel in the local diffusion area, I is the number of neighboring pixels of the pixel in the local diffusion area, i is the serial number of the neighboring pixels of the pixel in the local diffusion area, and G is m,i is the gray value of the ith neighboring pixel of the mth pixel in the local diffusion area, G m is the gray value of the mth pixel in the local diffusion area, || is the absolute value function, is the texture factor of the mth pixel in the local diffusion area, and n′ is the number of all gray levels in the local diffusion area.
[0087] In the calculation formula of the texture eigenvalue of the local diffusion area, the larger the texture factor is, the more complex the texture features in the local diffusion area are, the more information the local diffusion area contains, and the larger the texture eigenvalue of the local diffusion area is; the more the number of all gray levels in the local diffusion area is, the clearer the image hierarchy of the local diffusion area is, the higher the credibility of the edge features is, and the larger the texture eigenvalue is.
[0088] It should be noted that each local diffusion area has its corresponding texture eigenvalue. The reference value of the texture eigenvalues determined by combining two different angles is greater, which is conducive to improving the reliability of the subsequent classification of high-information areas and low-information areas based on the texture eigenvalues.
[0089] In the second step, all local diffusion regions are classified into high-information regions and low-information regions according to the texture feature values.
[0090] The local diffusion area with a larger texture eigenvalue has a more complex texture, that is, the local diffusion area contains more image information, and the area containing more image information is more likely to be a high-information area. In the forward diffusion process of the diffusion model, assuming that the number of noise points in the image distribution is fixed, when the noise points are evenly distributed in the high-information area and the low-information area for training, the high-information area learns more features, so it is reasonable to consider distributing more noise points to the high-information area, that is, the area containing more image information should have a greater noise density. Therefore, it is necessary to classify all local diffusion areas based on texture eigenvalues, and the specific implementation process may include:
[0091] In this embodiment, a texture feature threshold is set. When the texture feature value of the local diffusion area is greater than the texture feature threshold, the local diffusion area is determined to be a high-information area; when the texture feature value of the local diffusion area is not greater than the texture feature threshold, the local diffusion area is determined to be a low-information area.
[0092] Among them, the texture feature threshold can be set to 0.8, and the implementer can set the size of the texture feature threshold according to the actual situation without specific limitation; the high information area can refer to the foreground distribution area in the image to be diffused, and the low information area can refer to the background distribution area in the image to be diffused.
[0093] So far, this embodiment has obtained various high-information regions and various low-information regions of the image to be diffused by analyzing the texture features of the local region of the image.
[0094] S4, determining the local complexity of the image to be diffused according to the texture feature values of each high-information region and each low-information region.
[0095] It should be noted that the pixels in the high-information area are more likely to add additional noise, and the distribution of high-information areas in different images to be diffused is different, so different images to be diffused have different diffusion noise densities in the forward diffusion stage, that is, the more concentrated the distribution of high-information areas is, the higher the diffusion noise density of the image to be diffused is. By analyzing the texture feature values of information areas of different complexities, quantifying the distribution of high-information areas, and determining the local complexity, the more concentrated the distribution of high-information areas in the image to be diffused, the higher the local complexity, and the greater the diffusion noise density. Therefore, it is necessary to quantify the local complexity of the image to be diffused based on the distribution of high-information areas in the image to be diffused, and determining the local complexity provides data support for the subsequent determination of the noise density level of the image to be diffused.
[0096] In this embodiment, the texture eigenvalue can characterize the texture complexity of the local diffusion area. The texture eigenvalue of the high-information area is relatively large, and the areas with high texture eigenvalues are mostly distributed together, that is, the high-information area has continuity, so the distribution concentration of the high-information area can be quantified by analyzing the difference in texture eigenvalues between the high-information area and the surrounding areas; the low-information area often contains less picture content, such as the background part. For a picture, the background is often used to set off the foreground, so the main information is still displayed in the foreground part, then comparing the high-information area and the low-information area, the texture feature of the low-information area is smaller than that of the high-information area.
[0097] As an example, the calculation formula of the local complexity of the image to be diffused may be:
[0098]
[0099] Where F is the local complexity of the image to be diffused, Norm is the linear normalization function, K is the number of high-information regions, k is the serial number of the high-information region, U is the preset number of local diffusion regions around the high-information region, u is the serial number of the local diffusion region around the high-information region, and C is the default value of the local diffusion region. 1,k is the texture feature value of the kth high information area, C 1,k,u is the texture feature value of the uth local diffusion area around the kth high information area, R is the number of low information areas, r is the serial number of the low information area, C 1,r is the texture feature value of the rth low information area, || is the absolute value function.
[0100] In the calculation formula of local complexity, the preset number of local diffusion areas located around the high information area can be set to 8, and the implementer can set the size of the preset number according to the specific actual situation; the linear normalization process is to facilitate the subsequent determination of the noise density level; the smaller the difference in texture eigenvalues between the high information area and other local diffusion areas around it, the greater the possibility that the high information area is surrounded by high information areas, that is, the more obvious the trend of concentrated distribution of high information areas is, the greater the local complexity is; the smaller the average value of the texture eigenvalues of all low information areas is, the less obvious the texture features of the background part of the image to be diffused are, and the greater the local complexity of the image to be diffused will be; the local complexity can characterize the concentration of the distribution of high information areas in the image to be diffused, the higher the concentration of the high information area distribution, the smaller the texture eigenvalue of the low information area, the greater the information complexity of the local area of the image to be diffused, and the local complexity can be used to subsequently determine the probability of noise being added to each pixel in the image to be diffused; the higher the local complexity is, the more likely the high information area in the image to be diffused is to be clustered, and the less likely it is to be scattered.
[0101] So far, this embodiment determines the local complexity of the entire image to be diffused by analyzing the texture feature values of the high-information area and the low-information area.
[0102] S5, determining the probability of adding noise to each pixel in the image to be diffused according to the local complexity; obtaining the diffused image according to the probability of adding noise to each pixel and the image to be diffused.
[0103] In the first step, the probability of adding noise to each pixel in the image to be diffused is determined according to the local complexity.
[0104] In order to introduce the attention mechanism into the diffusion model and improve the feature learning ability, it is necessary to determine the probability of adding noise to the pixel based on the local complexity. The purpose of determining the probability of adding noise to the pixel is to provide data support for the subsequent acquisition of the diffused image. The specific implementation process may include:
[0105] In the first sub-step, the noise density level of the high information area in the image to be diffused is determined according to the local complexity.
[0106] In this embodiment, the local complexity can determine the density level of the diffusion noise in the forward diffusion stage. Each level has a different amount of additional noise added to the high information area compared to the previous level, and multiple noises are added each time.
[0107] Specifically, several noise density levels are set, and according to the local complexity, the image to be diffused corresponding to the local complexity is divided into the corresponding noise density level, and the noise density level of the high information area in the image to be diffused is determined.
[0108] Assuming the local complexity is 0.5, the noise density level is set to 5 levels, with each interval of 0.2 being one level, specifically: 0.1-0.2 is the first level, 0.3-0.4 is the second level, 0.5-0.6 is the third level, 0.7-0.8 is the fourth level, and 0.9-1 is the fifth level. Therefore, the noise density level of the high information area in the image to be diffused with a local complexity of 0.5 belongs to the third level.
[0109] Among them, the preset ratios of the five noise density levels in the high information area can be set to 1.2, 1.4, 1.6, 1.8 and 2, while the preset ratio in the low information area can be set to 1. The preset ratios of different noise density levels can be used for subsequent calculations of the probability of adding noise. The larger the preset ratio, the greater the probability of obtaining noise. The noise density level and the preset ratio of the noise density level can be set by the implementer according to the actual situation, without specific limitation.
[0110] In the second sub-step, the probability of adding noise to each pixel in each high-information area and each low-information area of the image to be diffused is determined according to the preset ratio of the noise density level in the high-information area and the preset ratio in the low-information area.
[0111] In this embodiment, when analyzing the probability of adding noise to pixels in the image to be diffused, the probability of adding noise to pixels in regions with different noise density levels is different. The higher the noise density level, the higher the preset ratio, and the greater the probability of adding noise to pixels in the corresponding region. However, the probability of adding noise to pixels in the same region is the same.
[0112] On the one hand, by adding more noise points to areas with rich information, the diffusion model can learn to restore images under more complex noise conditions, which helps to improve the robustness in the face of real noise; on the other hand, by reducing noise points in areas with less information, it helps to maintain the consistency and integrity of the image and avoid unnecessary details in areas of less importance, thereby improving the overall quality of the image generated in subsequent AI drawing. Among them, areas with rich information are high-information areas, and areas with less information are low-information areas.
[0113] First, for each pixel in any high-information area, the preset ratio of the noise density level in the high-information area is used as the numerator of the first ratio, the sum of the preset ratio of the noise density level in the high-information area and the preset ratio in the low-information area is used as the denominator of the first ratio, and the first ratio is used as the probability of noise being added to each pixel in the high-information area.
[0114] As an example, the probability of adding noise to each pixel in the high information area can be calculated as:
[0115] P(S1)=S1 / (S1+S2); wherein P(S1) is the probability of noise being added to each pixel in the high-information area, S1 is the preset ratio of the noise density level in the high-information area, S2 is the preset ratio in the low-information area, and S1 / (S1+S2) is the first ratio.
[0116] Secondly, for each pixel in any low-information area, the preset ratio of the noise density level in the low-information area is used as the numerator of the second ratio, the sum of the preset ratio of the noise density level in the high-information area and the preset ratio in the low-information area is used as the denominator of the second ratio, and the second ratio is used as the probability of noise being added to each pixel in the low-information area.
[0117] As an example, the calculation formula for the probability of adding noise to each pixel in the low information area can be:
[0118] P(S2)=S2 / (S1+S2); wherein P(S2) is the probability that noise is added to each pixel in the low information area, and S2 / (S1+S2) is the second ratio.
[0119] It is worth mentioning that the preset ratio is set to calculate the probability of added noise. For example, the preset ratios of the low-information area and the high-information area at the third noise density level are 1 and 1.6, and the corresponding probability ratio is 0.38:0.62. Therefore, when there are 100 noise points that can be added to the low-information area and the high-information area at the third noise density level, 62 noise points may be added to the high-information area at the third noise density level, while 38 noise points may be added to the low-information area.
[0120] In the second step, the diffused image is obtained according to the probability of adding noise to each pixel and the image to be diffused.
[0121] In this embodiment, a noise probability map is first created. The noise probability map has the same size as the image to be diffused. The noise probability map is composed of the probability of adding noise to each pixel in the image to be diffused. In the forward diffusion stage, noise is generated for each pixel according to the noise probability map, specifically:
[0122] A random number matrix of the same size as the image to be diffused is generated by a random generator, and the random number matrix is compared with the noise probability map; for each pixel, if the random number is less than the probability of adding noise to the pixel at the corresponding position, noise is added to the pixel at the corresponding position, otherwise, noise is not added to the pixel at the corresponding position, and a noise mask is obtained. The noise mask is added to the image to be diffused to obtain the diffused image. The value range of each random number in the random number matrix is between 0 and 1.
[0123] It should be noted that the probability of adding noise to pixels in high-information areas is high, while the probability of adding noise to pixels in low-information areas is low. Therefore, more noise can be added to the corresponding positions of high-information areas, and less noise can be added to the corresponding positions of low-information areas. The distribution of noise is controlled by the noise probability mapping. The attention mechanism is introduced into the training data of the diffusion model, which is conducive to improving the feature learning ability during model training.
[0124] So far, this embodiment obtains each diffused image corresponding to the training set, and completes the forward diffusion stage of the diffusion model.
[0125] S6, combining all the diffused images to perform model training to obtain a trained AI drawing model, inputting specific drawing requirements into the trained AI drawing model, and generating an AI drawing result.
[0126] After the forward diffusion stage, all diffused images are first subjected to feature extraction, including the identification of graphic features such as edges, textures, shapes, etc. from noise data; then, the extracted features are integrated with existing artistic style, color distribution and other information to form a comprehensive feature database; secondly, the feature database is used to train the AI drawing model. During the training process, deep learning techniques such as convolutional neural networks or generative adversarial networks are applied to learn the complex relationships between features; at the same time, the performance of the AI drawing model is optimized by adjusting the network structure and hyperparameters to ensure that the model can accurately capture and reproduce artistic features.
[0127] It should be noted that all diffused images obtained based on the attention mechanism, while improving the rationality of noise addition, also enhance the computational efficiency of the diffusion model in the forward diffusion stage and the ability to recognize the main information in the image data, further improving the drawing quality of AI logic drawing.
[0128] After completing the training of the AI drawing model, the reverse diffusion process is performed, that is, a clear image is gradually restored from the noisy data. The AI drawing model needs to gradually remove the noise through the learned features and reconstruct an artistic image; on the basis of image reconstruction, the style transfer technology is further applied to integrate the specific artistic style into the generated image; the quality of the generated image is subsequently evaluated, and objective evaluation indicators (such as image clarity, color richness, etc.) and subjective evaluation (such as feedback from testers) can be used; according to the evaluation results, the AI drawing model is iteratively optimized to continuously improve the accuracy and artistry of the drawing and obtain a trained AI drawing model.
[0129] Finally, an interactive interface is designed and provided for users, allowing them to input specific style requirements or creative descriptions. The AI drawing model performs personalized drawing creation based on the input content. The AI drawing method not only increases user participation, but also makes the generated artwork more diverse and personalized.
[0130] Thus, this embodiment has achieved a relatively high-quality AI logic drawing by improving the forward diffusion stage of the diffusion model.
[0131] The embodiment of the present invention provides an AI logic drawing method based on artificial intelligence, which improves the diffusion model required for use in the training stage of AI drawing, that is, preprocesses the training data required by the model and adds an attention mechanism, which enhances the ability to identify the main information in the image data, thereby improving the feature learning ability of the diffusion model, and further improving the drawing quality and generalization ability of the AI logic drawing involving the diffusion model.
[0132] The embodiments described above are only used to illustrate the technical solutions of the present invention, rather than to limit the same. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that the technical solutions described in the aforementioned embodiments may still be modified, or some of the technical features may be replaced by equivalents. Such modifications or replacements do not deviate the essence of the corresponding technical solutions from the scope of the technical solutions of the embodiments of the present invention, and should all be included in the protection scope of the present invention.
Claims
1. An AI logic drawing method based on artificial intelligence, characterized in that: The following steps are involved: Obtaining a training set corresponding to the diffusion model of the AI drawing, wherein the training data in the training set is an image to be diffused; Determine an adaptive sliding window according to different gray levels and image resolutions corresponding to the image to be diffused, wherein the adaptive sliding window slides on the image to be diffused to obtain each local diffusion area; Determine the texture feature value of the local diffusion area according to the grayscale difference between each pixel point in the local diffusion area and its surrounding pixels and the number of all grayscale levels in the local diffusion area; classify all local diffusion areas into high information areas and low information areas according to the texture feature value; Determine the local complexity of the image to be diffused according to the texture feature values of each high-information region and each low-information region; Determine the probability of adding noise to each pixel in the image to be diffused according to the local complexity; According to the probability of adding noise to each pixel and the image to be diffused, the diffused image is obtained; All diffused images are combined for model training to obtain a trained AI drawing model, and specific drawing requirements are input into the trained AI drawing model to generate AI drawing results.
2. The AI logic drawing method based on artificial intelligence according to claim 1, characterized in that: The step of determining the adaptive sliding window according to different gray levels and image resolutions corresponding to the image to be diffused includes: Grayscale processing is performed on the image to be diffused to obtain the grayscale image to be diffused, and then each grayscale level in the grayscale image to be diffused is determined; Analyze the complexity of the image according to each gray level in the gray image to be diffused, and determine the first window size index of the gray image to be diffused; First, perform square root processing on the image resolution, then calculate the ratio of the square root value to the hyperparameter, and use the ratio as the second window size indicator of the grayscale image to be diffused; The size of the adaptive sliding window of the grayscale image to be diffused is determined by combining the first window size index and the second window size index, thereby obtaining the adaptive sliding window.
3. The AI logic drawing method based on artificial intelligence according to claim 2, characterized in that: The step of analyzing the image complexity according to each gray level in the gray image to be diffused and determining the first window size index of the gray image to be diffused includes: The number of all gray levels in the gray image to be diffused is determined, the number of all gray levels is normalized to obtain normalized values, and then negative correlation processing is performed on the normalized values to obtain a first window size index of the gray image to be diffused.
4. The AI logic drawing method based on artificial intelligence according to claim 3 is characterized in that: The step of combining the first window size index and the second window size index to determine the size of the adaptive sliding window of the grayscale image to be diffused comprises: The product of the first window size index and the second window size index is calculated, and the product of the two window size indexes is rounded up to obtain the size of the adaptive sliding window.
5. The AI logic drawing method based on artificial intelligence according to claim 2, characterized in that: Determining the texture feature value of the local diffusion area according to the grayscale difference between each pixel point in the local diffusion area and its surrounding pixels and the number of all grayscale levels in the local diffusion area includes: Determine the pixels within the eight neighborhoods of each pixel in the local diffusion area as neighborhood pixels; For each pixel in the local diffusion area, the average value of the grayscale difference between the pixel and its corresponding neighboring pixels is calculated as the texture factor; The average value of the texture factors of all pixels in the local diffusion area is calculated, and then the product of the average value of the texture factors of all pixels and the number of all gray levels in the local diffusion area is calculated, the product is normalized, and the normalized value is used as the texture feature value of the local diffusion area.
6. The AI logic drawing method based on artificial intelligence according to claim 5, characterized in that: The method of classifying all local diffusion areas into high information areas and low information areas according to texture feature values includes: A texture feature threshold is set. When the texture feature value of the local diffusion area is greater than the texture feature threshold, the local diffusion area is determined to be a high-information area; when the texture feature value of the local diffusion area is not greater than the texture feature threshold, the local diffusion area is determined to be a low-information area.
7. The AI logic drawing method based on artificial intelligence according to claim 1, characterized in that: The determining of the local complexity of the image to be diffused according to the texture feature values of each high-information region and each low-information region includes: Where F is the local complexity of the image to be diffused, Norm is the linear normalization function, K is the number of high-information regions, k is the serial number of the high-information region, U is the preset number of local diffusion regions around the high-information region, u is the serial number of the local diffusion region around the high-information region, and C is the default value of the local diffusion region. 1,k is the texture feature value of the kth high information area, C 1,k,u is the texture feature value of the uth local diffusion area around the kth high information area, R is the number of low information areas, r is the serial number of the low information area, C 1,r is the texture feature value of the rth low information area, || is the absolute value function.
8. The AI logic drawing method based on artificial intelligence according to claim 7, characterized in that: The step of determining the probability of adding noise to each pixel in the image to be diffused according to the local complexity includes: Determine the noise density level of the high information area in the image to be diffused according to the local complexity; According to the preset ratio of the noise density level of the high-information area and the preset ratio of the low-information area, the probability of adding noise to each pixel in each high-information area and each low-information area of the image to be diffused is determined.
9. The AI logic drawing method based on artificial intelligence according to claim 8, characterized in that: The method of determining the probability of adding noise to each pixel in each high-information area and each low-information area of the image to be diffused according to the preset ratio of the noise density level in the high-information area and the preset ratio in the low-information area includes: For each pixel in any high-information area, the preset ratio of the noise density level in the high-information area is used as the numerator of the first ratio, the value obtained by adding the preset ratio of the noise density level in the high-information area and the preset ratio in the low-information area is used as the denominator of the first ratio, and the first ratio is used as the probability that noise is added to each pixel in the high-information area; For each pixel in any low-information area, the preset ratio of the noise density level in the low-information area is used as the numerator of the second ratio, the sum of the preset ratio of the noise density level in the high-information area and the preset ratio in the low-information area is used as the denominator of the second ratio, and the second ratio is used as the probability of noise being added to each pixel in the low-information area.
10. The AI logic drawing method based on artificial intelligence according to claim 1, characterized in that: The step of obtaining the diffused image according to the probability of adding noise to each pixel and the image to be diffused comprises: A random number matrix of the same size as the image to be diffused is generated by a random generator, and the random number matrix is compared with a noise probability map; wherein the noise probability map is composed of the probability of adding noise to each pixel in the image to be diffused; For each pixel, if the random number is less than the probability of adding noise to the pixel at the corresponding position, noise is added to the pixel at the corresponding position, otherwise noise is not added to the pixel at the corresponding position to obtain a noise mask, and the noise mask is added to the image to be diffused to obtain the diffused image.
Citation Information
Patent Citations
Ultrasonic image denoising method based on spatial filtering
CN116205823A
Transformer welding seam quality detection method for image processing
CN116309579A
