Image picture edge extraction method and system based on AI model

By introducing spatial attention, channel attention and graph neural networks into the AI ​​model, combining the loss function and structure-maintaining regularization terms based on edge gradients, the edge extraction problem of inaccurate edge extraction in complex backgrounds and noise environments is solved, and higher accuracy and robustness are achieved.

CN119672056AInactive Publication Date: 2025-03-21YUNZHISHANG (XIAN) INTELLIGENT TECH CO LTD
View PDF 0 Cites 1 Cited by

Patent Information

Application Number
CN202510033140.7
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-01-09
Publication Date
2025-03-21
Estimated Expiration
Not applicable · inactive patent

AI Technical Summary

Technical Problem

Traditional image edge extraction methods are prone to edge fracture and false detection in complex backgrounds or images with high noise, and are not adaptable to different scenes, lighting conditions and noise levels, making it difficult to meet the needs of practical applications.

Method used

The image image edge extraction method based on AI model is used, and the model is trained by introducing spatial attention, channel attention and graph neural networks into the AI ​​model, and the loss function and structural maintenance regularization terms based on edge gradient are used to capture the global and local relationships between important edge regions and edges in the image.

Benefits of technology

It improves the accuracy and robustness of edge extraction, can better adapt to complex scenes and noise interference, maintain more detailed information, and the generated edge map is more continuous and complete.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119672056A_ABST
    Figure CN119672056A_ABST
Patent Text Reader

Abstract

The invention provides an image picture edge extraction method and system based on an AI model. The method comprises the steps that space attention, channel attention and a graph neural network are introduced into the AI model; training the AI model by using an edge gradient-based loss function and a structure preserving regularization item; the method comprises the following steps: inputting an image into an AI model, capturing an important edge region in the image through space attention in a forward propagation process of the model, enabling the model to adaptively adjust the weight according to the importance of different feature channels through channel attention, capturing global and local relationships between edges by using a graph neural network, further refining the edges, and obtaining a final image; and obtaining a refined edge graph. According to the method, the accuracy of edge detection is improved through a space and channel attention mechanism, the robustness of the model to complex images and noise is enhanced, and meanwhile, the model can more comprehensively consider the global and local relationships between the edges to obtain a finer and more accurate edge image due to the introduction of the graph neural network.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of image processing technology, and in particular to an image edge extraction method and system based on an AI model. Background Art

[0002] Image edge extraction is one of the basic tasks of computer vision and image processing, and is of great significance for subsequent image analysis, target detection, image segmentation and other tasks. Edge extraction technology can extract key geometric features such as contours and lines from complex images. This information is crucial for understanding image content and identifying target objects.

[0003] In the field of image edge extraction, traditional technologies usually use edge detection algorithms such as Canny edge detection, Sobel operator, and Prewitt operator. These methods detect edges based on the gradient change of image grayscale values. Although they have the advantages of simple calculation and convenient implementation, they still have the following defects: traditional edge detection algorithms are prone to edge breakage and false detection in images with complex backgrounds or more noise, which affects the accuracy of edge extraction; they are not adaptable to images with different scenes, different lighting conditions, and different noise levels, and are prone to performance fluctuations. Especially in practical applications, due to the diversity and complexity of image acquisition conditions, the robustness of existing technologies is difficult to meet the requirements; in the process of edge extraction, how to maintain the detailed information of the edge is an important issue. Traditional technologies often only focus on the position and shape of the edge, but ignore the global and local relationship between the edges, resulting in the extracted edges being too smooth or broken, and losing important detailed information. Summary of the invention

[0004] Based on this, the purpose of the present invention is to propose an image edge extraction method and system based on an AI model to solve the above-mentioned problems.

[0005] According to the present invention, a method for extracting image edges based on an AI model is provided, the method comprising:

[0006] Introducing spatial attention, channel attention, and graph neural networks into AI models;

[0007] The AI ​​model is trained using an edge gradient-based loss function and a structure-preserving regularization term.

[0008] The image is input into the trained AI model. During the forward propagation of the model, the important edge areas in the image are captured through spatial attention, and the model adaptively adjusts the weights according to the importance of different feature channels through channel attention to obtain the image edge. The image edge is regarded as a graph structure, and the graph neural network is used to capture the global and local relationships between the edges, further refine the edges, and obtain a refined edge graph.

[0009] Furthermore, in the forward propagation process of the model, the important edge areas in the image are captured by spatial attention, and the model is adaptively adjusted according to the importance of different feature channels through channel attention to obtain the image edge, including:

[0010] Perform preliminary feature extraction on the input image through the convolutional layer of the convolutional neural network to generate a preliminary feature map containing image spatial information and feature channel information;

[0011] Based on the preliminary feature map, calculating the attention weight at each spatial position to obtain a spatial attention weight, and multiplying the spatial attention weight by the preliminary feature map element by element to obtain a spatially weighted feature map, which is set as a first feature map;

[0012] Based on the first feature map, calculate the attention weight of each feature channel to obtain the channel attention weight, and multiply the channel attention weight by the first feature map channel by channel to obtain a channel-weighted feature map, which is set as the second feature map;

[0013] The second feature map is input into the edge detection layer to be processed by the edge detection layer to output an initial edge map, wherein the initial edge map contains edge information in the image.

[0014] Furthermore, the image edges are regarded as graph structures, and the graph neural network is used to capture the global and local relationships between the edges, and the edges are further refined to obtain a refined edge graph, including:

[0015] The edges in the initial edge graph are used as nodes in the graph structure, and the connection relationships between the edges are used as edges to construct a basic graph structure;

[0016] Based on the basic graph structure, the connection weights between nodes are adjusted according to the local feature similarities of the nodes to construct an adaptive graph structure;

[0017] The adaptive graph structure is input into the graph neural network to update the state of each node. In the updating process of each node in the graph neural network, an attention mechanism is introduced to dynamically weight the contribution of different neighboring nodes, and the global and local relationships between edges are captured through information transmission and aggregation between nodes.

[0018] After multiple iterative updates of the graph neural network, a refined edge map is obtained.

[0019] Furthermore, based on the basic graph structure, the connection weights between nodes are adjusted according to the local feature similarity of the nodes to construct an adaptive graph structure, including:

[0020] For each node v i ∈V, extract local features and represent them as feature vector f i , the local features include gradient changes and texture consistency;

[0021] Define a similarity measurement function s(f i , f p ), used to calculate the two nodes v i and v p The feature similarity between them;

[0022] Traverse all edges in the graph (v i , v p )∈E;

[0023] For each edge, calculate the two nodes v i and v p The feature similarity between i , f p );

[0024] Dynamically adjust the edge weight w according to the similarity value and the preset threshold τ ip :

[0025] If s(f i , f p )>τ, then set the edge weight w ip =gs(f i , f p ), enhanced connection, where g is an amplification factor;

[0026] If s(f i , f p )≤τ, then set w ip =0, disconnect;

