Template matching method, electronic device and storage medium

Through image registration and template adjustment techniques, target template images that adapt to scale and angle are generated, which solves the matching difficulties of traditional template matching methods under scale scaling and angle rotation, and improves matching efficiency and accuracy.

CN118644692BActive Publication Date: 2024-12-10BYD CO LTD
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202411093094.1
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-08-09
Publication Date
2024-12-10
Estimated Expiration
2044-08-09

AI Technical Summary

Technical Problem

Traditional template matching methods easily fail to match the target area when scale scaling or angle rotation occurs in the image to be matched, and the calculation is large and time-consuming.

Method used

Obtain the registration results of the scaling scale and rotation angle through image registration, adjust the initial template image to generate the target template image, ensure that the target template image matches the target area, and use multiple adjustments to process the target template images of multiple scales and angles to match all Possible target areas.

Benefits of technology

It effectively solves the limitations of single template image matching, reduces the algorithm's calculation amount and time consumption, and ensures accurate matching at different scales and angles.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118644692B_ABST
    Figure CN118644692B_ABST
Patent Text Reader

Abstract

The present application discloses a template matching method, electronic device and storage medium. The method includes performing image registration on the registration image area corresponding to the initial template image in the image to be matched and the initial template image to obtain a registration result, and the registration result includes at least one of a scaling scale and a rotation angle; adjusting the initial template image according to the registration result to generate a target template image; performing template matching on the image to be matched according to the target template image to obtain various target areas in the image to be matched that match the target template image. In this way, when the target area is scaled or rotated relative to the initial template image, the present application can adjust the initial template image in a targeted manner according to the registration result, and then accurately match the target areas at various scales and angles in the image to be matched according to the target template image, thereby effectively solving the limitations of using an existing single template image for template matching.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of template matching technology, and more specifically, to a template matching method, an electronic device, and a non-volatile computer-readable storage medium. Background Art

[0002] Template matching is a method for matching image regions similar to a template image within an image. Traditional template matching methods have certain limitations, primarily because the template image is only moved parallel to the image to be matched, sliding from left to right and from top to bottom to traverse all pixel regions in the image to be matched that may contain the target region. If the target region in the image to be matched is scaled or rotated relative to the template image, traditional template matching methods may fail to match the target region. Summary of the Invention

[0003] This application provides a template matching method, an electronic device, and a non-volatile computer-readable storage medium.

[0004] The template matching method of the embodiment of the present application includes performing image registration on the registration image area corresponding to the initial template image in the image to be matched and the initial template image to obtain a registration result, wherein the registration result includes at least one of a scaling scale and a rotation angle; adjusting the initial template image according to the registration result to generate a target template image; and performing template matching on the image to be matched according to the target template image to obtain each target area in the image to be matched that matches the target template image.

[0005] The electronic device of the embodiment of the present application includes a processor, a memory, and a computer program, wherein the computer program is stored in the memory and executed by the processor, and the computer program includes instructions for executing a template matching method. The template matching method includes performing image registration on a registration image region corresponding to an initial template image in an image to be matched and the initial template image to obtain a registration result, wherein the registration result includes at least one of a scaling factor and a rotation angle; adjusting the initial template image according to the registration result to generate a target template image; and performing template matching on the image to be matched according to the target template image to obtain target regions in the image to be matched that match the target template image.

[0006] The non-volatile computer-readable storage medium of this application includes a computer program that, when executed by a processor, causes the processor to perform a template matching method. The template matching method includes image registration of a registration image region in an image to be matched that corresponds to an initial template image and the initial template image to obtain a registration result, the registration result including at least one of a scaling scale and a rotation angle; adjusting the initial template image according to the registration result to generate a target template image; and performing template matching on the image to be matched according to the target template image to obtain target regions in the image to be matched that match the target template image.

[0007] The template matching method, electronic device, and non-volatile computer-readable storage medium of this application first perform image registration on the registered image region of the image to be matched and the initial template image to obtain a registration result. The registration result includes at least one of scaling scale and rotation angle. The registration result can be used to reflect the scaling scale and / or rotation angle between the target region and the initial template image. Therefore, the initial template image can be adjusted according to the registration result to generate a target template image, such that the scale and angle between the target template image and the target region are matched. Then, template matching can be performed on the image to be matched according to the target template image to accurately obtain each target region in the image to be matched. When there are target regions with multiple angles or multiple scales in the image to be matched, the initial template image can be adjusted multiple times to generate the corresponding target template image, ensuring that target regions of all scales and angles in the image to be matched can be obtained in the end. In this way, when the target area is scaled or rotated relative to the initial template image, the present application can also adjust the initial template image in a targeted manner according to the alignment results, and then accurately match the target area at various scales and angles in the image to be matched based on the target template image, thereby effectively solving the limitations of template matching using an existing single template image.

