Image template matching filtering method based on candidate pedigree tracking and hierarchical dynamic parameters
By introducing candidate lineage tracking and hierarchical dynamic parameters into the pyramid matching system, the problems of computational performance degradation and output uncertainty in large-size image processing are solved, and efficient and reliable image template matching is achieved.
Patent Information
- Application Number
- CN202611310433.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-08-27
- Publication Date
- 2026-11-24
AI Technical Summary
Existing pyramid matching systems suffer from decreased computational performance when processing large images and templates, failing to meet production cycle requirements. Furthermore, the lack of cross-level candidate lineage information leads to uncertainty in the output order, affecting system real-time performance and engineering stability.
By constructing a multi-layer image pyramid, a candidate lineage tracking mechanism is introduced, and layered dynamic parameters are applied to each layer for filtering, including three-dimensional integer bucket index binning, local matching, and threshold filtering, to ensure that candidates retain clear inheritance relationships when propagating across layers. Dynamically adjusted angle step size and filtering threshold are used to optimize computational and storage requirements.
It improves the reproducibility and engineering reliability of template matching results, reduces computational load and storage bandwidth usage, improves matching efficiency and accuracy, and ensures the determinism and robustness of matching results.
Smart Images

Figure CN123160922A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of image template matching and filtering technology, specifically to an image template matching and filtering method based on candidate lineage tracking and hierarchical dynamic parameters. Background Technology
[0002] In the field of industrial visual inspection, pyramid template matching technology based on gradient response maps is widely used for the positioning and recognition of large-sized, high-precision workpieces. This type of technology constructs a multi-layered image pyramid with progressively decreasing resolution using template images and the image to be searched. The matching process starts by screening candidate positions at the top layer with the lowest resolution, and then proceeds layer by layer to higher resolution layers to refine the candidates until the final matching result is output at the bottom layer. During the layer-by-layer process, existing systems typically need to perform deduplication on the candidates to suppress redundancy, and at each layer, determine the angle range that the candidates from the upper layer need to be checked in the next layer.
[0003] However, in existing pyramid matching systems, the key parameters used to control deduplication and neighborhood search are usually fixed values that remain constant throughout the entire pyramid, or manually adjusted within an empirical range. Since the image resolution of the coarse layer of the pyramid is much lower than that of the fine layer, the displacement of a pixel in the coarse layer corresponds to a larger range of geometric changes in the original high-resolution image. Using the same judgment criteria as the fine layer will cause the coarse layer to retain a large number of redundant candidates that should be merged, resulting in a rapid expansion of the number of candidates in the intermediate layer, making it difficult to converge, and thus causing a sharp decline in computational performance.
[0004] On the other hand, existing systems, when managing these candidates passed down layer by layer, only record basic attributes such as candidate location and similarity, without recording the evolutionary origin relationships between candidate layers in the pyramid. This results in the system's inability to distinguish the cross-level lineage background of candidates. Due to the lack of lineage information, all candidates are applied the same filtering parameters indiscriminately at each layer, making it impossible to perform differentiated convergence control based on the candidate's parent source. The combination of these problems causes the number of intermediate layer candidates to exceed the real-time computing power and storage bandwidth limits of computer processors, directly causing industrial vision systems to fail to meet production cycle requirements when processing large-size images and templates.
[0005] Furthermore, due to the lack of cross-level candidate source records and globally unique identifiers, when multiple candidates have the same similarity value, the output order of the system depends on the insertion order of the underlying container, which makes the output order of the same input in different matching processes uncertain, posing difficulties for the regression testing and engineering deployment of the system.
[0006] The aforementioned problems, exacerbated by the lack of cross-layer candidate lineage information and the disconnect between interlayer parameter scales, are particularly prominent when dealing with large-size templates and multi-angle rotation variants, severely restricting the real-time performance and engineering stability of the pyramid template matching system. Summary of the Invention
[0007] To address the shortcomings of existing technologies, this invention provides an image template matching and filtering method based on candidate lineage tracking and hierarchical dynamic parameters, which can effectively solve the problems mentioned in the background technology.
[0008] To achieve the above objectives, the present invention provides the following technical solution: an image template matching and filtering method based on candidate lineage tracking and hierarchical dynamic parameters, comprising: acquiring a template image and constructing a multi-layer image pyramid using the template image; performing full-image similarity calculation on the template image at the top layer to generate a first-generation candidate pool, and generating a globally corresponding candidate identifier for each candidate in the first-generation candidate pool; sequentially applying first-level filtering, second-level filtering, and third-level filtering to the first-generation candidate pool; starting from the second-to-last layer and proceeding downwards, performing local matching on the surviving candidates after filtering at each upper layer by expanding the angle variant template within the angle neighborhood to generate a sub-candidate pool, and generating a globally corresponding candidate identifier for each sub-candidate; sequentially applying the first-level filtering, second-level filtering, and third-level filtering to the sub-candidate pools generated at each layer; after completing local matching at the bottom layer, performing threshold filtering on the bottom layer candidates, and deduplicating the surviving candidates after threshold filtering based on position and angle overlap to obtain a final candidate set; and outputting the final candidate set in a deterministic total order by descending similarity, ascending candidate identifier, and ascending parent candidate identifier.
[0009] As a further method, the first-level filtering involves binning candidates into three-dimensional integer buckets based on their position coordinates and angles, retaining only the candidates with the highest similarity within each integer bucket. The binning of position coordinates is obtained by dividing the candidate's x-coordinate and y-coordinate by the width of the current level's position bucket and then rounding the result. The binning of angles is obtained by normalizing the candidate's angle to a preset angle range, then dividing it by the width of the current level's angle bucket and then rounding the result. The width of the angle bucket is determined by the reference angle step size and the scaling factor corresponding to the current level.
[0010] As a further method, the scaling factor is specifically the power of the downsampling ratio of the pyramid level, where the downsampling ratio is the ratio of the side lengths of adjacent level images; the angle bucket width has a greater value at the top of the pyramid than at the bottom, and the angle bucket width and the scaling factor are reduced layer by layer in the same proportion.
[0011] As a further method, in the second-level filtering process, the position determination threshold and angle determination threshold corresponding to the determination of the inhibition relationship between candidate pairs based on the continuous position distance and the surrounding angle distance are consistent with the values of the position bin width and the angle bucket width of the current level in the first-level filtering; the angle sampling interval of the angle neighborhood expansion and the angle bucket width are driven by the scaling factor; the traversal step size of the skipped part of the angle variant template in the top-level full-image similarity calculation and the angle bucket width are driven by the scaling factor.
[0012] As a further method, the reference angle step size is determined by the geometric dimensions of the template image, specifically: The width and height of the template image are obtained to determine the bounding rectangle of the template image; the length of half the diagonal of the bounding rectangle is used as the rotation radius of the farthest point of the template image; the reference angle step size is determined by the ratio of a preset resolvable displacement threshold to the rotation radius of the farthest point.
[0013] As a further method, the preset resolvable displacement threshold is corrected according to the edge direction distribution complexity of the template image to finally obtain an effective resolvable displacement threshold; the edge direction distribution complexity is obtained by extracting the gradient direction of the edge points of the template image and statistically analyzing the dispersion of its direction distribution; the preset resolvable displacement threshold is replaced with the effective resolvable displacement threshold, and the reference angle step size is recalculated.
[0014] As a further method, the third-level filtering means that the candidates that survive after passing the first-level filtering and the second-level filtering are partially sorted in descending order of similarity, and a predetermined number of candidates are retained; the predetermined number is a first number in the top layer and a second number in the middle layer, wherein the first number is greater than the second number.
[0015] Compared with the prior art, the embodiments of the present invention have at least the following advantages or beneficial effects: (1) This invention provides an image template matching filtering method based on candidate lineage tracking and hierarchical dynamic parameters. By constructing a multi-scale image pyramid and introducing a candidate lineage tracking mechanism in the process of coarse-to-fine layer matching, the candidate can retain a clear inheritance relationship when propagating across layers, thereby achieving a deterministic total order matching result in the bottom output stage, improving the reproducibility and engineering reliability of the template matching result. At the same time, by applying local suppression based on spatial and angular binning, proximity suppression based on continuous distance and surrounding angular distance, and retention amount control based on similarity ranking to the candidates in each layer, a multi-level filtering cascade structure is formed. While maintaining matching accuracy, the candidate size of each layer is greatly compressed, effectively reducing the computational amount of high-resolution matching in the lower layer, thereby reducing the occupation of processor computing power and storage bandwidth.
[0016] (2) In the first-level filtering, the position coordinates and angles of the candidates are mapped to a three-dimensional integer bucket index, and only the candidates with the highest similarity are retained in each integer bucket. This allows redundant candidates that are spatially similar and have small angle differences to be efficiently eliminated in the early stage. This method of discretizing the continuous position and angle space into a unified integer index significantly reduces the number of candidate pairs that need to be processed in the subsequent second-level filtering and local matching stages, and avoids repeated access and comparison of a large number of similar candidates in the high-resolution layer. Thus, while ensuring the matching recall rate, the computational latency and memory access overhead in the matching process are further reduced.
[0017] (3) This invention analyzes the complexity of the edge direction distribution of the template image itself, corrects the preset distinguishable displacement threshold, and dynamically determines the reference angle step size accordingly. This allows the angle sampling density to be adaptively adjusted according to the texture structure features of the template image. For templates with complex edge direction distribution and rich details, matching can be performed with a finer angle step size, improving the accuracy and robustness of matching. For templates with relatively simple edge directions, matching can be completed with a coarser angle step size, avoiding unnecessary angle variant expansion and similarity calculation. This ensures the reliability of matching while improving the overall matching efficiency and reducing the consumption of computing resources. Attached Figure Description
[0018] The present invention will be further described with reference to the accompanying drawings, but the embodiments in the drawings do not constitute any limitation on the present invention. For those skilled in the art, other drawings can be obtained based on the following drawings without creative effort.
[0019] Figure 1 This is a schematic diagram of the method flow of the present invention.
[0020] Figure 2 This is a schematic diagram of the candidate lineage tracing involved in the present invention.
[0021] Figure 3 This is a flow chart of the three-stage filtration pipeline involved in the present invention. Detailed Implementation
[0022] The technical solutions of the present invention will be clearly and completely described below with reference to the accompanying drawings of the embodiments of the present invention. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. All other embodiments obtained by those skilled in the art based on the embodiments of the present invention without creative effort are within the scope of protection of the present invention.
[0023] This embodiment relies on a computer processing system, which includes a processor and a memory. The processor executes computer program instructions stored in the memory to perform tasks such as loading and storing template images, constructing and storing image pyramids, generating and caching similarity response maps, generating and updating candidate records, and filtering and deduplicating candidates. The execution of each of these steps is based on the numerical computation and data storage capabilities of the computer system.
[0024] The first-level filtering involves binning using three-dimensional integer bucket indices. This is achieved by the processor mapping the candidate's position coordinates and angle values to integer indices after numerical calculations. The partitioning and merging of each integer bucket are performed within the processor's memory using data structure operations. The second-level filtering only suppresses candidates with the same category identifier. This is done by the processor comparing the position and angle fields in the candidate records to generate suppression flags. The third-level filtering involves partial sorting, which is achieved by the processor rearranging the candidate array in-place using a sorting algorithm.
[0025] Reference Figure 1The diagram illustrates the method flow of this invention. This invention provides an image template matching and filtering method based on candidate lineage tracking and hierarchical dynamic parameters, comprising: acquiring a template image and a search image, and constructing a multi-layer image pyramid using the template image; performing full-image similarity calculation on the template image at the top layer to generate a first-generation candidate pool, and generating globally corresponding candidate identifiers for each candidate in the first-generation candidate pool, setting the parent candidate identifier as the root candidate identifier; sequentially passing the first-generation candidate pool through first-level filtering, second-level filtering, and third-level filtering; and, starting from the second-to-top layer and proceeding downwards, filtering each layer of candidates that survive the upper-level filtering process. In the first step, local matching is performed on the angle variant template within the angle neighborhood to generate a sub-candidate pool. A globally corresponding candidate identifier is generated for each sub-candidate, and the parent candidate identifier is pointed to the candidate identifier of the upper-level candidate from which it originates. The first-level filtering, the second-level filtering, and the third-level filtering are applied sequentially to the sub-candidate pools generated at each layer. After local matching is completed at the bottom layer, threshold filtering is performed on the bottom-level candidates, and the candidates that survive after threshold filtering are deduplicated based on position and angle overlap to obtain the final candidate set. The final candidate set is output as a deterministic total order in descending order of similarity, ascending order of candidate identifier, and ascending order of parent candidate identifier.
[0026] In this embodiment, the template image is a pre-established standard image containing the edge gradient direction features of the target object, used to locate the region matching the target object in the image to be searched; the image to be searched is the original input image acquired by the industrial vision system to detect the existence of the target object; the template image is obtained by reading a pre-generated template file from a template library, and the image to be searched is obtained by reading the original image data to be detected from an industrial camera or image storage medium. The multi-layer image pyramid is an image sequence obtained by downsampling the template image layer by layer according to a fixed downsampling ratio. The ratio of the image side length of adjacent layers is the downsampling ratio, and the downsampling ratio is exemplarily taken as 2:1, that is, the top layer is the coarsest layer with the lowest resolution, and the bottom layer is the original image layer with the highest resolution; the process of constructing the multi-layer image pyramid is as follows: taking the original template image as the finest layer, i.e., the bottom layer, the image side length is reduced proportionally layer by layer according to the downsampling ratio to obtain several layers of images with progressively decreasing resolution from the bottom layer to the top layer. The top layer is the coarsest layer with the lowest resolution in the pyramid, the second-to-top layer is the layer below the top layer, and the bottom layer is the finest layer with the highest resolution in the pyramid, which is the layer where the original template image is located. The layers are refined layer by layer from the top layer to the bottom layer in the direction of increasing pyramid level number.
[0027] The full-image similarity calculation involves comparing the features of the template image at the corresponding level with the features of the corresponding region of the search image at each possible location in the top-level pyramid image. A similarity score for each location is calculated by accumulating gradient direction responses. The final result is a similarity response map of the same size as the search image at the top-level resolution. Each pixel value in this response map represents the matching similarity of the template at that location. The first-generation candidate pool is generated by extracting all locations in the similarity response map that have similarity scores reaching a preset top-level threshold. These locations and their corresponding angular variant information are then added to the first-generation candidate pool as candidate records. The candidate identifier is a globally unique positive integer, sequentially assigned by an atomic incrementing counter during candidate generation, used to uniquely identify each candidate. The parent candidate identifier records the identifier of the upper-level candidate from which the current candidate originates. In the first-generation candidates generated at the coarsest layer, the parent candidate identifier is uniformly set to the root candidate identifier. The root candidate identifier is a reserved value that does not conflict with any legitimate candidate identifier, exemplarily taking the value of -1 or the maximum value of a 64-bit unsigned integer, used to indicate that the candidate has no upper-level source.
[0028] The surviving candidates refer to those that are retained, not suppressed, or truncated after the first, second, and third levels of filtering. Expanding angle variant templates within the angle neighborhood for local matching means: for each surviving candidate in the upper layer, taking its corresponding angle value, and expanding a predetermined number of angle step sizes on both sides of that angle value as the angle neighborhood; calculating the local similarity of the rotation variant template at each angle step size position within that neighborhood near the corresponding position in the current layer of the image to be searched; the angle variant template is a plurality of rotation variants obtained by rotating the template image around its geometric center by an angle step size, each rotation variant corresponding to a discrete angle value. The method for generating the sub-candidate pool is as follows: matching results in each local match whose similarity exceeds the current layer threshold are added to the sub-candidate pool as sub-candidates, and a new globally unique candidate identifier is assigned to each sub-candidate; the parent candidate identifier is pointed to the candidate identifier of the upper-layer candidate from which it originates, that is, the candidate identifier value of the upper-layer parent candidate on which the sub-candidate was based is recorded in the sub-candidate record, thereby establishing a cross-layer parent-child tracing relationship.
[0029] like Figure 2The diagram illustrates the candidate lineage tracing method of this invention. It uses a candidate tree to show the evolution of the parent-child relationship between the coarsest-level candidate and the pyramid levels. Each node in the diagram is labeled with a candidate identifier, a parent candidate identifier, and a triplet of the attribute of the level it belongs to. The candidate identifier is a globally unique integer value that increases sequentially with the candidate generation order. The parent candidate identifier is used to record the identifier of the upper-level candidate from which the current candidate originates. The coarsest-level node is the candidate generated at the top level, and its parent candidate identifier is uniformly set to the root candidate identifier, indicating that the candidate has no upper-level source and is the root node of the lineage tree. The intermediate-level nodes are the child candidates generated layer by layer from the second-to-last level. Their parent candidate identifiers point to the candidate identifier of the parent candidate directly from which they originate, thereby establishing a clear parent-child pointing relationship between adjacent levels. The arrows in the diagram point from the parent candidate at the top to the child candidate at the bottom, representing the propagation and transmission path of candidates during the layer-by-layer refinement of the pyramid. The same coarsest-layer candidate can expand into multiple child candidate branches from different neighborhoods via intermediate layers, forming a candidate tree structure rooted at the coarsest-layer candidate. Each layer in the tree corresponds to a level in the pyramid. The number of nodes within a layer gradually converges due to the upper limit constraint of the three-level filtering pipeline. The final matching result can be traced back up the parent candidate identifier chain from any leaf node to the coarsest-layer ancestor, completely reconstructing the candidate's evolutionary history from the top to the finest layer. This provides data support for tracing the source of matching results and locating anomalies. This diagram visually illustrates the candidate lineage tracking mechanism.
[0030] Threshold filtering of the bottom-level candidates refers to comparing the similarity scores of all candidates with a preset final similarity threshold after local matching is completed at the finest layer. Candidates with similarity scores that reach or exceed the threshold are retained, while those below the threshold are discarded. The final result is the set of candidates that survive after the final threshold determination. Deduplication of the candidates that survive after threshold filtering based on position and angle overlap means that before the final output, a non-maximum suppression operation based on continuous position distance and surrounding angle distance is used. For candidate pairs whose position distance is less than a preset position overlap threshold and whose angle distance is less than a preset angle overlap threshold, only the candidate with the highest similarity is retained, and other overlapping candidates are suppressed. The final set of candidates is the final candidate set. The process of outputting the final candidate set in a deterministic total order by descending similarity, ascending candidate identifier, and ascending parent candidate identifier is as follows: For all candidates in the final candidate set, they are first sorted from high to low similarity scores. When similarity scores are the same, they are sorted from small to large candidate identifiers. If candidate identifiers are still the same, they are sorted from small to large parent candidate identifiers. After forming a deterministic total order relationship, the position coordinates, angle, and similarity score of each candidate are output sequentially as the final matching result.
[0031] In this embodiment, after local matching is completed at the bottom layer, the processor performs threshold filtering on the bottom layer candidates, and the processor performs deduplication on the candidates that survive after threshold filtering based on position and angle overlap.
[0032] The deterministic total order output is executed by the processor. The processor reads the similarity field, candidate identifier field, and parent candidate identifier field of each candidate record in the final candidate set. It then calls a sorting algorithm to sort the records in descending order of similarity (first sorting key), ascending order of candidate identifier (second sorting key), and ascending order of parent candidate identifier (third sorting key). After sorting, the processor outputs the sorted candidate records sequentially to the upper-level caller or storage medium. Since the candidate identifier and parent candidate identifier in the sorting key are globally unique and strictly incrementing values assigned by the processor during candidate generation using atomic incrementing counters, and do not depend on the insertion order or memory address of the candidates in the container, the output order after sorting the same input in different executions is completely consistent.
[0033] Specifically, the first-level filtering involves binning candidates into three-dimensional integer buckets based on their position coordinates and angles, retaining only the candidates with the highest similarity within each bucket. The position coordinate binning is obtained by dividing the candidate's x-coordinate and y-coordinate by the width of the current level's position bucket and then rounding. The angle binning is obtained by normalizing the candidate's angle to a preset angle range, then dividing it by the current level's angle bucket width and then rounding. The angle bucket width has different values at different levels of the multi-layer image pyramid, and is determined by a reference angle step size and a scaling factor corresponding to the current level. The scaling factor monotonically increases with the pyramid level.
[0034] It should be explained that the three-dimensional integer bucket index binning refers to mapping each candidate to a three-dimensional integer coordinate grid, where the three dimensions correspond to the horizontal coordinate binning index, the vertical coordinate binning index, and the angle binning index, respectively. Each integer bucket is a group of candidates with the same three-dimensional integer index. The integer bucket is a grouping container uniquely determined by the three-dimensional integer index, and all candidates mapped to the same three-dimensional index are grouped into the same bucket. The similarity is the similarity score calculated by the candidate during the matching process, which is obtained by calculating the cumulative gradient direction response between the template and the image region to be searched at the corresponding pyramid level. The position binning width of the current level is determined by the product of the reference position step size and the scaling factor of the current level. The reference position step size is exemplarily taken as 1 pixel, which means the width of the basic spatial unit used for position deduplication at the current level resolution. The rounding is all down-rounding, that is, the quotient after dividing the horizontal coordinate by the position binning width is taken as the largest integer not exceeding the quotient. The same processing is applied to the vertical coordinate and the angle. Normalizing the candidate angles to a preset angle range means mapping the candidate angle values to a half-open interval of 0 to 360 degrees through a modulo operation. The normalization formula is: normalized angle value = mod(mod(angle, 360) + 360, 360), where mod refers to the modulo operation, i.e., taking the remainder, to ensure that all angle values are aligned within the same circumferential period; the preset angle range is 0 to 360 degrees.
[0035] It performs coarse-grained deduplication of a large candidate pool in linear time complexity, retaining only the candidates with the highest similarity in each integer bucket. This can quickly eliminate redundant candidates caused by positional and angular proximity, providing a candidate set with a significantly reduced size for subsequent fine filtering.
[0036] Furthermore, the scaling factor is specifically the power of the downsampling ratio of the pyramid level, where the downsampling ratio is the ratio of the side lengths of adjacent level images; the angle bucket width has a greater value at the top of the pyramid than at the bottom, and the angle bucket width decreases layer by layer from the top to the bottom of the pyramid in the same proportion as the scaling factor, so that the range of pixels merged due to the reduction in image resolution in the coarse layer remains consistent with the magnification factor of the angle bucket width.
[0037] It should also be noted that the term "level exponent" refers to a power operation with the downsampling ratio as the base and the pyramid level number as the exponent, i.e., scaling factor = downsampling ratio. (层级编号) The layer numbering starts from the bottom layer, with the bottom layer numbered as 0 and the top layer numbered as the maximum layer number minus 1. The ratio of the side lengths of adjacent layer images refers to the ratio of the corresponding side lengths between two adjacent layers in the pyramid. An example value of 2 indicates that the side length of the upper layer image is half the side length of the lower layer image.
[0038] In one specific implementation, the first-level filtering is performed by the processor. The processor reads the position coordinates and angle values of each candidate record in the current level's candidate pool. It divides the x-coordinate and y-coordinate by the current level's position bin width and rounds down to obtain the x-coordinate bin index and y-coordinate bin index, respectively. It normalizes the angle to the range of 0 to 360 degrees, divides it by the current level's angle bin width, and rounds down to obtain the angle bin index. These three integer indices together constitute a three-dimensional integer bucket index. The processor groups candidates with the same three-dimensional integer bucket index into the same integer bucket, retaining only the candidate with the highest similarity within each integer bucket, and deleting or marking the remaining candidates in that integer bucket as suppressed. The above binning and retention process is entirely completed by the processor through numerical comparisons and memory read / write operations.
[0039] Specifically, in the second-level filtering process, the position determination threshold and angle determination threshold corresponding to the determination of the inhibition relationship between candidate pairs based on continuous position distance and surrounding angle distance are consistent with the values of the position bin width and angle bucket width of the current level in the first-level filtering; the angle sampling interval of the angle neighborhood expansion and the angle bucket width are driven by the scaling factor and change synchronously with the pyramid level; the traversal step size of the skipped angle variant template in the top-level full-image similarity calculation and the angle bucket width are driven by the scaling factor and change synchronously with the pyramid level.
[0040] It should be explained that the continuous position distance refers to the Euclidean distance or Manhattan distance between two candidates, that is, the absolute values of the differences in the horizontal and vertical coordinates are within the position determination threshold range. The surrounding angle distance refers to the minimum difference in the angles of two candidates on a 360-degree circle, calculated as surrounding angle distance = min(|angle difference|, 360 - |angle difference|), where angle difference refers to the numerical difference in the angles of the two candidates. The specific method for determining the inhibition relationship between candidate pairs is as follows: during the process of traversing candidates in descending order of similarity, for the current high-scoring candidate, all low-scoring candidates that have not yet been suppressed are traversed. When the absolute value of the difference in the horizontal coordinate between the low-scoring candidate and the current high-scoring candidate does not exceed the position determination threshold, the absolute value of the difference in the vertical coordinate does not exceed the position determination threshold, the surrounding angle distance does not exceed the angle determination threshold, and the two candidates belong to the same category, the low-scoring candidate is marked as suppressed. The position determination threshold is the position bin width value of the current level, and the angle determination threshold is the angle bin width value of the current level. The angle sampling interval refers to the angle difference between two adjacent sampled rotation variants when expanding the angle neighborhood in the intermediate layer. This angle sampling interval is determined by the product of the reference angle step size and the current level scaling factor. The skipped angle variant template traversal step size refers to the selection of angle variant templates for matching at a predetermined step size interval when matching the entire top-level image. This is because the resolution of the coarsest layer is low and the template response difference between adjacent angles is small. The traversal step size is determined by the product of the reference angle step size and the current level scaling factor, so that the intermediate angle templates are skipped in the coarse layer and then replenished in the subsequent fine layer through neighborhood expansion, thereby reducing the computational load of coarse layer matching.
[0041] By using continuous distance metrics to repair boundary artifacts generated by the first-level hard binning, suppression is only implemented when candidate pairs are sufficiently close in both position and angle. This avoids the problem of adjacent candidates being incorrectly preserved or suppressed at the boundaries of integer bins. At the same time, category identification isolation ensures that candidates from different template categories do not interfere with each other.
[0042] Furthermore, the reference angle step size is determined by the geometric dimensions of the template image, specifically as follows: The width and height of the template image are obtained to determine the bounding rectangle of the template image; the length of half the diagonal of the bounding rectangle is used as the radius of rotation of the farthest point when the template image rotates around the geometric center; the reference angle step size is determined by the ratio of a preset resolvable displacement threshold to the radius of rotation of the farthest point; the larger the size of the template image, the larger the radius of rotation of the farthest point, and the smaller the reference angle step size.
[0043] It should be further explained that the width and height of the template image are directly read from the pixel size information of the template image. The circumscribed rectangle is the smallest upright rectangle that exactly encloses the template image, and its width is equal to the width of the template image and its height is equal to the height of the template image. The half-diagonal length refers to half the diagonal length of the circumscribed rectangle, and the calculation formula is half-diagonal length = 0.5 × sqrt(width). 2 +height 2 ), sqrt refers to the square root operation, and this length is used as the estimated value of the rotation radius of the farthest pixel point when the template rotates around the geometric center; the distinguishable displacement threshold is a preset pixel distance constant, with an exemplary value of 1.0 pixel, which means the minimum distinguishable edge displacement that adjacent angle buckets need to achieve at the farthest point, used to ensure that the matching response of adjacent angle templates is spatially distinguishable at the geometric level.
[0044] Specifically, the preset resolvable displacement threshold is corrected based on the edge direction distribution complexity of the template image to obtain an effective resolvable displacement threshold. The edge direction distribution complexity is obtained by extracting the gradient direction of the edge points of the template image and calculating the dispersion of its direction distribution. The more dispersed the direction distribution of the template, the higher its edge direction distribution complexity, and the smaller the corrected effective resolvable displacement threshold. The preset resolvable displacement threshold is replaced with the effective resolvable displacement threshold, and the reference angle step size is recalculated.
[0045] In the above, the specific method for correcting the preset resolvable displacement threshold based on the edge direction distribution complexity of the template image is as follows: An inverse proportional correction function δeff = δ / (1 + λ × C) is used, where δ is the preset resolvable displacement threshold, C is the edge direction distribution complexity index, and λ is the correction intensity coefficient, exemplarily set to 2.0. The correction result δeff is the effective resolvable displacement threshold. When the template direction distribution complexity is higher, the value of C is larger, and the effective resolvable displacement threshold is smaller, thus further tightening the angle step size. The specific process for extracting the gradient direction of the edge points of the template image and statistically analyzing the dispersion of the direction distribution to obtain the edge direction distribution complexity is as follows: First, the gradient direction of each edge point of the template image is calculated using the Sobel operator. The gradient direction is then uniformly divided into a preset number D direction buckets, with an unsigned direction modulus of 180 degrees. For example, D = 18. The number of edge points falling into each direction bucket is counted to obtain a direction histogram, which is then normalized to a probability distribution p. i , i represents the number of the directional bucket, i=1,2,3,...,D; then calculate the normalized directional entropy Hnorm=-{[Σ(p i ×log(p) i ))] / log(D)}, and calculate the length of the composite vector of the double-angle circle statistics rlen=sqrt{[(Σcos(2×θj )) / N] 2 +[(Σsin(2×θ j )) / N] 2}, θ j Let represent the gradient direction angle of the j-th edge point, where j represents the index number of the edge point, j=1, 2, 3, ..., N, and N is the total number of edge points in the template image. The directional dispersion V=1-rlen is obtained. Finally, the normalized directional entropy and directional dispersion are weighted and fused to obtain the directional distribution complexity index C=clamp(0.5×Hnorm+0.5×V, 0, 1). clamp is a numerical constraint function (also called a truncation function or clamping function). The larger the index value, the more dispersed the directional distribution of the template edges, the more complex the structure, and the more sensitive it is to rotation. The effect of recalculating the baseline angle step size is that templates with complex directional structures obtain smaller angle step sizes after being tightened by the effective displacement threshold, resulting in denser angle quantization and thus ensuring the rotation matching accuracy of high-complexity templates. Templates with simple directional structures use larger angle step sizes to reduce the number of redundant angle templates and improve matching efficiency.
[0046] In one specific implementation, the second-level filtering is performed by the processor. The processor traverses the candidate records that survived the first-level filtering in descending order of similarity. For the currently traversed high-scoring candidate, the processor reads its position coordinates, angle value, and category identifier. It then sequentially reads the corresponding fields of the low-scoring candidates that have not yet been suppressed from the candidate pool. The processor calculates the absolute value of the difference between the horizontal and vertical coordinates of the two candidates, as well as the surrounding angle distance. When the above three values do not exceed the position determination threshold, position determination threshold, and angle determination threshold of the current level, and the two candidates belong to the same category identifier, the processor marks the low-scoring candidate as suppressed and no longer participates in subsequent comparisons and outputs. All numerical comparisons and marking operations in the above determination process are performed by the processor's arithmetic logic unit.
[0047] Furthermore, the third-level filtering refers to partially sorting the candidates that survive after passing the first-level and second-level filtering by descending similarity, and retaining a predetermined number of candidates (in other words, retaining the top-ranked and predetermined number of candidates). The predetermined number is a first number in the top layer and a second number in the middle layer. The first number is greater than the second number. The first number is the maximum number of candidates retained in the top layer after the third-level filtering, with an exemplary value of 500, used to retain a large number of candidates in the early stage of candidate generation to ensure recall. The second number is the maximum number of candidates retained in the middle layer after the third-level filtering, with an exemplary value of 200, used to further tighten the candidate scale during the process of candidate transfer to the fine layer. The specific values of the first and second numbers are determined according to the requirements of recall and computational efficiency in the business scenario. The first number is greater than the second number to ensure that the coarse-layer candidate coverage is wide enough and the fine-layer candidate scale is compact enough.
[0048] The predetermined number in the intermediate layer is the second number, so that the number of candidates in the intermediate layer is converged to within the second number before entering the next layer; the predetermined number in the top layer is the first number, so that the top layer retains more candidates in the early stage of candidate generation to ensure recall; the bottom layer does not perform the first level filtering, the second level filtering and the third level filtering, and the candidate deduplication in the bottom layer is completed by an independent output deduplication operation.
[0049] In one specific implementation, the third-level filtering is performed by the processor. The processor rearranges the candidates that survive the first and second-level filtering by calling a partial sorting algorithm in descending order of similarity. A predetermined number of candidates are retained in the candidate pool after sorting, while candidates exceeding the predetermined limit are deleted or marked. The partial sorting algorithm is performed by the processor in linear time complexity, determining only the positions of the predetermined number of largest elements without completely sorting all candidates, thereby reducing computational overhead.
[0050] By partially sorting and truncating the number of candidates in linear time complexity, the size of candidates passed down at each level is strictly controlled within a predetermined upper limit, avoiding the exponential growth of the number of candidates as the level moves down. At the same time, the top level uses a larger truncation upper limit to retain sufficient candidate recall potential, while the middle level uses a smaller truncation upper limit to control computational overhead, forming a funnel-shaped convergence of the number of candidates from coarse to fine.
[0051] like Figure 3The diagram shows the three-stage filtering pipeline of this invention, illustrating the gradual convergence and evolution of the candidate pool's candidate number after passing through three progressive filtering stages, with the data flow arranged horizontally from left to right. The input candidate pool is located on the far left of the flow, with the top-level pool having the largest number of candidates, while the middle-level pool's candidate number is relatively controllable due to the upper limit constraint of the first K truncation of the upper-level pool. The first stage is binning for deduplication, where candidates are binned according to three-dimensional integer bucket indices for horizontal, vertical, and angular binning. Only the candidate with the highest similarity is retained in each bin, and the rest are directly removed. This stage has linear complexity, enabling large-scale coarse screening while maintaining recall and significantly reducing the number of candidates. The second stage is greedy distance deduplication, where surviving candidates from the first stage are greedily traversed and judged in descending order of similarity, using continuous position distance and surrounding angle distance as suppression criteria. Different categories of candidates are isolated by category identifiers to avoid cross-class false suppression. This stage is used to repair boundary artifacts generated by the hard binning in the first stage, further reducing the candidate size while ensuring accuracy. The third stage is the first K truncation. The surviving candidates from the second stage are sorted linearly in descending order of similarity. A predetermined number of candidates at the top of the sorted list are retained, while those exceeding the upper limit are hard-truncated and discarded. The top layer uses a larger truncation upper limit to ensure coarse-level recall, while the middle layers use a smaller truncation upper limit to control computational load. This stage has linear complexity, and the number of candidates is controlled within the predetermined upper limit after truncation. The three-stage filtering follows a progressive design philosophy from left to right: coarse screening, fine screening, and hard truncation. This gradually converges the number of candidates from the maximum input to a controllable small scale at the output, corresponding to the aforementioned three-stage filtering progression.
[0052] In summary, the matching output order is strictly reproducible due to the introduction of candidate identifiers and parent candidate identifiers, eliminating output uncertainty; the angle step size is adaptively adjusted according to the complexity of the template edge direction distribution, balancing the accuracy of complex templates with the efficiency of simple templates; after the three-level filtering is connected in series, the sum of the computational cost of each level is much smaller than the computational cost of a single fine filtering, and the candidate convergence effect exceeds the superposition of the individual effects of each level, forming a synergistic effect of coarse screening, fine screening, and hard truncation. Under the premise of maintaining matching accuracy, low latency and high stability template matching filtering are achieved.
[0053] The above description is merely an example and illustration of the structure of the present invention. Those skilled in the art can make various modifications or additions to the specific embodiments described, or use similar methods to replace them, as long as they do not deviate from the structure of the invention or exceed the scope defined in the claims, all of which should fall within the protection scope of the present invention.
Claims
1. An image template matching filter method based on candidate lineage tracking and hierarchical dynamic parameters, characterized in that, include: Obtain a template image and construct a multi-layered image pyramid using the template image; At the top level, a full-image similarity calculation is performed on the template image to generate a first-generation candidate pool, and a globally corresponding candidate identifier is generated for each candidate in the first-generation candidate pool. The first-generation candidate pool is sequentially filtered through first-level filtering, second-level filtering, and third-level filtering. Starting from the second-to-top layer and working downwards, for each candidate that survives the filtering of the upper layer, the angle variant template is expanded in the angle neighborhood for local matching to generate a sub-candidate pool, and a globally corresponding candidate identifier is generated for each sub-candidate. For each of the sub-candidate pools generated at each layer, the first-level filter, the second-level filter, and the third-level filter are applied sequentially. After completing local matching at the bottom layer, threshold filtering is performed on the bottom layer candidates, and the candidates that survive after threshold filtering are deduplicated based on position and angle overlap to obtain the final candidate set. The final candidate set is output as a deterministic total order in descending order of similarity, ascending order of candidate identifier, and ascending order of parent candidate identifier.
2. The image template matching filtering method based on candidate pedigree tracking and hierarchical dynamic parameters according to claim 1, characterized in that: The first-level filtering involves binning candidates into three-dimensional integer buckets based on their position coordinates and angles, retaining only the candidates with the highest similarity within each integer bucket; The binning of the position coordinates is obtained by dividing the candidate's x-coordinate and y-coordinate by the width of the current level's position bin and then rounding them down. The angle binning is obtained by normalizing the candidate angles to a preset angle range, dividing by the angle bin width of the current level, and then rounding down. The angle bin width is determined by the reference angle step size and the scaling factor corresponding to the current level.
3. The image template matching filtering method based on candidate pedigree tracking and hierarchical dynamic parameters according to claim 2, characterized in that: The scaling factor is specifically the downsampling ratio of the pyramid level raised to the level power, where the downsampling ratio is the ratio of the side lengths of adjacent level images; The angle barrel width is greater at the top of the pyramid than at the bottom, and the angle barrel width and the scaling factor decrease in the same proportion layer by layer.
4. The image template matching filtering method based on candidate pedigree tracking and hierarchical dynamic parameters according to claim 3, characterized in that: In the second-level filtering process, the position determination threshold and angle determination threshold corresponding to the determination of the inhibition relationship between candidate pairs by continuous position distance and surrounding angle distance are consistent with the values of the position bin width and the angle bin width of the current level in the first-level filtering. The angle sampling interval of the expanded angle neighborhood and the angle bucket width are driven by the scaling factor; The traversal step size of the skipped portion angle variant template in the top-level full-image similarity calculation and the width of the angle bucket are driven by the scaling factor.
5. The image template matching filtering method based on candidate pedigree tracking and hierarchical dynamic parameters according to claim 4, characterized in that: The reference angle step size is determined by the geometric dimensions of the template image, specifically: Obtain the width and height of the template image to determine the bounding rectangle of the template image; The length of half the diagonal of the circumscribed rectangle is used as the rotation radius of the farthest point of the template image; The reference angle step size is determined by the ratio of a preset resolvable displacement threshold to the rotation radius of the farthest point.
6. The image template matching filtering method based on candidate pedigree tracking and hierarchical dynamic parameters according to claim 5, characterized in that: The preset resolvable displacement threshold is corrected according to the edge direction distribution complexity of the template image to finally obtain an effective resolvable displacement threshold. The edge direction distribution complexity is obtained by extracting the gradient direction of the edge points of the template image and calculating the dispersion of the direction distribution; The preset resolvable displacement threshold is replaced with the effective resolvable displacement threshold, and the reference angle step size is recalculated.
7. The image template matching filtering method based on candidate pedigree tracking and hierarchical dynamic parameters according to claim 6, characterized in that: The third-level filtering means that the candidates that survive after passing the first-level filtering and the second-level filtering are partially sorted in descending order of similarity, and a predetermined number of candidates are retained. The predetermined quantity is a first quantity at the top layer and a second quantity at the middle layer, wherein the first quantity is greater than the second quantity.