[0027] According to the adjusted edge weights, an adaptive graph structure G′=(V, E′, W′) is constructed, where V is a set of nodes, E′ is an adjusted edge set, and W′ is an edge weight set.

[0028] Furthermore, the adaptive graph structure is input into the graph neural network to update the state of each node. In the updating process of each node in the graph neural network, an attention mechanism is introduced to dynamically weight the contribution of different neighboring nodes, and the global and local relationships between edges are captured through information transmission and aggregation between nodes, including:

[0029] For each node v in the graph neural network i , initialize its hidden state

[0030] For each iteration step t, the following operations are performed:

[0031] For node v i and each of its neighbor nodes v j ∈N(i), calculate the attention coefficient Where N(i) represents the node v i The neighbor node set of is calculated as:

[0032]

[0033] Among them, a is an attention vector, a T represents the transpose of a, that is, the transpose of the attention vector, W t is the weight matrix of the tth step, For node v i The hidden state at step t-1 is is the neighbor node v j In the hidden state of step t-1, || represents the vector concatenation operation, and LeakyReLU is the activation function;

[0034] The attention coefficient is normalized by the softmax function to obtain the neighbor node v j For node v i Contribution weight

[0035] According to the normalized attention coefficient, the weighted aggregation node v i The hidden states of all neighboring nodes of node v are obtained i Neighbor aggregation information at step t The calculation formula is:

[0036]

[0037] Combine node v i Its own hidden state and neighbor aggregation information, update node v i The hidden state at step t The calculation formula is:

[0038]

[0039] Where σ is a nonlinear activation function, is for node v i The weight matrix for updating its own hidden state.

[0040] Furthermore, the use of the edge gradient-based loss function and the structure-preserving regularization term to train the AI ​​model includes:

[0041] Collect a large number of images containing different edge features and mark the real edges of the images;

[0042] Initialize the parameters of the model;

[0043] The labeled image data is input into the model, and after the forward propagation of the model, a refined edge map is generated;

[0044] Based on the generated refined edge map, the loss value of the model is calculated using an edge gradient-based loss function and a structure-preserving regularization term, wherein the loss value is used to measure the difference between the model prediction result and the true result and the degree of preservation of the model structure;

[0045] Through back propagation, the gradient of each parameter is calculated according to the loss value;

[0046] Use optimization algorithms to update the model's parameters to minimize the loss function value;

[0047] Repeat the training until the model training effect reaches the expected result.

[0048] Furthermore, the loss value of the model is calculated based on the generated refined edge map using a loss function based on edge gradient and a structure-preserving regularization term, including:

[0049] Calculate the gradient of the input image to get the first gradient. The calculation formula is:

[0050]

[0051] Among them, I is the input image picture, is the first gradient, i.e. the gradient of the image, (x, y) is the pixel coordinate in the image, are the components of the gradient vector of the image in the x and y directions respectively;

[0052] The gradient of the generated refined edge map is calculated to obtain the second gradient, and the calculation formula is:

[0053]

[0054] Among them, E predis the generated refined edge map, is the second gradient, i.e. the gradient of the generated refined edge map, are each component of the gradient vector of the generated refined edge map in the x and y directions;

[0055] According to the difference between the first gradient and the second gradient, the edge gradient loss is calculated, and the calculation formula is:

[0056]

[0057] Among them, L1 is the edge gradient loss, N is the total number of pixels, || || represents the Euclidean norm, is the gradient of the input image I at the i-th pixel, The generated refined edge graph E pred The gradient at the i-th pixel;

[0058] According to the difference between the generated refined edge map and the annotated true edge information, the structure-preserving regularization term is calculated, and the calculation formula is:

[0059]

[0060] Among them, L2 is the structure-preserving regularization term, is the gradient of the annotated true edge information at the i-th pixel;

[0061] The edge gradient loss and the structure-preserving regularization term are weighted and combined to calculate the total loss value, and the calculation formula is:

[0062] L total =L1+λL2,

[0063] Among them, L total is the total loss value, and λ is the weight coefficient of the regularization term.

[0064] The present invention also proposes an image edge extraction system based on an AI model, the system comprising:

[0065] Model building module: used to introduce spatial attention, channel attention, and graph neural networks into AI models;

[0066] Training module: used to train AI models using edge gradient-based loss functions and structure-preserving regularization terms;

[0067] Edge extraction module: used to input images into the trained AI model. During the forward propagation of the model, important edge areas in the image are captured through spatial attention, and through channel attention, the model adaptively adjusts weights according to the importance of different feature channels to obtain image edges. The image edges are regarded as graph structures, and graph neural networks are used to capture the global and local relationships between edges, further refine the edges, and obtain a refined edge graph.

[0068] In summary, the image edge extraction method based on the AI ​​model of the present invention can more accurately locate the important edge areas in the image by combining the spatial attention and channel attention mechanisms. In the forward propagation process of the model, the spatial attention mechanism will automatically focus on the important edge areas in the image, ignoring the background or noise, while the channel attention mechanism will adaptively adjust the weights according to the importance of the feature channel to enhance the ability to capture key edge features, which makes the model more robust when dealing with complex scenes or noise interference. And introduce the graph neural network into the AI ​​model, which can capture the global and local relationships between edges, so that more detailed information can be maintained during the edge extraction process. Compared with the traditional edge extraction method, which often only focuses on the changes in local pixels and ignores the overall correlation between edges, resulting in the problem of edge breakage or loss of details, the addition of the graph neural network makes the extracted edges more continuous and complete. The AI ​​model of the present invention performs well in edge extraction and can be widely used in image processing, computer vision, medical image analysis and other fields. For example, in medical image analysis, accurate edge extraction is crucial for the identification and segmentation of lesion areas.

[0069] During the AI ​​model training stage, using an edge gradient-based loss function can give higher penalties to edge areas, encouraging the model to locate edges more accurately, and adding a structure-preserving regularization term to the loss function can encourage the model to maintain the integrity of the image structure while extracting edges.

[0070] Additional aspects and advantages of the present invention will be given in part in the following description and in part will be obvious from the following description or will be learned through embodiments of the present invention. BRIEF DESCRIPTION OF THE DRAWINGS

[0071] The above and / or additional aspects and advantages of the present invention will become apparent and easily understood from the description of the embodiments in conjunction with the following drawings, in which:

[0072] Figure 1 This is a flow chart of an image edge extraction method based on an AI model according to Embodiment 1 of the present invention;

[0073] Figure 2 This is a system block diagram of an image edge extraction system based on an AI model according to Embodiment 2 of the present invention. DETAILED DESCRIPTION

[0074] In order to facilitate the understanding of the present invention, the present invention will be described more fully below with reference to the relevant drawings. Several embodiments of the present invention are given in the drawings. However, the present invention can be implemented in many different forms and is not limited to the embodiments described herein. On the contrary, the purpose of providing these embodiments is to make the disclosure of the present invention more thorough and comprehensive.