[0008] Additional aspects and advantages of the embodiments of the present application will be given in part in the description below, and in part will become obvious from the description below, or will be learned through practice of the embodiments of the present application. BRIEF DESCRIPTION OF THE DRAWINGS

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

[0010] Figure 1 is a schematic flow chart of a template matching method according to certain embodiments of the present application;

[0011] Figure 2 is a schematic diagram of a scenario of a template matching method in certain embodiments of the present application;

[0012] Figure 3 is a schematic flow chart of a template matching method according to certain embodiments of the present application;

[0013] Figure 4 is a schematic flow chart of a template matching method according to certain embodiments of the present application;

[0014] Figure 5 is a schematic flow chart of a template matching method according to certain embodiments of the present application;

[0015] Figure 6 is a schematic flow chart of a template matching method according to certain embodiments of the present application;

[0016] Figure 7 is a schematic flow chart of a template matching method according to certain embodiments of the present application;

[0017] Figure 8 is a schematic flow chart of a template matching method according to certain embodiments of the present application;

[0018] Figure 9 This is a schematic diagram of a template matching device according to certain embodiments of this application;

[0019] Figure 10 is a schematic structural diagram of an electronic device according to some embodiments of the present application;

[0020] Figure 11 This is a schematic diagram illustrating the connection state of a non-volatile computer-readable storage medium and a processor in certain embodiments of this application. DETAILED DESCRIPTION

[0021] The embodiments of the present application are described in detail below. Examples of the embodiments are shown in the accompanying drawings, wherein the same or similar reference numerals represent the same or similar elements or elements having the same or similar functions throughout. The embodiments described below with reference to the accompanying drawings are exemplary and are only used to explain the embodiments of the present application, and should not be understood as limiting the embodiments of the present application.

[0022] Template matching is a method for matching image regions within an image that are similar to a template image. For example, template matching can be used to locate die (chip units) on a wafer, allowing probe testing of the die-to-chip circuit connectivity.

[0023] Traditional template matching methods have certain limitations. The main limitation is that the template image only moves horizontally within the image to be matched, that is, it slides from left to right and from top to bottom to traverse and match all pixel regions in the image to be matched that may contain the target region. If the target region in the image to be matched is scaled or rotated relative to the template image, the traditional template matching method is prone to failing to match the target region.

[0024] To address the impact of scaling and rotation of the target region on template registration results, a common approach is to scale and rotate the template image at multiple scales and angles, performing multiple passes over the source image. However, matching templates at every scale and angle increases the computational complexity exponentially, especially when the target region undergoes random rotations or scale changes within the image. This computational complexity becomes even greater, and the algorithm takes significantly longer to execute.

[0025] To address the aforementioned technical problems, this application provides a template matching method, which will be described in detail below:

[0026] Please see Figure 1 This application provides a template matching method, which includes:

[0027] Step 011: Perform image registration between the registration image region in the image to be matched and the initial template image to obtain the registration result. The registration result includes at least one of the scaling scale and rotation angle.

[0028] Specifically, the initial template image can be determined based on the region where the target element of the object to be matched is located in the preset matching image of the object to be matched. It can be understood that the region where the target element is located in the image is the target region. For example, if the object to be matched is a wafer, the target element is a die on the wafer, the preset matching image is an image of the wafer, and the target region is the region where the die is located, then the initial template image can be determined based on the image of the region where the die is located on the wafer.

[0029] For example, an object to be matched can be placed on the operating table, ensuring that the target components on the object are not tilted. Then, a camera is used to capture an image of the object to be matched, which serves as a preset matching image. In this preset matching image, the target area is not tilted. Then, an image of a specific target area within the preset matching image can be acquired to obtain an initial template image.

[0030] It is understandable that for multiple objects belonging to the same category to be matched, the same initial template image can be used to perform template matching on each object. For example, before performing template matching on multiple objects, an initial template image can be obtained based on one of the objects to be matched and stored. Subsequently, template matching on multiple objects can be performed based on this initial template image.

