Image template matching methods, storage media, and computers
By using an image template matching method, orientation quantization and diffusion processing are performed using the coordinate direction derivative and gradient direction map of the image. Combined with trained template feature points, fast and simplified image template matching is achieved, solving the problems of slow speed and low efficiency in existing technologies.
Patent Information
- Application Number
- CN202210475123.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-04-29
- Publication Date
- 2025-11-14
- Estimated Expiration
- 2042-04-29
AI Technical Summary
Existing image template matching techniques suffer from slow computation speed, large computational load, complex algorithms, and low recognition efficiency.
An image template matching method is adopted. By calculating the coordinate direction derivative of the input image, the gradient direction map is obtained, and orientation quantization and normalization are performed. The diffusion angle image is then used to calculate the orientation response map. By using the coordinates and orientation of the trained template feature points, similar images are found to achieve fast template matching.
It improves template matching speed, increases computational efficiency, simplifies the algorithm, and enhances recognition efficiency.
Smart Images

Figure CN114898133B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of image processing technology, and in particular to an image template matching method, a storage medium, and a computer. Background Technology
[0002] With the rise and rapid development of the artificial intelligence industry chain, image recognition technology has been widely used in the field of artificial intelligence. However, in the research and application of image recognition technology, the application of template matching technology is conducive to promoting the further development of image recognition. Therefore, it is of great significance to study template matching technology from different angles and directions.
[0003] Template matching is a technique that uses mathematical functions to compare the feature values of the search object and the template image to find the corresponding coordinate relationship. Template matching incorporates techniques such as fuzzy mathematics, differential mathematics, matrix analysis, and adaptive control. It features fast processing speed, low computational cost, simple algorithms, and high recognition efficiency.
[0004] Therefore, it is necessary to propose a new image template matching scheme. Summary of the Invention
[0005] The purpose of this invention is to provide an image template matching method, storage medium, and computer, which have a fast matching speed.
[0006] To achieve the objective of the invention, according to one aspect of the present invention, an image template matching method is provided, comprising: calculating the coordinate direction derivatives of an input image to obtain coordinate direction derivative images of the input image in the x and y directions; calculating a gradient direction map of the input image based on the coordinate direction derivative images of the input image in the x and y directions; performing orientation quantization and normalization on the gradient direction map of the input image to obtain a quantized angle image of the input image; diffusing the quantized angle image of the input image to obtain a diffused angle image of the input image; calculating an orientation response map for each orientation of the diffused angle image; linearizing the orientation response map for each orientation to obtain a linearized response map for each orientation; finding corresponding positions and corresponding linearized response images in the input image using the feature point coordinates and orientations of a trained template, thereby obtaining a similarity image; and obtaining a template matching result using the information in the similarity image, and annotating the template matching result on the input image.
[0007] According to another aspect of the present invention, a storage medium is provided that stores program instructions, wherein the image template matching method described above is executed during program execution.
[0008] According to another aspect of the present invention, a computer is provided, comprising a processor and a memory, wherein the memory stores program instructions, and the processor executes the program instructions to perform the image template matching method described above.
[0009] Compared with existing technologies, this invention obtains linearized response maps of multiple orientations of the input image. By using the feature point coordinates and orientations of the trained template, the corresponding positions and corresponding linearized response maps in the input image are found, and then similarity images are obtained, thus obtaining template matching results, which is fast. Attached Figure Description
[0010] Figure 1 This is a flowchart illustrating one embodiment of the image template matching method of the present invention. Detailed Implementation
[0011] To further illustrate the technical means and effects adopted by the present invention to achieve the intended purpose, the following detailed description of the specific implementation methods, structure, features and effects of the present invention, in conjunction with the accompanying drawings and preferred embodiments, is provided.
[0012] This invention provides an image template matching method that can improve the speed of template matching. The image template matching method uses C language to calculate the coordinate direction derivative of the input image, obtain the gradient direction corresponding to each pixel, discretize the gradient direction into 16 orientations, and then normalize these 16 orientations into 8 orientations. Cosine calculations are then performed between the calculated orientations and the orientations of the template matching feature points to obtain matching scores, thereby completing the template matching of the input image at a faster speed.
[0013] Figure 1 This is a schematic flowchart of one embodiment of the image template matching method 100 of the present invention. Figure 1 As shown, the image template matching method 100 includes the following steps.
[0014] Step 110: Calculate the coordinate direction derivatives of the input image to obtain the coordinate direction derivative images of the input image in the x and y directions.
[0015] The input image can be an RGB three-channel image, and there can be multiple images.
[0016] In one embodiment, step 110 includes: applying a Gaussian blur to the input image;
[0017] The Sobel operator is used to obtain the inverse coordinate directions in the x and y directions of the input image, thus yielding the coordinate derivative images in the x and y directions, sobel_3x and sobel_3y. Here, Gaussian blurring of the input image can eliminate the interference of image noise on template matching.
[0018] Step 120: Calculate the gradient direction map of the input image based on the coordinate direction derivative images of the input image in the x and y directions.
[0019] In one embodiment, step 120 includes: using the coordinate directional derivative images of the input image in the x and y directions to calculate the 2-norm of each pixel in each channel; comparing the 2-norm values of each channel calculated for each pixel to find the channel with the largest 2-norm; assigning the directional derivative of the channel with the largest 2-norm to the pixel corresponding to that channel to obtain the single-channel directional derivative of each pixel, thereby obtaining single-channel directional derivative maps sobel_x and sobel_y; using the single-channel directional derivative of each pixel to obtain the gradient direction of the corresponding pixel, thereby obtaining the gradient direction map sobel_ang of the input image.
[0020] Step 130: Orientation quantization and normalization are performed on the gradient direction map of the input image to obtain the quantized angle image of the input image.
[0021] In one embodiment, step 130 includes: dividing the range of angle values of the gradient direction map into M orientations; quantizing the gradient direction map based on the M orientations to obtain a quantized temporary image quantized_temp with M orientations; and normalizing the quantized temporary image with M orientations into a quantized angle image quantized_angle with N orientations, where N and M are positive integers and N = M / 2.
[0022] Specifically, in one example, N=8, M=16, and the angle values in the gradient direction map sobel_ang range from [0, 360]. The angle values are divided into 16 equal parts and represented by numbers from 0 to 15.
[0023] To eliminate the influence of edge polarity, each orientation in the quantized angle image is bitwise ORed with 7, and the orientation is normalized to 8 orientations from 0 to 7, thus obtaining a quantized angle image with 8 orientations.
[0024] Step 140: Diffusion is performed on the quantized angle image of the input image to obtain the diffusion angle image of the input image.
[0025] In one embodiment, step 140 includes: performing a spread operation on each orientation of the quantized angle image, specifically: recording the orientation with the highest frequency in the 3*3 neighborhood of each pixel of the quantized angle image; if the number of times the orientation appears exceeds a predetermined threshold, then the orientation is assigned to the pixel, thus obtaining the spread angle image spread-angle of the input image.
[0026] Step 150: Calculate the orientation response map for each orientation of the diffusion angle image.
[0027] To avoid calculating the maximum cosine of the input image orientation and the feature orientation in the template every time during subsequent template matching, we first calculate the orientation response map for each orientation of the input image and the diffusion angle image. In subsequent operations, we only need to perform a table lookup, which can improve the template matching efficiency. This step yields 8 orientation response maps (response_map).
[0028] Step 160: Linearize the orientation response map for each orientation to obtain the linearized response map for each orientation.
[0029] In one embodiment, step 150 includes: linearizing the orientation response map of each orientation according to a predetermined sampling step size T to obtain a linearized response map of each orientation. For example, if the input image is m*n, then the image linearized according to the sampling step size T is (T*T)*(m*n / T / T).
[0030] Step 170: Using the feature point coordinates and orientation of the trained template, the corresponding position and the corresponding linearized response image in the input image are found, and then the similarity image is obtained.
[0031] The pixel values in the similarity image correspond to the matching score, and the template matching status can be obtained from the image.
[0032] Collect template images as dataset C, train dataset C using a template training algorithm tool, and finally obtain the trained template Temp_Match.EHD, and calculate the feature point coordinates and orientation of the template.
[0033] Step 180: Obtain template matching results through the information of the similarity images, and annotate the template matching results on the input image.
[0034] If there are multiple template matching results on the input image, the matched feature regions are marked according to the priority of the matching, and finally the marked information is displayed on the input image.
[0035] In this invention, the orientation of the input image is calculated based on C language, and the orientation of the template matching feature points is calculated using cosine. The matching score is obtained sequentially, and then the degree of template matching of the image is measured by the calculated score, thereby achieving the effect of template matching.
[0036] Test Example 1
[0037] To verify the computational efficiency of the template matching tool written in C++, the following preparations were made for this test case: 1) Collect images to be matched as dataset A; 2) Collect template images as dataset C, and train the template file Temp_Match.EHD using a template training algorithm tool for dataset C; 3) Prepare two template matching modules: the first module is an algorithm tool written in C++, and the second module is a template matching tool written in C.
[0038] Testing Method: Testing is conducted using a flowchart. 1) Build an input image module, selecting an image as the input source (dataset A). 2) Build two template matching modules: the first, written in C (Template Matching 1), and the second, written in C++ (Template Matching 2). Runtime values are recorded for both modules. The module's computational efficiency is assessed by observing the template matching runtime. Finally, run the modules and observe the test results.
[0039] Test results: The test results showed that using template matching technology based on C language significantly improved the calculation speed compared to using template matching technology based on C++ language.
[0040] According to another aspect of the present invention, a storage medium is provided storing program instructions that are executed to perform the image template matching method 100 described above. For simplicity, the specific details of the image template matching method 100 will not be repeated here.
[0041] According to another aspect of the present invention, a computer is provided, comprising a processor and a memory, wherein the memory stores program instructions, and the processor executes the program instructions to perform the image template matching method 100 described above. For simplicity, the specific details of the image target matching and localization method are not repeated here.
[0042] In this document, the terms “comprising,” “including,” or any other variations thereof are intended to cover non-exclusive inclusion, which includes not only the elements listed but also other elements not expressly listed.
[0043] In this document, the directional terms such as front, back, top, and bottom are defined based on the location of the components in the accompanying drawings and their relative positions to each other, solely for the purpose of clarity and convenience in expressing the technical solution. It should be understood that the use of these directional terms should not limit the scope of protection claimed in this application.
[0044] Those skilled in the art will understand that embodiments of this application can be provided as methods, systems, or computer program products. Therefore, this application can take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, this application can take the form of a computer program product embodied on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0045] This application is described with reference to flowchart illustrations and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of this application. It will be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, special-purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, generate instructions for implementing the flowchart... Figure 1 One or more processes and / or boxes Figure 1 A device that provides the functions specified in one or more boxes.
[0046] These computer program instructions may also be stored in a computer-readable storage medium that can direct a computer or other programmable data processing device to function in a particular manner, such that the instructions stored in the computer-readable storage medium produce an article of manufacture including instruction means, which are implemented in a process Figure 1 One or more processes and / or boxes Figure 1 The function specified in one or more boxes.
[0047] These computer program instructions can also be loaded onto a computer or other programmable data processing device to cause a series of operational steps to be performed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions that execute on the computer or other programmable device for implementing the process. Figure 1 One or more processes and / or boxes Figure 1 The steps of the function specified in one or more boxes.
[0048] Although preferred embodiments of this application have been described, those skilled in the art, upon learning the basic inventive concept, can make other changes and modifications to these embodiments. Therefore, the appended claims are intended to be interpreted as including the preferred embodiments as well as all changes and modifications falling within the scope of this application.
Claims
1. An image template matching method, characterized in that, It includes: Calculate the coordinate directional derivatives of the input image to obtain the coordinate directional derivative images of the input image in the x and y directions; Calculate the gradient direction map of the input image based on the coordinate direction derivative images of the input image in the x and y directions; The gradient direction map of the input image is quantized and normalized to obtain the quantized angle image of the input image; The quantized angle image of the input image is diffused to obtain the diffusion angle image of the input image; Calculate the orientation response map for each orientation of the diffusion angle image; Linearize the orientation response map for each orientation to obtain the linearized response map for each orientation; By using the feature point coordinates and orientation of the trained template, the corresponding position and the corresponding linearized response image in the input image are found, and then the similarity image is obtained; and The template matching result is obtained by using information from the similar images, and the template matching result is then annotated on the input image. The process of calculating the coordinate directional derivatives of the input image to obtain the coordinate directional derivative images of the input image in the x and y directions includes: Apply Gaussian blur to the input image; The Sobel operator is used to obtain the inverse coordinate directions of the input image in the x and y directions, thereby obtaining the coordinate derivative images of the input image in the x and y directions. The step of calculating the gradient direction map of the input image based on the coordinate direction derivative images of the input image in the x and y directions includes: The 2-norm of each pixel in the input image in each channel is calculated using the coordinate derivative images of the input image in the x and y directions. Compare the L2 norm values of each channel calculated for each pixel, and find the channel with the largest L2 norm. The directional derivative of the channel with the largest 2-norm is assigned to the pixel corresponding to that channel to obtain the single-channel directional derivative of each pixel, thus obtaining the single-channel directional derivative map; The gradient direction of the corresponding pixel is obtained by using the single-channel directional derivative of each pixel, thereby obtaining the gradient direction map of the input image. The linearization of the orientation response map for each orientation to obtain the linearized response map for each orientation includes: The orientation response map for each orientation is linearized according to a predetermined sampling step size T to obtain the linearized response map for each orientation.
2. The image template matching method as described in claim 1, characterized in that, The template is obtained through training, and the feature point coordinates and orientation of the template are calculated based on the trained template.
3. The image template matching method as described in claim 1, characterized in that, The process of quantizing and normalizing the gradient direction map of the input image to obtain the quantized angle image of the input image includes: The range of angle values in the gradient direction map is divided into M orientations, and the gradient direction map is quantized based on the M orientations to obtain a quantized temporary image with M orientations. The quantized temporary image with M orientations is normalized into a quantized angle image with N orientations, where N and M are positive integers, and N = M / 2.
4. The image template matching method as described in claim 3, characterized in that, N=8, M=16 The process of normalizing a quantized temporary image with M orientations into a quantized angle image with N orientations includes: Each orientation of the quantized temporary image is bitwise ORed with 7 to obtain a quantized angle image with 8 orientations.
5. The image template matching method as described in claim 1, characterized in that, The step of diffusing the quantized angle image of the input image to obtain the diffusion angle image of the input image includes: The diffusion operation is performed on each orientation of the quantized angle image, specifically as follows: The orientation that appears most frequently in the 3*3 neighborhood of each pixel in the quantized angle image is recorded. If the number of times the orientation appears exceeds a predetermined threshold, the orientation is assigned to the pixel.
6. The image template matching method as described in claim 1, characterized in that, The calculation of the orientation response map for each orientation of the diffusion angle image includes: Calculate the orientation response map for each orientation of the input image and the diffusion angle image.
7. The image template matching method as described in claim 1, characterized in that, If there are multiple template matching results on the input image, the matched feature regions are marked according to the priority of the matching, and finally the marked information is displayed on the input image.
8. A storage medium, characterized in that, It stores program instructions that are executed to perform the image template matching method as described in any one of claims 1-7.
9. A computer, characterized in that, It includes a processor and a memory, the memory storing program instructions, and the processor executing the program instructions to perform the image template matching method as described in any one of claims 1-7.
Citation Information
Patent Citations
Real-time detection method for specific attitude
CN103793922A
Image matching method, detection device and storage medium
CN113469971A