[0075] It should be noted that when an element is referred to as being "fixed to" another element, it may be directly on the other element or there may be a central element. When an element is considered to be "connected to" another element, it may be directly connected to the other element or there may be a central element at the same time. The terms "vertical", "horizontal", "left", "right" and similar expressions used herein are for illustrative purposes only.

[0076] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as those commonly understood by those skilled in the art of the present invention. The terms used herein in the specification of the present invention are only for the purpose of describing specific embodiments and are not intended to limit the present invention. The term "and / or" used herein includes any and all combinations of one or more related listed items.

[0077] Embodiment 1

[0078] See also Figure 1 The present invention proposes an image edge extraction method based on an AI model, the method comprising steps S101 to S103:

[0079] S101, introduces spatial attention, channel attention and graph neural networks into AI models.

[0080] It should be noted that the AI ​​model of this embodiment integrates spatial attention, channel attention and graph neural network. This design not only makes the model more computationally efficient when processing large-scale data, but also enables the model to better adapt to different tasks and data distributions by dynamically adjusting the weights of different positions and channels and capturing the complex relationship between features, thereby more accurately capturing the key edge information and features in the image.

[0081] The basis of the AI ​​model in this embodiment can be a deep neural network (DNN), which consists of one or more input layers, multiple hidden layers and an output layer. On this basis, a specific network structure is incorporated:

[0082] The feature extraction layer, which can be composed of multiple convolutional neural network (CNN) layers, is responsible for the preliminary extraction of local features of the image, such as edges, textures, and colors;

[0083] After the feature extraction layer, an attention mechanism layer is introduced, including the spatial attention mechanism and the channel attention mechanism. The spatial attention mechanism highlights the features of important positions in the image through weighted operations, and the channel attention mechanism dynamically adjusts the weights of each channel to enhance the feature information that contributes to the edge extraction task. This layer improves the edge feature extraction capability and robustness of the AI ​​model.

[0084] The edge detection layer performs preliminary edge detection based on the feature map output by the attention mechanism layer (the traditional edge detection algorithm or deep learning method can be used to generate an initial edge map containing image edge information). The goal is to identify the edge position in the image and provide initial edge information for the subsequent graph neural network layer.

[0085] There is also a graph neural network layer, which receives the initial edge graph as input and converts it into graph structure data, where the edges in the initial edge graph are regarded as nodes in the graph, and the relationship between nodes is determined according to the structure and characteristics of the initial edge graph, and the relationship between nodes (i.e., edges) is captured and modeled, allowing information transfer and aggregation between nodes. Through multiple iterations and updates, the edges are gradually refined, broken edges are connected, and noise and redundant information are removed. After being processed by the graph neural network layer, the model outputs a refined edge graph.

[0086] The overall architecture of the AI ​​model of this embodiment includes several key parts: input layer, feature extraction layer (such as CNN), attention mechanism layer (spatial attention and channel attention), edge detection layer, graph neural network layer and output layer.

[0087] S102, train the AI ​​model using an edge gradient-based loss function and a structure-preserving regularization term.

[0088] It should be noted that after the AI ​​model introduced spatial attention, channel attention and graph neural network, the AI ​​model was trained using an edge gradient-based loss function and a structure-preserving regularization term to improve the model's edge detection performance and maintain the overall structure and coherence of the edge graph.

[0089] During the optimization training process of the AI ​​model in this embodiment, a loss function based on edge gradient is used to calculate the gradient difference between the edge map generated by the model (i.e., the refined edge map) and the true edge map (which can be obtained by annotation) to evaluate the edge detection performance of the model. This loss function can focus more directly on the accuracy and clarity of the edge, which helps the model to better learn edge features during the training process. The specific operation is further described in detail in the specific implementation plan below. By minimizing the gradient difference between the two edge maps, the model can gradually learn a more accurate and clear edge representation. Compared with the traditional pixel-level loss function, the edge gradient-based loss function pays more attention to the structure and details of the edge, can improve the accuracy of edge detection, and can guide the model to pay more attention to the continuity and smoothness of the edge, reducing the generation of noise and pseudo-edges.

[0090] At the same time, a structure-preserving regularization term is used to constrain AI model parameters or prediction results to maintain the structural information of the edge graph. This regularization term helps prevent the model from overfitting noise or details during training, thereby maintaining the overall structure and coherence of the edge graph. During the training process, the structural difference measure between the edge graph generated by the model and the true edge graph (such as edge length, consistency of edge direction, etc.) can be calculated through the structure-preserving regularization term, and then this difference measure is added to the loss function as a regularization term. The specific operation is further described in detail in the specific implementation plan below. By minimizing the regularization term, the model can maintain the overall structure and coherence of the edge graph while learning edge features. The structure-preserving regularization term can prevent the model from generating overly complex or irregular edge graphs during training, thereby maintaining the simplicity and interpretability of the edges. It can also guide the model to pay more attention to the overall structure and coherence of the edge graph and reduce the impact of noise and pseudo-edges.

[0091] Finally, the AI ​​model can be trained by combining the edge gradient-based loss function with the structure-preserving regularization term in a weighted summation manner.

[0092] S103, input the image into the trained AI model. During the forward propagation of the model, the important edge areas in the image are captured through spatial attention, and the model is enabled to adaptively adjust the weights according to the importance of different feature channels through channel attention to obtain the image edge. The image edge is regarded as a graph structure, and the graph neural network is used to capture the global and local relationships between the edges, and the edges are further refined to obtain a refined edge graph.

[0093] It should be noted that inputting images into a trained AI model and capturing, enhancing, and refining image edges through techniques such as spatial attention, channel attention, and graph neural networks is an efficient and accurate edge detection method. This method not only improves the accuracy of edge detection, but also enhances the model's robustness to complex images and noise. At the same time, through the introduction of graph neural networks, the model can more comprehensively consider the global and local relationships between edges, thereby obtaining a more refined and accurate edge map.

[0094] During the forward propagation of the model, the spatial attention mechanism is used to identify important edge regions in the image. This can be achieved by calculating the correlation between each pixel or image block and the surrounding area. The area with high correlation is considered to be an important edge area. The spatial attention mechanism can make the model focus more on the key information in the image and improve the accuracy of edge detection. The channel attention mechanism is introduced to adaptively adjust the weights according to the importance of different feature channels. Each feature channel may represent different features in the image (such as color, texture, shape, etc.). The channel attention mechanism evaluates the importance of these features and assigns them different weights, thereby enhancing the model's sensitivity to key features. Through the above attention mechanism, the model can capture the edge information in the image more accurately and generate an initial edge map through the edge detection layer. This edge map may still contain some noise or inaccurate edges, but it has provided a good foundation for subsequent refinement processing.

[0095] The initial edges are considered as graph structures, and graph neural networks (GNNs) are used to capture the global and local relationships between edges. GNNs can learn the complex relationships between nodes and update node features through information transmission and updating between nodes. In this process, GNNs can take into account the interactions and influences between edges, so as to more accurately judge which edges are real and which may be noise or pseudo edges. Based on the global and local relationships captured by GNNs, the model refines the preliminary edge map, which includes removing noise edges, enhancing the coherence of real edges, and filling in missing edges. After refinement, the resulting edge map is more accurate, clear, and coherent, and can more accurately reflect the actual edge information in the image.