[0031] The camera in the scene can be used to obtain the image to be matched of the object to be matched. It should be noted that the object to be matched corresponding to the image to be matched and the object to be matched corresponding to the preset matching image are the same. The shooting height and shooting angle of each camera in the scene may be different, resulting in the scaling and rotation angle of the target area of ​​the image to be matched relative to the initial template image may change. For example Figure 2 In the image to be matched, the objects to be matched include target element A and target element B. Clearly, there is an angular difference between the target regions corresponding to target element A and target element B in the image to be matched and the initial template image. Furthermore, the sizes of the target regions in the image to be matched may differ; for example, a wafer may have grains of various sizes.

[0032] Therefore, the image to be matched can be traversed by sliding to obtain a registration image region corresponding to the initial template image. For example, a pixel region with the same size as the initial template image can be used as the registration image region. The image to be matched can be traversed according to a preset step size and preset movement direction to select the registration image region. For example, the preset movement direction is from left to right and from top to bottom, and the preset step size is 1 pixel. In actual implementation, the preset step size can be appropriately increased to speed up image registration.

[0033] Then, image registration can be performed on the initial template image and the registration image region to obtain a registration result, wherein the registration result includes at least one of scaling scale and rotation angle. It can be understood that scaling scale refers to the relative scaling scale between the registration image region and the initial template image, and rotation angle refers to the relative rotation angle between the registration image region and the initial template image.

[0034] For example, the Fourier-Mellin transform method is a frequency domain transform method. During the image registration process, it is often necessary to deal with issues such as translation, rotation, scale transformation, occlusion, and deformation. The Fourier-Mellin transform method can effectively handle translation, rotation, scaling, and occlusion, making it a highly robust method. Therefore, based on the Fourier-Mellin transform method, the registration image region corresponding to the initial template image in the image to be matched can be registered with the initial template image to obtain a registration result, which includes the scaling scale, rotation angle, matching degree, and position offset between the registration image region and the initial template image.

[0035] Step 012: Adjust the initial template image according to the registration result to generate a target template image;

[0036] Specifically, at least part of the registered image area contains the target area, so the scaling and rotation angle between the target area in the image to be matched and the initial template image can be determined based on the registration result. Then the initial template image is adjusted according to the scaling and rotation angle. For example, the initial template image is reduced or enlarged according to the scaling to generate the target template image; or the initial template image is rotated according to the rotation angle to generate the target template image; or the initial template image can be reduced or enlarged according to the scaling, and the initial template image can be rotated according to the rotation angle to generate the target template image. In this way, the generated target template image matches the scale and angle of the target area, thereby ensuring that the target area can be accurately identified based on the target template image later. For example Figure 2 Based on the registration results of the initial template image and the registration image region corresponding to the target element A, the target template image C can be generated. It can be found that the scale and angle of the target template image C match those of the target region corresponding to the target element A.

[0037] The registration result may also include a degree of match. As will be appreciated, a higher degree of match indicates that the corresponding registered image region contains more of the target region. Therefore, based on the registration results corresponding to the registered image regions with higher degrees of match, the scaling and rotation angle between the target region and the initial template image can be determined. The initial template image can then be adjusted based on the scaling and rotation angle to generate the target template image, thereby ensuring the accuracy of the target template image.

[0038] Step 013: Perform template matching on the image to be matched based on the target template image to obtain each target region in the image to be matched that matches the target template image.

[0039] Specifically, the image to be matched can be traversed by sliding to obtain the matching image region corresponding to the target template image, and template matching can be performed on the matching image region based on the target template image to obtain each target region in the image to be matched that matches the target template image.

[0040] For example, the Normalized Cross-Correlation (NCC) template matching algorithm is a commonly used grayscale template matching algorithm. Its basic principle is to slide a window of the same size as the target template within the image to be matched and perform a correlation operation on the pixel values ​​within the window with those of the target template. The peak position of the correlation coefficient is used to determine the location of the target element. The NCC template matching algorithm is a standard pixel-based template matching method that is less susceptible to factors such as lighting and noise, and provides better matching stability. Therefore, the NCC template matching algorithm can be used to perform template matching between the target template image and the matching image area to obtain the target area.

[0041] It can be understood that the target template image has been specifically adjusted according to the registration result, so that the matching degree between the target template image and the target area is higher, so that all target areas matching the target template image can be more accurately identified and obtained in the image to be matched.

[0042] If the target elements on the object to be matched are of the same size, the rotation angle and scale between each target region in the image to be matched and the initial template image are roughly the same. Therefore, after adjusting the initial template image once based on the registration results, the generated target template image can be used to match all target regions in the image to be matched.

