Image contour matching method, device and storage medium
Patent Information
- Application Number
- CN202611224805.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-08-13
- Publication Date
- 2026-09-08
AI Technical Summary
[0004]本申请的主要目的在于提供一种图像轮廓匹配方法、设备及存储介质,旨在解决金字塔轮廓匹配中因各层边缘特征结构不一致导致匹配精度下降的技术问题
本申请通过预先对模板图像进行边界扩展,使得原本位于图像边界的轮廓特征在经历逐层平滑与降采样后仍能完整保留在有效图像区域内,避免了高层模板图像中边缘特征被截断的问题;通过提取各层梯度幅度平均值并计算其相对于基准幅度值的衰减比例,据此动态调整各层的对比度阈值,使得高层图像中因梯度衰减而强度降低的有效边缘特征仍能被提取出来,避免了固定阈值导致的高层特征大量丢失;进一步地,通过将相邻低层模板特征集合中各特征点的位置映射到相邻高层并对高层特征进行校验,利用低层真实特征验证高层特征的来源真实性,剔除了因噪声或纹理混叠产生的虚假边缘特征,从而保证了金字塔各层模板特征集合在空间结构上的一致性和自洽性。在此基础上,将各层校验后的模板特征集合与搜索图像金字塔对应层的搜索图特征进行逐层滑动匹配,由于各层模板特征结构一致且真实可靠,高层粗匹配的准确性得到保障,逐层映射和精搜索过程中误差不会因特征不一致而累积放大,最终在整个金字塔匹配过程中实现了稳定、高精度的轮廓匹配定位。
Smart Images