[0096] Based on step S101 to step S103, by combining the spatial attention and channel attention mechanisms, the important edge areas in the image can be more accurately located. In the forward propagation process of the model, the spatial attention mechanism will automatically focus on the important edge areas in the image, ignoring the background or noise, while the channel attention mechanism will adaptively adjust the weights according to the importance of the feature channel to enhance the ability to capture key edge features, which makes the model more robust when dealing with complex scenes or noise interference. And introduce a graph neural network in the AI ​​model, which can capture the global and local relationships between edges, so that more detailed information can be maintained during edge extraction. Compared with traditional edge extraction methods, which often only focus on changes in local pixels and ignore the overall correlation between edges, resulting in edge breakage or loss of details, the addition of a graph neural network makes the extracted edges more continuous and complete. The AI ​​model of the present invention performs well in edge extraction and can be widely used in image processing, computer vision, medical image analysis and other fields. For example, in medical image analysis, accurate edge extraction is crucial for the identification and segmentation of lesion areas.

[0097] During the AI ​​model training stage, using an edge gradient-based loss function can give higher penalties to edge areas, encouraging the model to locate edges more accurately, and adding a structure-preserving regularization term to the loss function can encourage the model to maintain the integrity of the image structure while extracting edges.

[0098] The following is a further detailed introduction to an image edge extraction method based on an AI model according to an embodiment of the present invention:

[0099] Further optionally, in step S103, in the forward propagation process of the model, the important edge areas in the image are captured by spatial attention, and the model is adaptively adjusted according to the importance of different feature channels by channel attention to obtain the image edge, including:

[0100] Perform preliminary feature extraction on the input image through the convolutional layer of the convolutional neural network to generate a preliminary feature map containing image spatial information and feature channel information;

[0101] Based on the preliminary feature map, calculating the attention weight at each spatial position to obtain a spatial attention weight, and multiplying the spatial attention weight by the preliminary feature map element by element to obtain a spatially weighted feature map, which is set as a first feature map;

[0102] Based on the first feature map, calculate the attention weight of each feature channel to obtain the channel attention weight, and multiply the channel attention weight by the first feature map channel by channel to obtain a channel-weighted feature map, which is set as the second feature map;

[0103] The second feature map is input into the edge detection layer to be processed by the edge detection layer to output an initial edge map, wherein the initial edge map contains edge information in the image.

[0104] It is understandable that the convolutional layer of the convolutional neural network first performs preliminary feature extraction on the input image. The convolutional layer can use the convolution kernel to slide on the image to extract local features of the image, such as edges, textures, and colors. These features are combined into a preliminary feature map, which contains the spatial information and feature channel information of the image. The preliminary feature map is the basis for subsequent attention mechanism processing and provides a preliminary representation of the image.

[0105] Based on the preliminary feature map, the attention weights at each spatial position are calculated to obtain the spatial attention weights, which can be implemented by an additional neural network (such as a small fully connected network or a convolutional network) that takes the preliminary feature map as input and outputs a weight map with the same spatial size as the preliminary feature map. The spatial attention weights are multiplied element-by-element with the preliminary feature map to obtain the spatially weighted feature map (the first feature map). In this way, important edge areas are given larger weights and thus enhanced, while unimportant background or noise areas are given smaller weights and thus suppressed. The spatial attention mechanism enables the model to focus more on the key areas in the image and improve the accuracy of edge detection.

[0106] Based on the first feature map, the attention weight of each feature channel is further calculated to obtain the channel attention weight, which can be achieved through global average pooling, fully connected layers and activation functions (such as Sigmoid or ReLU). Global average pooling compresses the spatial dimension of each feature channel into one value, and then the fully connected layer calculates the channel attention weight based on these values. The channel attention weight is multiplied by the first feature map channel by channel to obtain the channel-weighted feature map (second feature map). In this way, the model will adaptively adjust the weights according to the importance of different feature channels and further refine the key edge features. The channel attention mechanism enables the model to adaptively adjust the importance of different feature channels, thereby more flexibly processing different features in the image.

[0107] The second feature map is input into the edge detection layer to be processed by the layer and output the initial edge map. The edge detection layer can be a combination of a convolutional layer, a pooling layer, or an upsampling layer, and its purpose is to convert the extracted edge features into a clear edge representation. The initial edge map contains the edge information in the image and is the result of the model's preliminary edge detection of the input image, which can be used for subsequent refined edge detection.

[0108] This embodiment effectively captures important edge areas in the image during the forward propagation of the model by combining spatial attention and channel attention mechanisms, and adaptively adjusts the weights of feature channels. This mechanism improves the accuracy of edge detection and enables the model to process different features in the image more flexibly. The final output of the initial edge map provides strong support for the subsequent further refinement of edge detection tasks.

[0109] Further optionally, the image edges are regarded as graph structures, a graph neural network is used to capture the global and local relationships between the edges, and the edges are further refined to obtain a refined edge graph, including:

[0110] The edges in the initial edge graph are used as nodes in the graph structure, and the connection relationships between the edges are used as edges to construct a basic graph structure;

[0111] Based on the basic graph structure, the connection weights between nodes are adjusted according to the local feature similarities of the nodes to construct an adaptive graph structure;

[0112] The adaptive graph structure is input into the graph neural network to update the state of each node. In the updating process of each node in the graph neural network, an attention mechanism is introduced to dynamically weight the contribution of different neighboring nodes, and the global and local relationships between edges are captured through information transmission and aggregation between nodes.

[0113] After multiple iterative updates of the graph neural network, a refined edge map is obtained.

[0114] It can be understood that the edges in the initial edge graph are used as nodes in the graph structure, and the connection relationship between the edges is used as edges to convert the image edges into elements in the graph structure. The graph structure is constructed according to the spatial position, direction or other attributes of the edges.

[0115] Based on the basic graph structure, the connection weights between nodes are dynamically adjusted according to the local feature similarity of the nodes (such as gradient changes, texture consistency, etc.) to build an adaptive graph structure. This dynamic adjustment method can make the graph structure more consistent with the distribution and relationship of the actual edges and improve the accuracy of edge refinement. Specifically, a similarity measurement function can be introduced to evaluate the feature similarity between nodes, and the connection between nodes can be strengthened or weakened according to the similarity value. When the feature similarity of two nodes exceeds a certain threshold, the connection between them is strengthened; otherwise, the connection is weakened or disconnected. This mechanism can further refine the edges and highlight important edge features.

[0116] The adaptive graph structure is input into the graph neural network to update the state of each node. The graph neural network can capture the global and local relationships between nodes and update the representation of nodes through information transmission and aggregation, so as to make full use of the association information between image edges and improve the effect of edge refinement.