[0043] If there are target elements of different sizes on the object to be matched, the target template image can be adjusted multiple times. For example, Figure 2 , there are target elements A and target elements B on the object to be matched, and the size of target element A is larger than that of target element B. First, the initial template image can be adjusted according to the registration result corresponding to target element A to generate a target template image C corresponding to target element A. Then, template matching is performed on the image to be matched based on the target template image C, so that the target areas corresponding to all target elements A in the image to be matched can be obtained. Then, the initial template image is adjusted according to the registration result corresponding to target element B to generate a target template image D corresponding to target element B. Then, template matching is performed on the image to be matched based on the target template image D, so that the target areas corresponding to all target elements B in the image to be matched can be obtained. In this way, the target areas corresponding to target element A and the target areas corresponding to target element B can be obtained on the image to be matched, and thus all target areas can be obtained on the image to be matched.

[0044] The template matching method according to an embodiment of the present application first performs image registration on the registration image region of the image to be matched and the initial template image to obtain a registration result, which includes at least one of a scale and a rotation angle. The registration result can be used to reflect the scale and / or rotation angle between the target region and the initial template image. Therefore, the initial template image can be adjusted based on the registration result to generate a target template image so that the target template image matches the target region in both scale and angle. Next, template matching can be performed on the image to be matched based on the target template image to accurately obtain each target region in the image to be matched. If the image to be matched contains target regions at multiple angles or scales, the initial template image can be adjusted multiple times to generate corresponding target template images, ensuring that target regions at all scales and angles in the image to be matched are ultimately obtained. Thus, even if the target region is scaled or rotated relative to the initial template image, the present application can also adjust the initial template image specifically based on the registration result. The target template image can then be used to accurately match the target region at various scales and angles in the image to be matched, effectively addressing the limitations of existing template matching methods using a single template image.

[0045] In addition, compared with existing methods that perform template matching based on each scale and each angle, this application can determine the scaling scale and rotation angle value of the initial template image relative to the target region, and adjust and update the template image in a timely manner, avoiding template matching by blindly adjusting the template image at multiple scales and angles, thereby reducing the computational load of the algorithm and reducing the time consumption.

[0046] Please see Figure 3 In some implementations, the registration result also includes position offset and matching degree. Step 011: Perform image registration between the registration image region in the image to be matched that corresponds to the initial template image and the initial template image to obtain the registration result, including:

[0047] Step 0111: obtaining a plurality of registration image regions corresponding to the size of the initial template image in the image to be matched;

[0048] Step 0112: performing image registration on the multiple registration image regions and the initial template image respectively to obtain multiple registration results;

[0049] Step 012: Adjusting the initial template image according to the registration result to generate a target template image, including:

[0050] Step 0121: Adjust the scaling scale and rotation angle of the registered image region corresponding to the position offset is less than the preset offset threshold and the matching degree is greater than the first preset matching degree threshold to generate the target template image.

[0051] Specifically, the registration result also includes a position offset and a matching degree. For the registered image region containing the target area, the matching degree is relatively high. When the geometric center of the target area in the registered image region coincides with the geometric center of the initial template image, the position offset is minimized, ideally close to 0.

[0052] The preset offset threshold is the maximum value of the positional offset between the registered image area and the initial template image when the geometric center position of the target area is close to the geometric center position of the initial template image and the registered image area includes most of the target element area, for example, 10pix. The first preset matching threshold is the minimum value of the matching degree between the registered image area and the initial template image when the registered image area includes most of the target element area, for example, 0.7, where the matching threshold range is limited to the interval [0,1].

[0053] By sliding the image to be matched based on the initial template image, multiple registered image regions corresponding to the size of the initial template image can be obtained. Image registration can then be performed on each of these registered image regions and the initial template image to obtain multiple registration results. Once the position offset corresponding to a registered image region is less than a preset offset threshold and the matching degree is greater than a first preset matching degree threshold, sliding the image to be matched is stopped. Simultaneously, the template image is adjusted based on the scale and rotation angle corresponding to the registered image regions whose position offset is less than the preset offset threshold and whose matching degree is greater than the first preset matching degree threshold to generate the target template image.

[0054] It can be understood that at this time the registration image area contains most of the target element area, so the adjusted target template image has a high degree of matching with the target area in the image to be matched, so that the target area in the image to be matched can be accurately identified based on the target template image, thereby improving the matching accuracy.