Figure CN122714818A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of image processing technology, and in particular to an image contour matching method, device and storage medium. Background Technology
[0002] In the field of industrial visual matching, image pyramid-based contour matching methods construct multi-resolution images through layer-by-layer downsampling. Coarse matching begins at the top layer (low resolution) and is then refined down to the bottom layer (original image), thereby reducing computational cost. However, this pyramid construction process suffers from inherent feature degradation. After layer-by-layer smoothing and downsampling, edge contours near the boundaries of higher layers are gradually truncated. Simultaneously, the gradient magnitude systematically decays with increasing layer number, leading to the loss of many effective contour features due to excessively low magnitudes. Furthermore, texture details or noise may alias into false edges that were not originally present during downsampling. These factors collectively result in significant inconsistencies in the edge feature structures between different pyramid layers, reducing the reliability of high-level coarse matching. Once the pose estimation at the top layer deviates, this error propagates and accumulates down the pyramid, ultimately affecting the overall matching accuracy.
[0003] The above content is only used to help understand the technical solution of this application and does not represent an admission that the above content is prior art. Summary of the Invention
[0004] The main objective of this application is to provide an image contour matching method, device, and storage medium, which aims to solve the technical problem of decreased matching accuracy in pyramid contour matching due to inconsistent edge feature structures of each layer.
[0005] To achieve the above objectives, embodiments of this application provide an image contour matching method, the image contour matching method comprising: Obtain a template image, and expand the boundaries of the template image according to the total number of pyramid layers to obtain a template pyramid image; Extract the average gradient magnitude of each layer of the template pyramid image, and determine the contrast threshold of each layer based on the attenuation ratio of the average gradient magnitude of each layer relative to the reference magnitude value. Based on the contrast threshold of each layer, the edge contour feature points in the corresponding layer template pyramid image are extracted to form the template feature set of each layer. The positions of each feature point in the template feature set of the adjacent lower layer are mapped to the adjacent higher layer, and the template feature set of the adjacent higher layer is verified to obtain the verified template feature set of each layer. A search image pyramid is constructed and search graph features of each layer are extracted. The search graph features of each layer are then matched with the template feature set after verification of the corresponding layer. The target position is mapped from the top to the bottom layer of the search image pyramid, and the final matching target is output.
[0006] In one embodiment, the step of obtaining a template image and expanding the template image by its boundaries according to the total number of pyramid layers to obtain a template pyramid image includes: The boundary expansion size is determined based on the total number of pyramid layers and the size of the smoothing filter used during pyramid construction; Based on the boundary expansion size, the template image is mirrored and expanded in both the width and height directions to obtain the expanded template image; The template pyramid image is constructed based on the expanded template image.
[0007] In one embodiment, the step of extracting the average gradient magnitude of each layer of the template pyramid image and determining the contrast threshold of each layer based on the attenuation ratio of the average gradient magnitude of each layer relative to the reference magnitude value includes: The average gradient magnitude of the bottom layer of the template pyramid image is calculated as the reference magnitude value; Calculate the average gradient magnitude of the template pyramid image for each layer, and use the ratio of the average gradient magnitude of each layer to the reference magnitude value as the attenuation ratio of the corresponding layer. The contrast threshold of the corresponding layer is calculated based on the attenuation ratio of each layer and the preset contrast threshold attenuation coefficient.
[0008] In one embodiment, the step of extracting edge contour feature points from the corresponding layer template pyramid image based on the contrast threshold of each layer to form the template feature set of each layer includes: Based on the contrast threshold corresponding to each layer, the edge contour feature points are extracted from the template pyramid image of the corresponding layer; Record the position and orientation information of each edge contour feature point in the corresponding layer template pyramid image; Based on the edge contour feature points, position information, and orientation feature information extracted from each layer, a template feature set for each layer is constructed.
[0009] In one embodiment, the step of mapping the positions of each feature point in the template feature set of adjacent lower layers to adjacent higher layers, and verifying the template feature sets of the adjacent higher layers to obtain the verified template feature sets of each layer includes: The position coordinates of each feature point in the template feature set of the adjacent lower layer are mapped to the adjacent higher layer according to the downsampling factor to obtain the mapped position of each feature point in the adjacent higher layer. With each of the aforementioned mapping positions as the center, a corresponding neighborhood window is constructed according to a preset window size; In the template feature set of the adjacent high layers, feature points that fall within any of the neighborhood windows are retained, and feature points that do not fall within any of the neighborhood windows are removed, thus obtaining the template feature set after verification for each layer.
[0010] In one embodiment, the step of performing sliding matching between the search graph features of each layer and the corresponding layer's verified template feature set, mapping the target position layer by layer from the top to the bottom of the search image pyramid, and outputting the final matching target includes: Obtain the verified template feature set and the corresponding search graph features of each layer; Starting from the top of the search image pyramid, the template feature set verified in the current layer is slid-matched on the search graph feature of the corresponding layer, the matching score at each sliding position is calculated, and the matching target of the current layer is determined based on the matching score. The position of the matching target in the current layer is mapped to the next adjacent layer, and matching continues in the next adjacent layer. This process is repeated layer by layer until the bottom layer of the search image pyramid is reached, and the final matching target is output.
[0011] In one embodiment, the step of performing sliding matching on the search graph features of the corresponding layer using the template feature set verified in the current layer, calculating the matching score at each sliding position, and determining the matching target of the current layer based on the matching score includes: The template feature set after the current layer is verified is slid row by row and column by column on the search graph feature of the corresponding layer. At each sliding position, the similarity between each feature point in the template feature set and the corresponding feature point on the search graph feature is calculated. The similarity of all feature points is accumulated as the matching score corresponding to the sliding position. The matching score at each sliding position is compared with a preset score threshold, and the sliding position with a matching score not lower than the preset score threshold is taken as the matching target of the current layer.
[0012] In one embodiment, the step of mapping the position of the matching target in the current layer to the adjacent next layer, continuing matching in the adjacent next layer, and sequentially mapping and matching layer by layer until the bottom layer of the search image pyramid, and outputting the final matching target includes: The position of the matching target is scaled according to the upsampling ratio between adjacent layers, while keeping the angle unchanged, to obtain the mapping position of the matching target in the next adjacent layer. In the adjacent next layer, with the mapping position as the center, a matching search is performed within a preset neighborhood range to obtain the matching result of the matching target in the adjacent next layer; Repeat the step of mapping the position of the matching target in the current layer to the next adjacent layer until it is mapped to the bottom layer of the search image pyramid, and output the final matching target.
[0013] This application embodiment also provides an image contour matching device, the image contour matching device including: a memory, a processor, and a computer program stored in the memory and executable on the processor, the computer program being configured to implement the steps of the image contour matching method as described above.
[0014] This application embodiment also provides a storage medium, which is a computer-readable storage medium, and stores a computer program thereon. When the computer program is executed by a processor, it implements the steps of the image contour matching method described above.
[0015] One or more technical solutions proposed in this application have at least the following technical effects: This application pre-expands the boundaries of the template image, ensuring that contour features originally located at the image boundary remain intact within the effective image area after layer-by-layer smoothing and downsampling, thus avoiding the problem of edge features being truncated in higher-level template images. By extracting the average gradient magnitude of each layer and calculating its attenuation ratio relative to the baseline magnitude value, the contrast threshold of each layer is dynamically adjusted accordingly, allowing effective edge features in higher-level images with reduced intensity due to gradient attenuation to still be extracted, avoiding the loss of a large number of higher-level features due to fixed thresholds. Furthermore, by mapping the positions of each feature point in the adjacent lower-level template feature set to the adjacent higher-level features and verifying the higher-level features, the authenticity of the source of the higher-level features is verified using the real features of the lower levels, eliminating false edge features caused by noise or texture aliasing, thereby ensuring the consistency and self-consistency of the template feature sets of each layer of the pyramid in spatial structure. Based on this, the template feature sets verified at each layer are matched with the search map features of the corresponding layer of the search image pyramid layer by layer. Since the template feature structures of each layer are consistent and reliable, the accuracy of coarse matching at higher levels is guaranteed. Errors in the layer-by-layer mapping and fine search process will not accumulate and be amplified due to inconsistent features. Finally, stable and high-precision contour matching and positioning are achieved in the entire pyramid matching process. Attached Figure Description
[0016] Figure 1 This is a flowchart illustrating an embodiment of the image contour matching method of this application. Figure 2 This is a schematic diagram of the structure of the image contour matching device in the hardware operating environment of the image contour matching method in the embodiments of this application.
[0017] The purpose, features, and advantages of this application will be further explained in conjunction with the embodiments and with reference to the accompanying drawings. Detailed Implementation
[0018] It should be understood that the specific embodiments described herein are merely illustrative of this application and are not intended to limit this application.
[0019] To better understand the technical solution of this application, a detailed description will be provided below in conjunction with the accompanying drawings and specific implementation methods.
[0020] In the field of industrial visual matching, image pyramid-based contour matching methods construct multi-resolution images through layer-by-layer downsampling. Coarse matching begins at the top layer (low resolution) and is then refined down to the bottom layer (original image), thereby reducing computational cost. However, this pyramid construction process suffers from inherent feature degradation. After layer-by-layer smoothing and downsampling, edge contours near the boundaries of higher layers are gradually truncated. Simultaneously, the gradient magnitude systematically decays with increasing layer number, leading to the loss of many effective contour features due to excessively low magnitudes. Furthermore, texture details or noise may alias into false edges that were not originally present during downsampling. These factors collectively result in significant inconsistencies in the edge feature structures between different pyramid layers, reducing the reliability of high-level coarse matching. Once the pose estimation at the top layer deviates, this error propagates and accumulates down the pyramid, ultimately affecting the overall matching accuracy.
[0021] In view of the above problems, this application proposes an image contour matching method. The method involves acquiring a template image, expanding the template image's boundaries according to the total number of pyramid layers to obtain a template pyramid image; extracting the average gradient magnitude of each layer of the template pyramid image, and determining the contrast threshold of each layer based on the attenuation ratio of the average gradient magnitude of each layer relative to the reference magnitude value; extracting edge contour feature points in the corresponding layer's template pyramid image based on the contrast threshold of each layer to form a template feature set for each layer; mapping the positions of each feature point in the template feature set of adjacent lower layers to adjacent higher layers, and verifying the template feature sets of the adjacent higher layers to obtain verified template feature sets for each layer; constructing a search image pyramid and extracting search graph features for each layer; performing sliding matching between the search graph features of each layer and the verified template feature sets of the corresponding layers, mapping the matching target position layer by layer from the top to the bottom of the search image pyramid, and outputting the final matching target.
[0022] This application provides a solution that pre-expands the boundaries of the template image, ensuring that contour features originally located at the image boundary remain intact within the effective image area after layer-by-layer smoothing and downsampling, thus avoiding the problem of edge features being truncated in higher-level template images. By extracting the average gradient magnitude of each layer and calculating its attenuation ratio relative to the baseline magnitude value, the contrast threshold of each layer is dynamically adjusted accordingly, allowing effective edge features in higher-level images with reduced intensity due to gradient attenuation to still be extracted, avoiding the loss of a large number of higher-level features due to fixed thresholds. Furthermore, by mapping the positions of each feature point in the adjacent lower-level template feature set to the adjacent higher-level features and verifying the higher-level features, the authenticity of the source of the higher-level features is verified using the real features of the lower levels, eliminating false edge features caused by noise or texture aliasing, thereby ensuring the consistency and self-consistency of the template feature sets of each layer of the pyramid in spatial structure. Based on this, the template feature sets verified at each layer are matched with the search map features of the corresponding layer of the search image pyramid layer by layer. Since the template feature structures of each layer are consistent and reliable, the accuracy of coarse matching at higher levels is guaranteed. Errors in the layer-by-layer mapping and fine search process will not accumulate and be amplified due to inconsistent features. Finally, stable and high-precision contour matching and positioning are achieved in the entire pyramid matching process.
[0023] It should be noted that the executing entity in this embodiment can be a computing service device with data processing, network communication, and program execution functions, such as an industrial camera, smart camera, industrial control computer, personal computer, computer equipment, etc., or an electronic device, image processing device, image contour matching device, or system capable of realizing the above functions. The following description uses an image contour matching system as an example to illustrate this embodiment and the subsequent embodiments.
[0024] The image contour matching method of the first embodiment proposed in this application can be found in [reference needed]. Figure 1 The method includes steps S10 to S50: Step S10: Obtain a template image, and expand the template image by boundary according to the total number of pyramid layers to obtain a template pyramid image.
[0025] During the construction of the image pyramid, with each smoothing filter and downsampling, pixel information near the image edges gradually shrinks inward, causing contour features located at the image boundary to be truncated in the higher-level image. To solve this problem, this embodiment first expands the boundary of the template image before constructing the pyramid.
[0026] In this embodiment, the template image refers to a pre-selected standard image containing the target to be matched, the total number of pyramid layers represents the number of image layers from the original resolution image to the lowest resolution image, and boundary expansion refers to adding extra pixel areas outside the edges of the template image to accommodate the loss of boundary information caused by subsequent smoothing and downsampling.
[0027] As an optional implementation, the boundary expansion size is calculated based on the total number of pyramid layers and the size of the smoothing filter used in constructing the pyramid. Specifically, after each smoothing filter, the image edge erodes inward by a pixel width equivalent to the filter radius. Through the cumulative effect of multiple pyramid layers, the total expansion must be sufficient to compensate for the loss of boundary information in all layers. Subsequently, mirror expansion is performed in both the width and height directions of the template image according to this boundary expansion size. Mirror expansion refers to folding and copying the pixel content near the original image boundary outwards, using the original image boundary as the axis of symmetry. This method, compared to zero-padding or constant padding, maintains the continuity of texture and gradient at the boundary, avoiding the introduction of edge responses that were not originally present in the expanded area. Based on the expanded template image, smoothing filtering and downsampling operations can be performed layer by layer according to the standard pyramid construction process to generate template pyramid images for each layer. Because the expanded area provides sufficient boundary margin, the contour features originally located at the edge of the template image can still be completely preserved within the effective image area after multiple smoothing and downsampling processes, thus ensuring the integrity of feature extraction in subsequent layers.
[0028] As an example, suppose the pyramid has a total of [number] levels. Then the boundary expansion size The calculation formula is as follows: ,in The size of the smoothing filter used when constructing the pyramid.
[0029] Step S20: Extract the average gradient magnitude of each layer of the template pyramid image, and determine the contrast threshold of each layer based on the attenuation ratio of the average gradient magnitude of each layer relative to the reference magnitude value.
[0030] In a template pyramid image, edge features are characterized by gradient magnitude values; a larger gradient magnitude indicates a higher probability of an edge existing at that location. As the number of pyramid layers increases, the overall gradient magnitude gradually decreases after multiple smoothing filters and downsampling processes—a phenomenon known as gradient decay. If the same contrast threshold is used to extract edge features across all layers, only a very small number of strong edges will be preserved in higher-level images, while many weak edges that are originally valid contours will be missed, resulting in severe loss of high-level template features. Therefore, this embodiment uses an adaptive thresholding method based on the gradient magnitude decay ratio to extract high-level template features.
[0031] In this embodiment, the average gradient magnitude refers to the average gradient magnitude of all pixels in a certain layer of the pyramid image, reflecting the overall edge strength level of that layer. The baseline magnitude refers to the average gradient magnitude of the bottom template pyramid image, serving as a reference for measuring the gradient attenuation of other layers. The attenuation ratio is the ratio of the average gradient magnitude of the current layer to the baseline magnitude; a smaller ratio indicates more severe gradient attenuation in the current layer. The contrast threshold is a critical value used to determine whether a pixel is an edge feature point; only pixels with gradient magnitudes exceeding this contrast threshold are retained as edge points.
[0032] As an optional implementation, the average gradient magnitude of the bottom layer of the template pyramid image is first calculated as a baseline magnitude value. Then, the average gradient magnitude of each layer of the pyramid image is calculated separately. The ratio of the average gradient magnitude of each layer to the baseline magnitude value is used as the attenuation ratio of that layer. Based on the attenuation ratio of each layer and a preset contrast threshold attenuation coefficient, the contrast threshold of the corresponding layer is calculated. When the attenuation ratio of a certain layer is small, it indicates that the gradient attenuation of that layer is severe. Accordingly, its contrast threshold is lowered so that more edge points with relatively small gradient magnitudes can be preserved.
[0033] As an example, the average gradient magnitude of the template pyramid image at level 0 is calculated as the baseline magnitude value. In extracting the first When performing layer template feature calculations, the average gradient magnitude of the layer is also calculated first. Then according to the first Average gradient magnitude of layer Ratio to the reference amplitude value Determine the first The attenuation ratio of the layer is Based on this attenuation ratio And the preset contrast threshold attenuation coefficient determines the first Contrast threshold when extracting template features from layers ,Right now ,in This is the contrast threshold attenuation coefficient. Typically, a value of 0.6 to 0.9 is used to effectively extract high-level template features.
[0034] Step S30: Extract edge contour feature points from the corresponding layer template pyramid image based on the contrast threshold of each layer to form a template feature set for each layer.
[0035] After determining the contrast threshold for each layer of the template pyramid image, edge contour features can be extracted from each layer. In this embodiment, edge contour feature points refer to pixels in the template image whose gradient magnitude exceeds the contrast threshold and have a clear directionality; these points collectively constitute the contour shape of the template pyramid image. The template feature set refers to the summary set of all extracted edge contour feature points and their attribute information in a certain layer, including the position coordinates of each feature point in the image and the corresponding gradient direction vector.
[0036] As an optional implementation, based on the contrast threshold corresponding to each layer Edge contour feature points are extracted from the template pyramid images of each corresponding layer, and the position and orientation information of each edge contour feature point in the corresponding layer image are recorded. Then, a template feature set for each layer is constructed based on the extracted edge contour feature points, position information, and orientation feature information. Specifically, for each layer of template pyramid image, the contrast threshold corresponding to that layer is used to determine whether each pixel in the image meets the edge condition. When the gradient magnitude of a pixel is greater than or equal to the contrast threshold corresponding to that layer, the pixel is marked as an edge contour feature point, and the position information of the pixel in the coordinate system of that layer image is recorded. At the same time, the gradient direction vector of the pixel is calculated as the orientation feature information. Among them, the position information is used to determine the alignment position of the template pyramid image in the search image during subsequent matching, and the orientation feature information is used to measure the similarity between the template feature points and the corresponding position feature points in the search image.
[0037] When recording the location information of feature points, you can choose to normalize the coordinates of the feature points to the center of the template pyramid image of that layer, or you can directly use the original coordinate values in the coordinate system of that layer's image. The advantage of location normalization is that it makes the description of the template feature set independent of the specific location of the template in the search image, which facilitates subsequent similarity calculation. When recording directional feature information, the gradient vector is normalized to obtain a unit direction vector. This eliminates the interference of gradient magnitude on similarity calculation, so that the matching score only reflects the consistency of direction.
[0038] As an example, when the coordinates of feature points are normalized to the center of the template pyramid image of that layer, the position of each edge contour feature point is represented by the offset of its coordinates in the image coordinate system of that layer relative to the coordinates of the center of the template pyramid image. The template feature set records the normalized position coordinates of each edge contour feature point and its corresponding gradient unit direction vector, i.e. The template feature set is denoted as... , ) represents the normalized coordinates of each edge contour feature point. The coordinates of the edge feature points, The coordinates of the center of the pyramid image in this layer are: is the unit direction vector of the gradient at the feature point.
[0039] Step S40: Map the positions of each feature point in the template feature set of the adjacent lower layer to the adjacent higher layer, and verify the template feature set of the adjacent higher layer to obtain the verified template feature set of each layer.
[0040] During the construction of the template pyramid image, in addition to the attenuation and loss of true edge contour features, texture details or noise in the image may also cause spectral aliasing during downsampling, forming false edges in higher layers that do not exist in lower layers. These false edges are treated as valid features during higher-level matching, thus interfering with the direction determination of coarse matching. Therefore, after the template features are extracted, it is necessary to verify the authenticity of higher-level features using the geometric correspondence between adjacent layers.
[0041] In this embodiment, adjacent lower layers and adjacent higher layers refer to two adjacent levels in the pyramid, where lower layers have higher resolution and larger size, and higher layers have lower resolution and smaller size. Since the higher layer image is obtained by downsampling the lower layer image, each feature point in the lower layer has a corresponding mapping position in the higher layer, and the position coordinates need to be scaled down proportionally according to the downsampling factor.
[0042] As an optional implementation, the position coordinates of each feature point in the template feature set of the adjacent lower layer are mapped to the adjacent higher layer according to the downsampling factor to obtain the mapped position of each feature point in the adjacent higher layer; with each mapped position as the center, a corresponding neighborhood window is constructed according to a preset window size; in the template feature set of the adjacent higher layer, feature points that fall within any neighborhood window are retained, and feature points that do not fall within any neighborhood window are removed to obtain the template feature set after verification of each layer.
[0043] Specifically, for each extracted feature point in the adjacent lower layer (L layer), its position coordinates are scaled according to a downsampling factor (e.g., a downsampling factor of 2) to obtain the mapped position of the feature point in the image coordinate system of the adjacent higher layer (L+1 layer). A neighborhood window of a preset size (e.g., 5×5, 7×7, 9×9, etc.) is constructed with this mapped position as the center to tolerate slight drift of feature points caused by smoothing filtering and quantization errors caused by coordinate rounding. After mapping all lower layer feature points, each feature point actually extracted in the L+1 layer is traversed, and it is checked whether it falls within the neighborhood window corresponding to any mapped position. If it falls within the neighborhood window, it means that the higher layer feature point can form a correspondence with a real feature point in the lower layer, and it is retained; if it does not fall within any neighborhood window, it is determined that the feature point is a false edge caused by noise aliasing and is discarded. By verifying upwards layer by layer in this way, the template feature set of each layer is verified by the real features of the lower layer, ensuring the consistency of the feature structure between the layers of the pyramid and avoiding interference from false features during higher layer matching.
[0044] Step S50: Construct a search image pyramid and extract search graph features from each layer. Perform sliding matching between the search graph features of each layer and the template feature set verified by the corresponding layer. Map the matching target position layer by layer from the top to the bottom of the search image pyramid and output the final matching target.
[0045] After completing the multi-layer construction and verification of template features, contour matching using a pyramid strategy can be performed on the search image. In this embodiment, the search image pyramid refers to a multi-resolution image sequence constructed based on the image to be matched. Its construction method is consistent with that of the template pyramid image to ensure that the scale correspondence of each layer is valid. The search image features refer to the set of edge contour feature points extracted from each layer of the search image, and the extraction method is the same as that used for the template feature set.
[0046] As an optional implementation, the search image pyramid is constructed using the exact same boundary expansion size, smoothing filter, and downsampling factor as the template pyramid image, ensuring that the template pyramid image and the search image pyramid at the same level have the same resolution and image feature response characteristics. When extracting search map features, the same dynamic contrast thresholding method as used for template feature set extraction can be employed. The average gradient magnitude of each search image layer is calculated, and the corresponding contrast threshold is determined, thereby adaptively extracting the edge contour features of each search image layer. It should be noted that each layer of the search image only needs to provide edge feature points for matching searches; therefore, the dynamic contrast thresholding method in step S20 can be used for feature extraction, without performing the cross-layer verification in step S40. When extracting search map feature points, the gradient direction vector of each feature point is calculated in the same way as the template feature points and normalized to a unit direction vector. This is used for similarity calculation in the subsequent matching process.
[0047] Furthermore, step S50 includes steps S51 to S53: Step S51: Obtain the verified template feature set and the search graph features of the corresponding layer for each layer; Step S52: Starting from the top of the search image pyramid, slide the template feature set verified in the current layer onto the search graph features of the corresponding layer, calculate the matching score at each sliding position, and determine the matching target of the current layer based on the matching score. Step S53: Map the position of the matching target in the current layer to the next adjacent layer, continue matching in the next adjacent layer, and map and match layer by layer until the bottom layer of the search image pyramid is reached, and output the final matching target.
[0048] After obtaining the verified template feature sets and corresponding search graph features for each layer, the matching process starts from the top layer of the search image pyramid. The top layer image has the lowest resolution, and the matching search range covers the entire image. The approximate location of the target can be quickly determined through sliding matching. Specifically, step S52 includes: sliding the verified template feature set of the current layer row by row and column by column on the search graph features of the corresponding layer; at each sliding position, calculating the similarity between each feature point in the template feature set and the corresponding feature point on the search graph features; summing the similarity of all feature points as the matching score corresponding to that sliding position; after calculating the matching scores for all sliding positions, comparing the matching scores corresponding to each sliding position with a preset score threshold; eliminating sliding positions with matching scores lower than the preset score threshold; and using sliding positions with matching scores not lower than the preset score threshold as the matching targets for the current layer. The higher the matching score, the more similar the template at that position is to the local structure in the search image, and the greater the probability that the target exists.
[0049] As an example, when matching, use the first The template feature set after layer verification is in the search image pyramid at the th layer. The layer is slid up row by row and column by column to find a matching target. At each sliding position... The similarity is calculated between each feature point in the template feature set and the corresponding feature points on the search graph. Specifically, the cosine of the angle between the unit direction vectors of the two feature points is calculated, and the sum of the cosine values of all feature points is used as the matching score at that sliding position. The specific similarity calculation formula is as follows:
[0050] in, and These are the magnitudes of the template feature point direction vector and the search graph feature point direction vector, respectively. , It is a unit vector.
[0051] Therefore, similarity calculation can be simplified to , ,in The similarity between template feature points and search graph feature points. Template features at search graph locations The matching score at the location.
[0052] After calculating the matching scores for all sliding positions in the search image layer, sliding positions with matching scores below a preset threshold are removed, and sliding positions with matching scores at or above the preset threshold are used as the matching targets for that layer, thus completing the search image pyramid. Layer matching.
[0053] After the matching of the previous layer is completed, the position of the matching target needs to be transferred to the next layer with higher resolution for precise matching. Specifically, step S53 includes: scaling the current layer's matching target position according to the upsampling ratio between adjacent layers while keeping the angle unchanged, to obtain the mapped position of the matching target in the next adjacent layer; in the next adjacent layer, using the mapped position as the center, continue the matching search within a preset neighborhood to obtain the matching result of the matching target in the next adjacent layer. Compared to the top layer, which requires a full search of the entire image, the local search within the neighborhood only needs to process pixels within a limited range, effectively controlling the computational load of each matching layer. Since the next adjacent layer has a higher resolution, the mapped position is approximately the coarse position of the target in the next layer, and a more accurate matching result can be obtained by performing a local search based on this. Repeat the above steps of mapping the current layer's matching target position to the next adjacent layer until the bottom layer of the search image pyramid is reached. At this point, the bottom layer image has the highest resolution, and the final matching target and its corresponding position and angle information are output as the final matching result.
[0054] As an example, when the current sampling factor is 2, the image size between adjacent layers differs by a factor of two. Complete the search of the image pyramid. After matching the layers, continue with the first layer. The target matched by the layer is mapped to the lower layer. The first floor, soon to be the first Multiply the target position coordinates matched by the first layer by 2, while keeping the angle unchanged, to obtain the second layer. Layer matching target in the first The mapping location in the layer, i.e. In the first In the layer, a matching search is performed within a preset neighborhood, centered on the mapped location. After the search is completed, targets whose matching scores do not meet the preset score threshold are removed, and then the result is obtained. The matching target for each layer is mapped and matched layer by layer in the manner described above, until the matching reaches layer 0, thus completing the final matching.
[0055] This embodiment pre-expands the boundaries of the template image, ensuring that the contour features originally located at the image boundary remain intact within the effective image area after layer-by-layer smoothing and downsampling, thus avoiding the problem of edge features being truncated in higher-level template images. By extracting the average gradient magnitude of each layer and calculating its attenuation ratio relative to the baseline magnitude value, the contrast threshold of each layer is dynamically adjusted accordingly, allowing effective edge features in higher-level images with reduced intensity due to gradient attenuation to still be extracted, avoiding the loss of a large number of higher-level features due to a fixed threshold. Furthermore, by mapping the positions of each feature point in the adjacent lower-level template feature set to the adjacent higher-level features and verifying the higher-level features, the authenticity of the source of the higher-level features is verified using the real features of the lower layers, eliminating false edge features caused by noise or texture aliasing, thereby ensuring the consistency and self-consistency of the template feature sets of each layer of the pyramid in spatial structure. Based on this, the template feature sets verified at each layer are matched with the search map features of the corresponding layer of the search image pyramid layer by layer. Since the template feature structures of each layer are consistent and reliable, the accuracy of coarse matching at higher levels is guaranteed. Errors in the layer-by-layer mapping and fine search process will not accumulate and be amplified due to inconsistent features. Finally, stable and high-precision contour matching and positioning are achieved in the entire pyramid matching process.
[0056] This application provides an image contour matching device, which includes: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor, which are executed by the at least one processor to enable the at least one processor to perform the image contour matching method in the first embodiment described above.
[0057] The following is for reference. Figure 2 This diagram illustrates a structural schematic of an image contour matching device suitable for implementing embodiments of this application. The image contour matching device in the embodiments of this application may include various hardware and software components for implementing the image contour matching method. Figure 2 The image contour matching device shown is merely an example and should not impose any limitations on the functionality and scope of use of the embodiments of this application.
[0058] like Figure 2As shown, the image contour matching device may include a processing unit 1001 (e.g., a central processing unit, a graphics processing unit, etc.) that can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 1002 or a program loaded from a storage device 1003 into a random access memory (RAM) 1004. The RAM 1004 also stores various programs and data required for the operation of the image contour matching device. The processing unit 1001, the ROM 1002, and the RAM 1004 are interconnected via a bus 1005. An input / output (I / O) interface 1006 is also connected to the bus. Typically, the following systems can be connected to the I / O interface 1006: input devices 1007 including, for example, a touchscreen, a touchpad, a keyboard, etc.; output devices 1008 including, for example, a liquid crystal display (LCD), a speaker, a vibrator, etc.; storage devices 1003 including, for example, magnetic tape, a hard disk, etc.; and communication devices 1009. The communication device 1009 allows the image contour matching device to communicate wirelessly or wiredly with other devices to exchange data. Although the figures show image contour matching devices with various systems, it should be understood that implementing or having all of the systems shown is not required. More or fewer systems may be implemented alternatively.
[0059] Specifically, according to the embodiments disclosed in this application, the processes described above with reference to the flowcharts can be implemented as computer software programs. For example, embodiments disclosed in this application include a computer program product comprising a computer program carried on a computer-readable medium, the computer program containing program code for performing the methods shown in the flowcharts. In such embodiments, the computer program can be downloaded and installed from a network via a communication device, or installed from storage device 1003, or installed from read-only memory 1002. When the computer program is executed by processing device 1001, it performs the functions defined in the methods of the embodiments disclosed in this application.
[0060] The image contour matching device provided in this application, employing the image contour matching method described in the above embodiments, can solve the technical problem of decreased matching accuracy caused by inconsistent edge feature structures in pyramid contour matching. Compared with the prior art, the beneficial effects of the image contour matching device provided in this application are the same as those of the image contour matching method described in the above embodiments, and other technical features of this image contour matching device are the same as those disclosed in the previous embodiment method, and will not be repeated here.
[0061] It should be understood that the various parts disclosed in this application can be implemented using hardware, software, firmware, or a combination thereof. In the description of the above embodiments, specific features, structures, materials, or characteristics can be combined in any suitable manner in one or more embodiments or examples.
[0062] The above description is merely a specific embodiment of this application, but the scope of protection of this application is not limited thereto. Any variations or substitutions that can be easily conceived by those skilled in the art within the scope of the technology disclosed in this application should be included within the scope of protection of this application. Therefore, the scope of protection of this application should be determined by the scope of the claims.
[0063] This application provides a computer-readable storage medium having computer-readable program instructions (i.e., a computer program) stored thereon, which are used to execute the image contour matching method described above.
[0064] The computer-readable storage medium provided in this application may be, for example, a USB flash drive, but is not limited to, electrical, magnetic, optical, electromagnetic, infrared, or semiconductor systems, devices, or any combination thereof. More specific examples of computer-readable storage media may include, but are not limited to: electrical connections having one or more wires, portable computer disks, hard disks, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fibers, portable compact disk read-only memory (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination thereof. In this embodiment, the computer-readable storage medium may be any tangible medium containing or storing a program that can be used by or in conjunction with an instruction execution system, device, or apparatus. The program code contained on the computer-readable storage medium may be transmitted using any suitable medium, including but not limited to: wires, optical cables, radio frequency (RF), etc., or any suitable combination thereof.
[0065] The aforementioned computer-readable storage medium may be included in the image contour matching device; or it may exist independently and not assembled into the image contour matching device.
[0066] The aforementioned computer-readable storage medium carries one or more programs that, when executed by an image contour matching device, cause the image contour matching device to: acquire a template image; extend the template image by its boundaries according to the total number of pyramid layers to obtain a template pyramid image; extract the average gradient magnitude of each layer of the template pyramid image; determine the contrast threshold of each layer based on the attenuation ratio of the average gradient magnitude of each layer relative to the reference magnitude value; extract edge contour feature points in the corresponding layer's template pyramid image based on the contrast threshold of each layer, forming a template feature set for each layer; map the positions of each feature point in the template feature set of adjacent lower layers to adjacent higher layers, verify the template feature sets of the adjacent higher layers, and obtain a verified template feature set for each layer; construct a search image pyramid and extract search graph features for each layer; perform sliding matching between the search graph features of each layer and the verified template feature set for the corresponding layer, mapping the matching target position layer by layer from the top to the bottom of the search image pyramid, and outputting the final matching target.
[0067] Computer program code for performing the operations of this application can be written in one or more programming languages or a combination thereof, including object-oriented programming languages such as Java, Smalltalk, and C++, as well as conventional procedural programming languages such as the "C" language or similar programming languages. The program code can be executed entirely on the user's computer, partially on the user's computer, as a standalone software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In cases involving remote computers, the remote computer can be connected to the user's computer via any type of network—including a local area network (LAN) or a wide area network (WAN)—or can be connected to an external computer (e.g., using an internet connection from an internet service provider).
[0068] The flowcharts and block diagrams in the accompanying drawings illustrate the architecture, functionality, and operation that may be implemented in systems, methods, and computer program products according to various embodiments of this application. In this regard, each block in a flowchart or block diagram may represent a module, segment, or portion of code containing one or more executable instructions for implementing the specified logical function. It should also be noted that in some alternative implementations, the functions indicated in the blocks may occur in a different order than those indicated in the drawings. For example, two consecutively indicated blocks may actually be executed substantially in parallel, and they may sometimes be executed in reverse order, depending on the functions involved. It should also be noted that each block in the block diagrams and / or flowcharts, and combinations of blocks in the block diagrams and / or flowcharts, may be implemented using a dedicated hardware-based system that performs the specified function or operation, or using a combination of dedicated hardware and computer instructions.
[0069] The modules described in the embodiments of this application can be implemented in software or hardware. The names of the modules do not necessarily limit the functionality of the unit itself.
[0070] The readable storage medium provided in this application is a computer-readable storage medium that stores computer-readable program instructions (i.e., a computer program) for executing the above-described image contour matching method. This solves the technical problem of decreased matching accuracy in pyramid contour matching due to inconsistent edge feature structures across layers. Compared with the prior art, the beneficial effects of the computer-readable storage medium provided in this application are the same as those of the image contour matching method provided in the above embodiments, and will not be elaborated upon here.
[0071] This application provides a computer program product, including a computer program that, when executed by a processor, implements the steps of the image contour matching method described above.
[0072] The computer program product provided in this application can solve the technical problem of decreased matching accuracy in pyramid contour matching due to inconsistent edge feature structures of each layer. Compared with the prior art, the beneficial effects of the computer program product provided in this application are the same as those of the image contour matching method provided in the above embodiments, and will not be repeated here.
[0073] The above are merely preferred embodiments of this application and do not limit the patent scope of this application. Any equivalent structural or procedural transformations made using the content of this application's specification and drawings, or direct or indirect applications in other related technical fields, are similarly included within the patent scope of this application.
[0074] It should be noted that, in this document, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or system that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or system. Unless otherwise specified, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or system that includes that element.
[0075] Through the above description of the embodiments, those skilled in the art can clearly understand that the methods of the above embodiments can be implemented by means of software plus necessary general-purpose hardware platforms. Of course, they can also be implemented by hardware, but in many cases the former is a better implementation method.
[0076] The above are merely preferred embodiments of this application and do not limit the patent scope of this application. Any equivalent structural or procedural transformations made using the content of this application's specification and drawings, or direct or indirect applications in other related technical fields, are similarly included within the patent protection scope of this application.
Claims
1. An image contour matching method, characterized in that, The image contour matching method includes: Obtain a template image, and expand the boundaries of the template image according to the total number of pyramid layers to obtain a template pyramid image; Extract the average gradient magnitude of each layer of the template pyramid image, and determine the contrast threshold of each layer based on the attenuation ratio of the average gradient magnitude of each layer relative to the reference magnitude value. Based on the contrast threshold of each layer, the edge contour feature points in the corresponding layer template pyramid image are extracted to form the template feature set of each layer. The positions of each feature point in the template feature set of the adjacent lower layer are mapped to the adjacent higher layer, and the template feature set of the adjacent higher layer is verified to obtain the verified template feature set of each layer. A search image pyramid is constructed and search graph features of each layer are extracted. The search graph features of each layer are then matched with the template feature set after verification of the corresponding layer. The target position is mapped from the top layer to the bottom layer of the search image pyramid, and the final matching target is output.
2. The image contour matching method as described in claim 1, characterized in that, The step of obtaining a template image and expanding the template image by its boundaries according to the total number of pyramid layers to obtain a template pyramid image includes: The boundary expansion size is determined based on the total number of pyramid layers and the size of the smoothing filter used during pyramid construction; Based on the boundary expansion size, the template image is mirrored and expanded in both the width and height directions to obtain the expanded template image; The template pyramid image is constructed based on the expanded template image.
3. The image contour matching method as described in claim 1, characterized in that, The step of extracting the average gradient magnitude of each layer of the template pyramid image and determining the contrast threshold of each layer based on the attenuation ratio of the average gradient magnitude of each layer relative to the reference magnitude value includes: The average gradient magnitude of the bottom layer of the template pyramid image is calculated as the reference magnitude value; Calculate the average gradient magnitude of the template pyramid image for each layer, and use the ratio of the average gradient magnitude of each layer to the reference magnitude value as the attenuation ratio of the corresponding layer. The contrast threshold of the corresponding layer is calculated based on the attenuation ratio of each layer and the preset contrast threshold attenuation coefficient.
4. The image contour matching method as described in claim 1, characterized in that, The step of extracting edge contour feature points from the corresponding layer template pyramid image based on the contrast threshold of each layer to form the template feature set of each layer includes: Based on the contrast threshold corresponding to each layer, the edge contour feature points are extracted from the template pyramid image of the corresponding layer; Record the position and orientation information of each edge contour feature point in the corresponding layer template pyramid image; Based on the edge contour feature points, position information, and orientation feature information extracted from each layer, a template feature set for each layer is constructed.
5. The image contour matching method as described in claim 1, characterized in that, The steps of mapping the positions of each feature point in the template feature set of adjacent lower layers to adjacent higher layers, and verifying the template feature sets of the adjacent higher layers to obtain the verified template feature sets of each layer include: The position coordinates of each feature point in the template feature set of the adjacent lower layer are mapped to the adjacent higher layer according to the downsampling factor to obtain the mapped position of each feature point in the adjacent higher layer. With each of the aforementioned mapping positions as the center, a corresponding neighborhood window is constructed according to a preset window size; In the template feature set of the adjacent high layers, feature points that fall within any of the neighborhood windows are retained, and feature points that do not fall within any of the neighborhood windows are removed, thus obtaining the template feature set after verification for each layer.
6. The image contour matching method as described in claim 1, characterized in that, The step of performing sliding matching between the search graph features of each layer and the corresponding layer's verified template feature set, mapping the target position layer by layer from the top to the bottom of the search image pyramid, and outputting the final matching target includes: Obtain the verified template feature set and the corresponding search graph features of each layer; Starting from the top of the search image pyramid, the template feature set verified in the current layer is slid-matched on the search graph feature of the corresponding layer, the matching score at each sliding position is calculated, and the matching target of the current layer is determined based on the matching score. The position of the matching target in the current layer is mapped to the next adjacent layer, and matching continues in the next adjacent layer. This process is repeated layer by layer until the bottom layer of the search image pyramid is reached, and the final matching target is output.
7. The image contour matching method as described in claim 6, characterized in that, The steps of performing sliding matching on the search graph features of the corresponding layer after the current layer is verified, calculating the matching score at each sliding position, and determining the matching target of the current layer based on the matching score include: The template feature set after the current layer is verified is slid row by row and column by column on the search graph feature of the corresponding layer. At each sliding position, the similarity between each feature point in the template feature set and the corresponding feature point on the search graph feature is calculated. The similarity of all feature points is accumulated as the matching score corresponding to the sliding position. The matching score at each sliding position is compared with a preset score threshold, and the sliding position with a matching score not lower than the preset score threshold is taken as the matching target of the current layer.
8. The image contour matching method as described in claim 7, characterized in that, The step of mapping the position of the matching target in the current layer to the adjacent next layer, continuing matching in the adjacent next layer, and mapping and matching layer by layer until the bottom layer of the search image pyramid is reached, and then outputting the final matching target, includes: The position of the matching target is scaled according to the upsampling ratio between adjacent layers, while keeping the angle unchanged, to obtain the mapping position of the matching target in the next adjacent layer. In the adjacent next layer, with the mapping position as the center, a matching search is performed within a preset neighborhood range to obtain the matching result of the matching target in the adjacent next layer; Repeat the step of mapping the position of the matching target in the current layer to the next adjacent layer until it is mapped to the bottom layer of the search image pyramid, and output the final matching target.
9. An image contour matching device, characterized in that, The image contour matching device includes: a memory, a processor, and a computer program stored in the memory and executable on the processor, the computer program being configured to implement the steps of the image contour matching method as described in any one of claims 1 to 8.
10. A storage medium, characterized in that, The storage medium is a computer-readable storage medium, and a computer program is stored on the storage medium. When the computer program is executed by a processor, it implements the steps of the image contour matching method as described in any one of claims 1 to 8.