[0117] In the process of updating each node in the graph neural network, the attention mechanism is introduced to dynamically weight the contribution of different neighbor nodes. The attention mechanism can calculate the attention coefficient between the current node and each neighbor node, reflecting the importance of the neighbor node to the current node. This enables the model to pay more attention to important neighbor nodes and improve the accuracy of edge refinement.

[0118] After multiple iterative updates of the graph neural network, a refined edge map is obtained. The refined edge map more accurately reflects the actual edges in the image, with higher resolution and finer details.

[0119] This embodiment achieves edge refinement by treating image edges as graph structures and using graph neural networks and attention mechanisms to capture global and local relationships between edges. This mechanism can make full use of the association information between image edges to improve the accuracy and effect of edge refinement. At the same time, by dynamically adjusting the connection weights between nodes and introducing the attention mechanism, the model can process image edges more flexibly and accurately. The refined edge map finally generated has higher resolution and finer details, and can be widely used in image processing, computer vision, medical image analysis and other fields. For example, in medical image analysis, accurate edge extraction is crucial for the identification and segmentation of lesion areas.

[0120] Further optionally, based on the basic graph structure, adjusting the connection weights between nodes according to the local feature similarities of the nodes to construct an adaptive graph structure includes:

[0121] For each node v i ∈V, extract local features and represent them as feature vector f i , the local features include gradient changes and texture consistency;

[0122] Define a similarity measurement function s(f i , f p ), used to calculate the two nodes v i and v p The feature similarity between them;

[0123] Traverse all edges in the graph (v i , v p )∈E;

[0124] For each edge, calculate the two nodes v i and vp The feature similarity between i , f p );

[0125] Dynamically adjust the edge weight w according to the similarity value and the preset threshold τ ip :

[0126] If s(f i , f p )>τ, then set the edge weight w ip =gs(f i , f p ), enhanced connection, where g is an amplification factor;

[0127] If s(f i , f p )≤τ, then set w ip = 0 or a smaller value δ, disconnecting or weakening the connection;

[0128] According to the adjusted edge weights, an adaptive graph structure G′=(V, E′, W′) is constructed, where V is a set of nodes, E′ is an adjusted edge set, and W′ is an edge weight set.

[0129] It can be understood that for each node, its local features are extracted and expressed as feature vectors to quantify the local information of the node in the form of vectors. Local features include gradient changes and texture consistency, which are important indicators for describing the characteristics of image edges or regions. Gradient changes can reflect the sharp changes in pixel values ​​in the image, which are usually related to edges; while texture consistency can describe the uniformity or pattern of regions in the image. The selection of these features helps to accurately capture the similarities between nodes.

[0130] Define a similarity measurement function to calculate the feature similarity between two nodes. The similarity measurement function should have symmetry, non-negativity and certain measurement properties (such as satisfying the triangle inequality, etc.). These properties can ensure the accuracy and rationality of the similarity measurement.

[0131] Traverse all the edges in the graph, calculate the feature similarity and adjust the edge weight for each edge. Dynamically adjust the edge weight according to the similarity value and the preset threshold τ. If the similarity is greater than the threshold, the connection is enhanced (the weight can be increased by the amplification factor g); if the similarity is less than or equal to the threshold, the connection is disconnected or weakened (by setting the weight to 0 or a smaller value δ). This adjustment rule can make the graph structure more consistent with the distribution and relationship of actual edges or regions.

[0132] According to the adjusted edge weights, an adaptive graph structure G′=(V, E′, W′) is constructed. Where V is a set of nodes (the same as the basic graph structure), E′ is an adjusted edge set (may contain fewer or more edges, depending on the result of the weight adjustment), and W′ is an edge weight set (including the adjusted weight values). The adaptive graph structure can dynamically adjust the edge weights according to the local feature similarity of the nodes, thereby more accurately reflecting the association relationship between edges or regions in the image.

[0133] This embodiment can fully utilize the local information of nodes and accurately capture the correlation between edges or regions in the image by constructing an adaptive graph structure. At the same time, by dynamically adjusting the edge weights, the graph structure is made more flexible and adaptable, providing strong support and guarantee for refined edge detection.

[0134] Further optionally, the adaptive graph structure is input into a graph neural network, the state of each node is updated, and in the updating process of each node in the graph neural network, an attention mechanism is introduced to dynamically weight the contribution of different neighboring nodes, and the global and local relationships between edges are captured through information transmission and aggregation between nodes, including:

[0135] For each node v in the graph neural network i , initialize its hidden state

[0136] For each iteration step t (starting from 1), do the following:

[0137] For node v i and each of its neighbor nodes v j ∈N(i), calculate the attention coefficient Where N(i) represents the node v i The set of neighbor nodes of

[0138] Node v i Its neighbor node v j The calculation of the attention coefficient between can use various attention mechanisms, such as multi-head attention, dot product attention, etc. Taking dot product attention as an example, first, the node v i and v j The hidden state of t Transform, then concatenate the transformed vectors, and then use the transpose a of the attention vector a T Do a dot product with the concatenated vector, and finally get the attention coefficient through the LeakyReLU activation function. The specific calculation formula is:

[0139]

[0140] Among them, a is a learnable attention vector, a T represents the transpose of a, that is, the transpose of the attention vector, W t is the weight matrix of the tth step, For node v i The hidden state at step t-1 is is the neighbor node v j In the hidden state of step t-1, || represents the vector concatenation operation and LeakyReLU is the activation function.

[0141] The attention coefficient is normalized by the softmax function to obtain the neighbor node v j For node v i Contribution weight

[0142] According to the normalized attention coefficient, the weighted aggregation node v i The hidden states of all neighboring nodes of node v are obtained i Neighbor aggregation information at step t The calculation formula is:

[0143]

[0144] Combine node v i Its own hidden state and neighbor aggregation information, update node v i The hidden state at step t The calculation formula is:

[0145]

[0146] Where σ is a nonlinear activation function, is for node v i The weight matrix for updating its own hidden state.

[0147] It can be understood that for each node in the graph neural network, its hidden state is initialized, which is the starting point of the graph neural network iteration. The node state is updated in an iterative manner, and each iteration step t performs a series of operations to update the hidden states of all nodes to gradually capture the complex relationships between nodes.

[0148] For a node and each of its neighboring nodes, an attention coefficient is calculated, which represents the importance or relevance of the neighboring node to the node. By introducing the attention mechanism (note that the attention mechanism here does not refer to the spatial attention and channel attention introduced in the AI ​​model mentioned in the full text, which are introduced separately in the graph neural network), the model can dynamically weight the contributions of different neighboring nodes, thereby more accurately capturing the relationship between nodes. Various attention mechanisms can be used to calculate the attention coefficient, such as multi-head attention, dot product attention, etc.

[0149] The attention coefficient is normalized by the softmax function to obtain the contribution weight of the neighbor node to the node. According to the normalized attention coefficient, the hidden states of all neighbor nodes of the weighted aggregation node are obtained to obtain the neighbor aggregation information of the node at the tth step (current step). This information integrates the contribution of the neighbor nodes. The hidden state of the node at the tth step is updated by combining the node's own hidden state and the neighbor aggregation information, so that the node can consider its own features and neighbor features at the same time, thereby more accurately representing the state of the node.