[0055] Please see Figure 4 In some implementations, the registration result also includes position offset and matching degree. Step 011: Perform image registration between the registration image region in the image to be matched that corresponds to the initial template image and the initial template image to obtain the registration result, including:

[0056] Step 0111: obtaining a plurality of registration image regions corresponding to the size of the initial template image in the image to be matched;

[0057] Step 0112: performing image registration on the multiple registration image regions and the initial template image respectively to obtain multiple registration results;

[0058] Step 012: Adjusting the initial template image according to the registration result to generate a target template image, including:

[0059] Step 0122: Adjust the template image according to the zoom scale and rotation angle corresponding to the registration image region with the smallest position offset and the greatest matching degree to generate a target template image.

[0060] Specifically, when sliding across the image to be matched based on the initial template image, a plurality of registration image areas corresponding to the size of the initial template image can be obtained. Then, the plurality of registration image areas and the initial template image can be separately registered to obtain a plurality of registration results. It can be understood that the registration image area with the smallest position offset and the largest degree of matching contains the largest area of ​​the target element, and its corresponding rotation angle can be used to accurately reflect the rotation angle between the target area and the initial template image, and the corresponding scaling can be used to accurately reflect the scaling between the target area and the initial template image. Therefore, the initial template image can be scaled and rotated according to the scaling and rotation angle corresponding to the registration image area with the smallest position offset and the largest degree of matching to generate a target template image, ensuring a high degree of matching between the target template image and the target area in the image to be matched, thereby ensuring the subsequent matching accuracy.

[0061] Please see Figure 5 In some implementations, step 013: performing template matching on the image to be matched based on the target template image to obtain each target region in the image to be matched that matches the target template image, including:

[0062] Step 0131: Select matching image regions in the image to be matched according to the preset step size and preset movement direction to obtain multiple matching image regions;

[0063] Step 0132: Match the matching image regions based on the target template image to determine the matching degree of each matching image region;

[0064] Step 0133: Determine the target area based on the matching image area whose matching degree is higher than a second preset matching degree threshold.

[0065] Specifically, the second preset matching degree threshold is the minimum matching degree between the matched image region and the initial template image when the matched image region includes most of the target element, for example, 0.85. The range of the second preset matching degree threshold is [0, 1], which can be set according to the strictness of the specific matching requirements.

[0066] The system can traverse the image to be matched based on a preset step size and a preset movement direction to select matching image regions and obtain multiple matching image regions. For example, the preset movement direction is from left to right and from top to bottom, and the preset step size is 1 pixel. In actual implementation, the preset step size can be appropriately increased to speed up image matching.

[0067] The matching image regions are then matched against the target template image to obtain a matching degree for each matching image region. If the matching degree is less than a second predetermined matching degree threshold, it can be assumed that the target component has not been matched, or that the matching image region contains a relatively small area of ​​the target component. If the matching degree is greater than the second predetermined matching degree threshold, it can be confirmed that the matching image region contains a substantial portion of the target component, and therefore the matching image region can be confirmed as the target region.

[0068] In this way, the target template image can be used to accurately obtain the target area in the image to be matched, thereby improving the matching accuracy.

[0069] Please see Figure 6 In some embodiments, step 0133: determining the target area based on the matching image area having a matching degree higher than a second preset matching degree threshold includes:

[0070] Step 01331: Perform non-maximum suppression processing on the matching image areas whose matching degree is higher than a second preset matching degree threshold to determine the target area so that any two adjacent target areas do not overlap.

[0071] Specifically, when the target matching template slides and traverses the matching on the image to be matched, there may be more than one matching image area with a matching degree higher than the second preset matching degree threshold in the neighborhood of the local best matching position coordinates, resulting in the possibility of overlapping between multiple matching image areas with a matching degree higher than the second preset matching degree threshold.

[0072] Therefore, after obtaining matching image regions with a matching degree greater than a second preset matching degree threshold, non-maximum suppression processing can be further performed on the matching image regions with a matching degree greater than the second preset matching degree threshold to determine the target region. That is, the matching image region with the highest matching degree within a preset range is selected as the target region corresponding to the preset range, and other matching image regions within the preset range are not selected as target regions. It will be understood that after the non-maximum suppression processing, any two adjacent target regions do not overlap.