[0150] This embodiment introduces an attention mechanism to dynamically weight the contributions of different neighbor nodes, and combines information transfer and aggregation between nodes to update the state of each node in the graph neural network and capture the global and local relationships between edges.

[0151] Further optionally, in step S102, the AI ​​model is trained using the edge gradient-based loss function and the structure-preserving regularization term, including:

[0152] Collect a large number of images containing different edge features and mark the real edges of the images;

[0153] Initialize the parameters of the model;

[0154] The annotated image data is input into the model, and after the forward propagation of the model (i.e., after the forward propagation of each layer in the input layer, feature extraction layer, spatial attention layer, channel attention layer, edge detection layer, graph neural network layer and output layer), a refined edge map is generated;

[0155] Based on the generated refined edge map, the loss value of the model is calculated using an edge gradient-based loss function and a structure-preserving regularization term, wherein the loss value is used to measure the difference between the model prediction result (i.e., the generated refined edge map) and the true edge map and the degree of preservation of the model structure;

[0156] Through back propagation, the gradient of each parameter is calculated according to the loss value;

[0157] Use optimization algorithms to update the model's parameters to minimize the loss function value;

[0158] Repeat the training until the model training effect reaches the expected result.

[0159] Understandably, a large number of image pictures containing different edge features are collected, and the real edges of these pictures are annotated. The annotated real edges will be used as the target of model prediction.

[0160] The annotated image data is input into the model, and the model calculates the predicted edge image through forward propagation. The specific propagation process is as follows: the input layer of the AI ​​model receives the input image data, and performs feature extraction on the input image through the feature extraction layer to extract the basic features in the image. The spatial attention layer performs spatial attention processing on the feature map output by the feature extraction layer to enhance the feature representation of key spatial positions, and the channel attention layer performs channel attention processing on the feature map to enhance the feature representation of key channels. Based on the feature map that has been processed with attention, edge detection is then performed through the edge detection layer to preliminarily generate an edge map, namely the initial edge map. Then, the graph neural network layer further refines the preliminarily generated edge map, and uses the structural information of the graph neural network to enhance the coherence and accuracy of the edge. Finally, the output layer outputs the final refined edge map.

[0161] Based on the generated refined edge graph, the loss value of the model is calculated using the edge gradient-based loss function and the structure-preserving regularization term. This loss function can focus on the gradient information of the edge, and at the same time, through the structure-preserving regularization term, it can maintain certain characteristics or constraints of the model structure to prevent the model from overfitting or improve the generalization ability of the model. The loss value of the model is calculated by combining the edge gradient-based loss function and the structure-preserving regularization term. This value reflects the difference between the current prediction result of the model and the actual result and the degree of preservation of the model structure.

[0162] Through the back propagation algorithm, the gradient of each parameter is calculated according to the value of the loss function. These gradients indicate the direction of the loss function with respect to the model parameters. And using optimization algorithms (such as gradient descent algorithm, Adam, etc.), the model parameters are updated to minimize the loss function value, so that the model's prediction results are closer to the real results.

[0163] Repeat the above steps until the model training effect reaches the expected result. During the training process, it is necessary to continuously adjust the model parameters, learning rate and other hyperparameters to optimize the performance of the model.

[0164] During the training process of the model, this embodiment introduces an edge gradient-based loss function and a structure-preserving regularization term to measure the difference between the model prediction results and the actual results and the degree of preservation of the model structure.

[0165] Further optionally, the method of calculating the loss value of the model based on the generated refined edge graph using a loss function based on edge gradient and a structure-preserving regularization term includes:

[0166] Calculate the gradient of the input image to get the first gradient. The calculation formula is:

[0167]

[0168] Among them, I is the input image picture, is the first gradient, i.e. the gradient of the image, (x, y) is the pixel coordinate in the image, are the components of the gradient vector of the image in the x and y directions respectively;

[0169] The gradient of the generated refined edge map is calculated to obtain the second gradient, and the calculation formula is:

[0170]

[0171] Among them, E pred is the generated refined edge map, is the second gradient, i.e. the gradient of the generated refined edge map, are each component of the gradient vector of the generated refined edge map in the x and y directions;

[0172] According to the difference between the first gradient and the second gradient, the edge gradient loss is calculated, and the calculation formula is:

[0173]

[0174] Among them, L1 is the edge gradient loss, N is the total number of pixels, || || represents the Euclidean norm, is the gradient of the input image I at the i-th pixel, The generated refined edge graph E pred The gradient at the i-th pixel;

[0175] According to the difference between the generated refined edge map and the annotated true edge information, the structure-preserving regularization term is calculated, and the calculation formula is:

[0176]

[0177] Among them, L2 is the structure-preserving regularization term, is the gradient of the annotated true edge information at the i-th pixel;

[0178] The edge gradient loss and the structure-preserving regularization term are weighted and combined to calculate the total loss value, and the calculation formula is:

[0179] Ltotal =L1+λL2,

[0180] Among them, L total is the total loss value, and λ is the weight coefficient of the regularization term.

[0181] It can be understood that the gradient of the input image I is calculated to obtain the first gradient, which is achieved by calculating the gradient vector of the image at each pixel, including the components in the x and y directions. At the same time, the gradient of the generated refined edge map is calculated to obtain the second gradient. And according to the difference between the first gradient and the second gradient, the edge gradient loss is calculated. The edge gradient loss reflects the difference between the refined edge map generated by the model and the real edge at the gradient level.

[0182] Based on the difference between the generated refined edge map and the annotated real edge information (the real edge information can be obtained through manual annotation, which is time-consuming and labor-intensive, but can provide very accurate edge information and is particularly suitable for situations with extremely high precision requirements), the structure-preserving regularization term is calculated to encourage the model to maintain the structural characteristics of the image when generating refined edges, that is, the generated refined edges should be structurally consistent with the real edges.

[0183] The edge gradient loss and the structure-preserving regularization term are weighted together to calculate the total loss value. The total loss value reflects the comprehensive evaluation of the accuracy of the AI ​​model in generating refined edges and the structure-preserving performance. By adjusting the weight coefficient of the regularization term, the proportion between the two can be balanced, thereby optimizing the overall performance of the AI ​​model.

[0184] Embodiment 2

[0185] See also Figure 2 The present invention proposes an image edge extraction system based on an AI model, the system comprising:

[0186] Model building module: used to introduce spatial attention, channel attention, and graph neural networks into AI models;

[0187] Training module: used to train AI models using edge gradient-based loss functions and structure-preserving regularization terms;

[0188] Edge extraction module: used to input images into the trained AI model. During the forward propagation of the model, important edge areas in the image are captured through spatial attention, and through channel attention, the model adaptively adjusts weights according to the importance of different feature channels to obtain image edges. The image edges are regarded as graph structures, and graph neural networks are used to capture the global and local relationships between edges, further refine the edges, and obtain a refined edge graph.

[0189] Further optionally, the edge extraction module is further used for:

[0190] Perform preliminary feature extraction on the input image through the convolutional layer of the convolutional neural network to generate a preliminary feature map containing image spatial information and feature channel information;

[0191] Based on the preliminary feature map, calculating the attention weight at each spatial position to obtain a spatial attention weight, and multiplying the spatial attention weight by the preliminary feature map element by element to obtain a spatially weighted feature map, which is set as a first feature map;

[0192] Based on the first feature map, calculate the attention weight of each feature channel to obtain the channel attention weight, and multiply the channel attention weight by the first feature map channel by channel to obtain a channel-weighted feature map, which is set as the second feature map;

[0193] The second feature map is input into the edge detection layer to be processed by the edge detection layer to output an initial edge map, wherein the initial edge map contains edge information in the image.

[0194] Further optionally, the edge extraction module is further used for:

[0195] The edges in the initial edge graph are used as nodes in the graph structure, and the connection relationships between the edges are used as edges to construct a basic graph structure;

[0196] Based on the basic graph structure, the connection weights between nodes are adjusted according to the local feature similarities of the nodes to construct an adaptive graph structure;

[0197] The adaptive graph structure is input into the graph neural network to update the state of each node. In the updating process of each node in the graph neural network, an attention mechanism is introduced to dynamically weight the contribution of different neighboring nodes, and the global and local relationships between edges are captured through information transmission and aggregation between nodes.

[0198] After multiple iterative updates of the graph neural network, a refined edge map is obtained.

[0199] Further optionally, the edge extraction module is further used for:

[0200] For each node v i ∈V, extract local features and represent them as feature vector f i , the local features include gradient changes and texture consistency;

[0201] Define a similarity measurement function s(f i , f p ), used to calculate the two nodes v i and v p The feature similarity between them;

[0202] Traverse all edges in the graph (v i , v p )∈E;

[0203] For each edge, calculate the two nodes v i and v p The feature similarity between i , f p );

[0204] Dynamically adjust the edge weight w according to the similarity value and the preset threshold τ ip :

[0205] If s(f i , f p )>τ, then set the edge weight w ip =gs(f i , f p ), enhanced connection, where g is an amplification factor;

[0206] If s(f i , f p )≤τ, then set w ip =0, disconnect;

[0207] According to the adjusted edge weights, an adaptive graph structure G′=(V, E′, W′) is constructed, where V is a set of nodes, E′ is an adjusted edge set, and W′ is an edge weight set.

[0208] Further optionally, the edge extraction module is further used for:

[0209] For each node v in the graph neural network i , initialize its hidden state

[0210] For each iteration step t, the following operations are performed:

[0211] For node v i and each of its neighbor nodes v j ∈N(i), calculate the attention coefficient Where N(i) represents the node v i The neighbor node set of is calculated as:

[0212]

[0213] Among them, a is an attention vector, a T represents the transpose of a, that is, the transpose of the attention vector, W t is the weight matrix of the tth step, For node v iThe hidden state at step t-1 is is the neighbor node v j In the hidden state of step t-1, || represents the vector concatenation operation, and LeakyReLU is the activation function;

[0214] The attention coefficient is normalized by the softmax function to obtain the neighbor node v j For node v i Contribution weight

[0215] According to the normalized attention coefficient, the weighted aggregation node v i The hidden states of all neighboring nodes of node v are obtained i Neighbor aggregation information at step t The calculation formula is:

[0216]

[0217] Combine node v i Its own hidden state and neighbor aggregation information, update node v i The hidden state at step t The calculation formula is:

[0218]

[0219] Where σ is a nonlinear activation function, is for node v i The weight matrix for updating its own hidden state.

[0220] Optionally, the training module is also used to:

[0221] Collect a large number of images containing different edge features and mark the real edges of the images;

[0222] Initialize the parameters of the model;

[0223] The labeled image data is input into the model, and after the forward propagation of the model, a refined edge map is generated;

[0224] Based on the generated refined edge map, the loss value of the model is calculated using an edge gradient-based loss function and a structure-preserving regularization term, wherein the loss value is used to measure the difference between the model prediction result and the true result and the degree of preservation of the model structure;

[0225] Through back propagation, the gradient of each parameter is calculated according to the loss value;

[0226] Use optimization algorithms to update the model's parameters to minimize the loss function value;

[0227] Repeat the training until the model training effect reaches the expected result.

[0228] Optionally, the training module is also used to:

[0229] Calculate the gradient of the input image to get the first gradient. The calculation formula is:

[0230]

[0231] Among them, I is the input image picture, is the first gradient, i.e. the gradient of the image, (x, y) is the pixel coordinate in the image, are the components of the gradient vector of the image in the x and y directions respectively;

[0232] The gradient of the generated refined edge map is calculated to obtain the second gradient, and the calculation formula is:

[0233]

[0234] Among them, E pred is the generated refined edge map, is the second gradient, i.e. the gradient of the generated refined edge map, are each component of the gradient vector of the generated refined edge map in the x and y directions;

[0235] According to the difference between the first gradient and the second gradient, the edge gradient loss is calculated, and the calculation formula is:

[0236]

[0237] Among them, L1 is the edge gradient loss, N is the total number of pixels, || || represents the Euclidean norm, is the gradient of the input image I at the i-th pixel, The generated refined edge graph E pred The gradient at the i-th pixel;

[0238] According to the difference between the generated refined edge map and the annotated true edge information, the structure-preserving regularization term is calculated, and the calculation formula is:

[0239]

[0240] Among them, L2 is the structure-preserving regularization term, is the gradient of the annotated true edge information at the i-th pixel;

[0241] The edge gradient loss and the structure-preserving regularization term are weighted and combined to calculate the total loss value, and the calculation formula is:

[0242] L total =L1+λL2,

[0243] Among them, L total is the total loss value, and λ is the weight coefficient of the regularization term.

[0244] The above-mentioned embodiments only express several implementation methods of the present invention, and the description thereof is relatively specific and detailed, but it cannot be understood as limiting the scope of the patent of the present invention. It should be pointed out that, for ordinary technicians in this field, several variations and improvements can be made without departing from the concept of the present invention, which all belong to the protection scope of the present invention. Therefore, the protection scope of the patent of the present invention shall be subject to the attached claims.

Claims

1. A method for extracting image edges based on an AI model, characterized in that: The method comprises: Introducing spatial attention, channel attention, and graph neural networks into AI models; The AI ​​model is trained using an edge gradient-based loss function and a structure-preserving regularization term. The image is input into the trained AI model. During the forward propagation of the model, the important edge areas in the image are captured through spatial attention, and the model adaptively adjusts the weights according to the importance of different feature channels through channel attention to obtain the image edge. The image edge is regarded as a graph structure, and the graph neural network is used to capture the global and local relationships between the edges, further refine the edges, and obtain a refined edge graph.