[0073] In this way, when obtaining a matching image area with a matching degree higher than a second preset matching degree threshold, the non-maximum suppression method can be used to suppress the local overlapping areas that may exist, and the local best matching result can be used as the target area, so that multiple best target areas can be obtained in the end.

[0074] Please see Figure 7 In some embodiments, the control method further comprises:

[0075] Step 014: Mark the area corresponding to the target area in the image to be matched, and no longer perform image registration and template matching in the marked area;

[0076] The process involves re-entering the image to be matched and performing image registration between the registered image region corresponding to the initial template image and the initial template image to obtain the registration result. The registration result includes at least one of the scaling scale and rotation angle steps, until no new target region can be obtained.

[0077] Specifically, after determining the target area, a mark can be set on the area corresponding to the target area in the image to be matched. For example, a mask can be set on the area corresponding to the target area in the image to be matched. A mask is generally referred to as a baffle. For example, when engraving or painting, a mask of a specific shape is placed on the material to be modified. The desired pattern can be obtained by fitting the shape of the baffle. For example, a mask is set on the area corresponding to the target area in the image to be matched, and the mask value of this area is set to 0. The mask values ​​of other areas in the image to be matched are set to 1. The mask is a binary image with the same size as the image to be matched. The corresponding area in the image to be matched with a mask value of 0 will no longer participate in subsequent image registration and template matching. Therefore, after determining the target area and setting the mark, the area in the image to be matched where the target area has been identified will no longer undergo subsequent image registration and template matching, thereby reducing the computational complexity of subsequent image registration and template matching.

[0078] Then re-enter step 011 to step 013, and when executing the above steps, the marked area is no longer subjected to image registration and template matching. After obtaining the target area, step 014 is executed again, that is, step 011 to step 014 is executed in a loop. In the case that no new target area can be obtained, it can be considered that all target areas of the image to be matched have been obtained. Therefore, the loop can be ended at this time, and the matching results are output based on the obtained target areas, such as the size of each target area and the coordinates of the center point of each target area, so as to facilitate subsequent operations based on the matching results. It should be noted that during the loop execution process, the template image used each time step 011 is executed is the initial template image to ensure that the subsequent image registration steps can be executed normally.

[0079] Thus, this application can set markers on the image to be matched so that the regions corresponding to the markers in the image to be matched will no longer participate in subsequent image registration and template matching. This ensures that all target regions in the image to be matched can be obtained, while reducing the computational load and time consumption of the image registration and template matching processes.

[0080] Please see Figure 8 In some embodiments, the control method further comprises:

[0081] Step 015: Identify the target area in the preset matching image, and determine the initial template image based on the target area with the largest size.

[0082] Specifically, the preset matching image is an image of the object to be matched. The sizes of the target elements of the object to be matched may be the same or different, so that the preset matching image may have target areas of different sizes. In this case, the target areas of the preset target image can be identified, and the size of each target area can be obtained. Then, the initial template image is determined based on the target area with the largest size to ensure that the initial template image contains most of the target element area, so as to facilitate subsequent image registration operations. For example Figure 2 In the example, an initial template image may be set according to the target area of ​​the target component A.

[0083] Meanwhile, marking the regions in the image to be matched that correspond to the target region, and in the case that there are target regions of different sizes in the image to be matched, determining the initial template image based on the largest target region can also ensure that the computational load of subsequent image registration and template matching gradually decreases.

[0084] For example Figure 2 , the image to be matched contains a target region corresponding to target element A and a target region corresponding to target element B. Since the initial template image is determined based on the target region in the preset matching image, and the image to be matched and the initial template image correspond to the same object to be matched, the initial template image and the target region corresponding to target element A have the highest degree of match. At this point, the initial template image is first adjusted based on the target region corresponding to target element A, so that all target regions corresponding to target elements A in the image to be matched can be subsequently matched. Then, a mark is set for the region corresponding to the target region corresponding to target element A in the image to be matched. It can be understood that after the mark is set, the area in the image to be matched that can be used for image registration and template matching is greatly reduced. The initial template image is then adjusted based on the target region corresponding to target element B, so that all target regions corresponding to target elements B in the image to be matched can be subsequently matched. It can be understood that the image registration and template matching areas in this process are smaller, which greatly reduces the computational complexity of image registration and template matching.

[0085] Please see Figure 9In order to facilitate better implementation of the template matching method of the embodiment of the present application, the embodiment of the present application also provides a template matching device 10. The template matching device 10 may include a registration module 11, an adjustment module 12 and a matching module 13. The registration module 11 is used to perform image registration on the registration image area corresponding to the initial template image in the image to be matched and the initial template image to obtain a registration result, and the registration result includes at least one of a scaling scale and a rotation angle. The adjustment module 12 is used to adjust the initial template image according to the registration result to generate a target template image. The matching module 13 is used to perform template matching on the image to be matched according to the target template image to obtain each target area in the image to be matched that matches the target template image.

[0086] The registration module 11 is used to perform image registration on the registration image region corresponding to the initial template image in the image to be matched and the initial template image based on the Fourier-Mellin transform method to obtain a registration result.

[0087] The registration module 11 is configured to obtain multiple registration image regions in the image to be matched that correspond to the dimensions of the initial template image; and to perform image registration on each of the multiple registration image regions and the initial template image to obtain multiple registration results. The adjustment module 12 is configured to adjust the template image based on the scale and rotation angle corresponding to the registration image regions whose positional offset is less than a preset offset threshold and whose matching degree is greater than a first preset matching degree threshold, to generate a target template image.

[0088] The registration module 11 is used to obtain multiple registration image regions in the image to be matched that correspond to the dimensions of the initial template image; and to perform image registration on each of these registration image regions and the initial template image to obtain multiple registration results. The adjustment module 12 is used to adjust the template image based on the scale and rotation angle corresponding to the registration image region with the smallest positional offset and the highest degree of match, thereby generating a target template image.

[0089] The adjustment module 12 is configured to reduce or enlarge the initial template image according to a zoom scale to generate a target template image; and / or rotate the initial template image according to a rotation angle to generate a target template image.

[0090] The matching module 13 is used to select matching image areas in the image to be matched according to a preset step size and a preset moving direction to obtain multiple matching image areas; match the matching image areas according to the target template image to determine the matching degree of each matching image area; and determine the target area based on the matching image areas whose matching degree is higher than a second preset matching degree threshold.

[0091] The matching module 13 is configured to perform non-maximum suppression processing on the matching image regions with a matching degree higher than a second preset matching degree threshold to determine the target region so that any two adjacent target regions do not overlap.

[0092] The template matching device 10 further includes a marking module 14 and a loop module 15. The marking module 14 is configured to mark the region of the image to be matched that corresponds to the target region, and image registration and template matching are no longer performed in the marked region. The loop module 15 is configured to re-register the registration image region of the image to be matched that corresponds to the initial template image with the initial template image to obtain a registration result, which includes at least one of scaling and rotation steps, until no new target region can be obtained.

[0093] The template matching device 10 further includes a determination module 16. The determination module 16 is configured to identify a target region in a preset matching image and determine an initial template image according to the target region with the largest size.

[0094] The template matching device 10 is described above from the perspective of a functional module in conjunction with the accompanying drawings. The functional module can be implemented in hardware, can be implemented by instructions in software, or can be implemented by a combination of hardware and software modules. Specifically, the steps of the method embodiment in the embodiment of the present application can be completed by the hardware integrated logic circuit and / or software instructions in the processor. The steps of the method disclosed in the embodiment of the present application can be directly embodied as being executed by a hardware encoding processor, or can be executed by a combination of hardware and software modules in the encoding processor. Optionally, the software module can be located in a mature storage medium in the art such as a random access memory, a flash memory, a read-only memory, a programmable read-only memory, an electrically erasable programmable memory, a register, etc. The storage medium is located in the memory, and the processor reads the information in the memory and completes the steps in the above method embodiment in conjunction with its hardware.

[0095] Please see Figure 10 The electronic device 100 of an embodiment of the present application includes a processor 20, a memory 30 and a computer program, wherein the computer program is stored in the memory 30 and executed by the processor 20, and the computer program includes instructions for executing the template matching method of any of the above embodiments.

[0096] Please see Figure 11 The embodiment of the present application also provides a non-volatile computer-readable storage medium 300, on which a computer program 310 is stored. When the computer program 310 is executed by the processor 320, the steps of the template matching method of any of the above-mentioned embodiments are implemented. For the sake of brevity, they are not repeated here.

[0097] In the description of this specification, the reference terms "certain embodiments", "in an example", "exemplarily", etc. mean that the specific features, structures, materials or characteristics described in conjunction with the embodiments or examples are included in at least one embodiment or example of the present application. In this specification, the schematic representations of the above terms do not necessarily refer to the same embodiment or example. Moreover, the specific features, structures, materials or characteristics described may be combined in any one or more embodiments or examples in a suitable manner. In addition, those skilled in the art may combine and combine the different embodiments or examples described in this specification and the features of the different embodiments or examples, unless they are mutually inconsistent.