2. The image edge extraction method based on the AI ​​model according to claim 1 is characterized in that: In the forward propagation process of the model, the important edge areas in the image are captured by spatial attention, and the model is adaptively adjusted according to the importance of different feature channels through channel attention to obtain the image edge, including: Perform preliminary feature extraction on the input image through the convolutional layer of the convolutional neural network to generate a preliminary feature map containing image spatial information and feature channel information; Based on the preliminary feature map, calculating the attention weight at each spatial position to obtain a spatial attention weight, and multiplying the spatial attention weight by the preliminary feature map element by element to obtain a spatially weighted feature map, which is set as a first feature map; Based on the first feature map, calculate the attention weight of each feature channel to obtain the channel attention weight, and multiply the channel attention weight by the first feature map channel by channel to obtain a channel-weighted feature map, which is set as the second feature map; The second feature map is input into the edge detection layer to be processed by the edge detection layer to output an initial edge map, wherein the initial edge map contains edge information in the image.

3. The image edge extraction method based on the AI ​​model according to claim 2 is characterized in that: The image edges are regarded as graph structures, and the graph neural network is used to capture the global and local relationships between the edges, and the edges are further refined to obtain a refined edge graph, including: The edges in the initial edge graph are used as nodes in the graph structure, and the connection relationships between the edges are used as edges to construct a basic graph structure; Based on the basic graph structure, the connection weights between nodes are adjusted according to the local feature similarities of the nodes to construct an adaptive graph structure; The adaptive graph structure is input into the graph neural network to update the state of each node. During the updating process of each node in the graph neural network, an attention mechanism is introduced to dynamically weight the contribution of different neighboring nodes, and the global and local relationships between edges are captured through information transmission and aggregation between nodes. After multiple iterative updates of the graph neural network, a refined edge map is obtained.

4. The image edge extraction method based on the AI ​​model according to claim 3 is characterized in that: The method of adjusting the connection weights between nodes based on the basic graph structure according to the local feature similarities of the nodes to construct an adaptive graph structure includes: For each node v i ∈V, extract local features and represent them as feature vector f i , the local features include gradient changes and texture consistency; Define a similarity measurement function s(f i , f p ), used to calculate the two nodes v i and v p The feature similarity between them; Traverse all edges in the graph (v i , v p )∈E; For each edge, calculate the two nodes v i and v p The feature similarity between i , f p ); Dynamically adjust the edge weight w according to the similarity value and the preset threshold τ ip : If s(f i , f p )>τ, then set the edge weight w ip =gs(f i , f p ), enhanced connection, where g is an amplification factor; If s(f i , f p )≤τ, then set w ip =0, disconnect; According to the adjusted edge weights, an adaptive graph structure G′=(V, E′, W′) is constructed, where V is a set of nodes, E′ is an adjusted edge set, and W′ is an edge weight set.

5. The method for extracting image edges based on an AI model according to claim 3, characterized in that: The adaptive graph structure is input into the graph neural network to update the state of each node. In the updating process of each node in the graph neural network, an attention mechanism is introduced to dynamically weight the contribution of different neighboring nodes, and the global and local relationships between edges are captured through information transmission and aggregation between nodes, including: For each node v in the graph neural network i , initialize its hidden state For each iteration step t, the following operations are performed: For node v i and each of its neighbor nodes v j ∈N(i), calculate the attention coefficient Where N(i) represents the node v i The neighbor node set of is calculated as: Among them, a is an attention vector, a T represents the transpose of a, that is, the transpose of the attention vector, W t is the weight matrix of the tth step, For node v i The hidden state at step t-1 is is the neighbor node v j In the hidden state of step t-1, || represents the vector concatenation operation, and LeakyReLU is the activation function; The attention coefficient is normalized by the softmax function to obtain the neighbor node v j For node v i Contribution weight According to the normalized attention coefficient, the weighted aggregation node v i The hidden states of all neighboring nodes of node v are obtained i Neighbor aggregation information at step t The calculation formula is: Combine node v i Its own hidden state and neighbor aggregation information, update node v i The hidden state at step t The calculation formula is: Where σ is a nonlinear activation function, is for node v i The weight matrix for updating its own hidden state.

6. The method for extracting image edges based on an AI model according to claim 1, characterized in that: The AI ​​model is trained using a loss function based on edge gradients and a structure-preserving regularization term, including: Collect a large number of images containing different edge features and mark the real edges of the images; Initialize the parameters of the model; The labeled image data is input into the model, and after the forward propagation of the model, a refined edge map is generated; Based on the generated refined edge map, the loss value of the model is calculated using an edge gradient-based loss function and a structure-preserving regularization term, wherein the loss value is used to measure the difference between the model prediction result and the true result and the degree of preservation of the model structure; Through back propagation, the gradient of each parameter is calculated according to the loss value; Use optimization algorithms to update the model's parameters to minimize the loss function value; Repeat the training until the model training effect reaches the expected result.

7. The method for extracting image edges based on an AI model according to claim 6, characterized in that: Based on the generated refined edge map, the loss value of the model is calculated using a loss function based on edge gradient and a structure-preserving regularization term, including: Calculate the gradient of the input image to get the first gradient. The calculation formula is: Among them, I is the input image picture, is the first gradient, i.e. the gradient of the image, (x, y) is the pixel coordinate in the image, are the components of the gradient vector of the image in the x and y directions respectively; The gradient of the generated refined edge map is calculated to obtain the second gradient, and the calculation formula is: Among them, E pred is the generated refined edge map, is the second gradient, i.e. the gradient of the generated refined edge map, are each component of the gradient vector of the generated refined edge map in the x and y directions; According to the difference between the first gradient and the second gradient, the edge gradient loss is calculated, and the calculation formula is: Among them, L1 is the edge gradient loss, N is the total number of pixels, || || represents the Euclidean norm, is the gradient of the input image I at the i-th pixel, The generated refined edge graph E pred The gradient at the i-th pixel; According to the difference between the generated refined edge map and the annotated true edge information, the structure-preserving regularization term is calculated, and the calculation formula is: Among them, L2 is the structure-preserving regularization term, is the gradient of the annotated true edge information at the i-th pixel; The edge gradient loss and the structure-preserving regularization term are weighted and combined to calculate the total loss value, and the calculation formula is: L total =L1+λL2, Among them, L total is the total loss value, and λ is the weight coefficient of the regularization term.

8. An image edge extraction system based on AI model, characterized in that: The system comprises: Model building module: used to introduce spatial attention, channel attention, and graph neural networks into AI models; Training module: used to train AI models using edge gradient-based loss functions and structure-preserving regularization terms; Edge extraction module: used to input images into the trained AI model. During the forward propagation of the model, important edge areas in the image are captured through spatial attention, and through channel attention, the model adaptively adjusts weights according to the importance of different feature channels to obtain image edges. The image edges are regarded as graph structures, and graph neural networks are used to capture the global and local relationships between edges, further refine the edges, and obtain a refined edge graph.

Citation Information

Cited By

  • Backlight effect image edge enhancement method based on intelligent identification

    CN120953153A