[0098] Any process or method description in a flowchart or otherwise described herein may be understood to represent a module, segment or portion of code comprising one or more executable instructions for implementing the steps of a specific logical function or process, and the scope of the preferred embodiments of the present application includes alternative implementations in which functions may be performed out of the order shown or discussed, including performing functions in a substantially simultaneous manner or in the reverse order depending on the functions involved, which should be understood by those skilled in the art to which the embodiments of the present application belong.

[0099] Although the embodiments of the present application have been shown and described above, it can be understood that the above embodiments are exemplary and cannot be understood as limitations on the present application. Ordinary technicians in this field can change, modify, replace and modify the above embodiments within the scope of the present application.

Claims

1. A template matching method, It is characterized in that The method comprises: Performing image registration on a registration image region corresponding to an initial template image in an image to be matched and the initial template image to obtain a registration result, wherein the registration result includes at least one of a scaling scale and a rotation angle; Adjusting the initial template image according to the registration result to generate a target template image; Performing template matching on the image to be matched according to the target template image to obtain each target area in the image to be matched that matches the target template image; The step of performing image registration on the registration image region corresponding to the initial template image in the image to be matched and the initial template image to obtain a registration result includes: Acquire a plurality of registration image regions corresponding to the sizes of the initial template image in the image to be matched; Performing image registration on the plurality of registration image regions and the initial template image respectively to obtain a plurality of registration results, wherein the registration results also include a position offset and a matching degree; The adjusting the initial template image according to the registration result to generate a target template image includes: adjusting the template image according to the zoom scale and rotation angle corresponding to the registration image region whose position offset is less than a preset offset threshold and whose matching degree is greater than a first preset matching degree threshold, so as to generate a target template image; or The template image is adjusted according to the zoom scale and the rotation angle corresponding to the registration image region with the smallest position offset and the largest matching degree to generate a target template image.

2. The template matching method according to claim 1, It is characterized in that The step of performing image registration on the registration image region corresponding to the initial template image in the image to be matched and the initial template image to obtain a registration result includes: Based on the Fourier-Mellin transform method, the registration image region corresponding to the initial template image in the image to be matched is registered with the initial template image to obtain a registration result.

3. The template matching method according to claim 1, It is characterized in that The adjusting the initial template image according to the registration result to generate a target template image includes: According to the scaling scale, reducing or enlarging the initial template image to generate the target template image; and / or The initial template image is rotated according to the rotation angle to generate the target template image.

4. The template matching method according to claim 1, It is characterized in that The performing template matching on the image to be matched according to the target template image to obtain each target area in the image to be matched that matches the target template image includes: According to a preset step length and a preset moving direction, a matching image region is selected in the image to be matched to obtain a plurality of matching image regions; Matching the matching image regions according to the target template image to determine the matching degree of each matching image region; The target area is determined based on the matching image area whose matching degree is higher than a second preset matching degree threshold.

5. The template matching method according to claim 4, It is characterized in that The determining the target area based on the matching image area whose matching degree is higher than a second preset matching degree threshold further includes: Non-maximum suppression processing is performed on the matching image regions whose matching degree is higher than a second preset matching degree threshold to determine the target region, so that any two adjacent target regions do not overlap.

6. The template matching method according to claim 1, It is characterized in that The method further comprises: Setting a mark on the area corresponding to the target area in the image to be matched, and no longer performing image registration and template matching on the marked area; Re-enter the process of performing image registration on the registration image area in the image to be matched corresponding to the initial template image and the initial template image to obtain a registration result, wherein the registration result includes at least one of a scaling step and a rotation angle step, until no new target area can be obtained.

7. The template matching method according to claim 1, It is characterized in that The method further comprises: A target area in a preset matching image is identified, and the initial template image is determined according to the target area with the largest size.

8. An electronic device, It is characterized in that include: Processor, memory; and A computer program, wherein the computer program is stored in the memory and executed by the processor, and the computer program includes instructions for executing the template matching method according to any one of claims 1 to 7.

9. A non-volatile computer-readable storage medium containing a computer program, It is characterized in that When the computer program is executed by a processor, the processor is caused to execute the template matching method according to any one of claims 1 to 7.

Citation Information

Patent Citations

  • Image processing method and device based on template matching, equipment and medium

    CN114140631A