A template image matching method and device, electronic equipment and storage medium
By constructing a grayscale pyramid and comparing feature pixel blocks layer by layer, the accuracy and speed issues of template matching under illumination noise are solved, and efficient template image matching is achieved.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-10-18
- Publication Date
- 2026-03-20
AI Technical Summary
Existing template matching methods suffer from low accuracy and high computational cost under the influence of illumination noise, making it difficult to complete matching quickly.
By constructing grayscale pyramids of template and search images, feature pixel blocks are determined using a set sampling interval, and comparisons are performed layer by layer. The similarity calculation formula of feature pixel blocks is used for matching, reducing the amount of comparison calculations for the entire image.
While resisting the effects of lighting noise, it improves the accuracy and speed of template matching and reduces the amount of computation.
Smart Images

Figure CN115601570B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of image analysis, and in particular to a template image matching method and device, electronic equipment and a storage medium. BACKGROUND
[0002] Template matching is an important method in the field of computer vision and image processing technology. By using a template image to search and compare in a search image, the highest similarity candidate region is found as the matching result, so that the target in the search image is found. Traditional template matching is to compare the gray values of image pixels, for example, the corresponding pixels in the corresponding regions of the template image and the search image are compared one by one to obtain the absolute value, or the difference values generated by the corresponding pixels are squared and summed, and the smaller the generated value is, the higher the similarity is. The region with the highest similarity is taken as the matching result. However, when the search image is affected by light noise, the matching will fail. Considering the influence of light, the corresponding discrimination function in the prior art uses a normalized cross-correlation calculation formula, which greatly improves the matching accuracy but increases the calculation amount and reduces the matching speed.
[0003] Therefore, a scheme capable of resisting light influence to a certain extent and quickly completing template matching has important research significance. SUMMARY
[0004] Therefore, a scheme capable of resisting light influence to a certain extent and quickly completing template matching has important research significance.
[0005] An aspect of an embodiment of the present application provides a template image matching method, which comprises the following steps.
[0006] The gray scale of a template image, a template image pyramid generated based on the gray scale of the template image, the gray scale of a search image, and a search image pyramid generated based on the gray scale of the search image are obtained, and the image layers of the template image pyramid and the search image pyramid are the same;
[0007] In a first top layer image of the template image pyramid and a second top layer image of the search image pyramid, a plurality of sampling pixel points and a feature pixel block corresponding to each sampling pixel point are determined according to a set sampling interval, respectively;
[0008] The feature pixel block of the first top layer image is compared with the feature pixel block of the second top layer image, and a top layer matching region with the highest similarity to the first top layer image in the second top layer image is obtained;
[0009] According to the top layer matching area, layer-by-layer comparison is performed on each layer image of the search image pyramid except the top layer image, until a bottom layer matching area with the highest similarity to the bottom layer image of the template image pyramid is determined in the bottom layer image of the search image pyramid as a target matching area of the template image on the search image.
[0010] Optionally, the process of determining the feature pixel block corresponding to the sampling point comprises:
[0011] A square pixel block composed of the sampling pixel point and eight surrounding pixel points is determined.
[0012] If there are three pixel points on at least one side of the four sides of the pixel block, and the number of pixel points with an absolute value of pixel difference higher than a preset segmentation threshold between the target pixel point reaches a preset number, the pixel block is determined as a feature pixel block.
[0013] The target pixel point is located outside the pixel block, and the target pixel point is adjacent to the pixel block.
[0014] Optionally, the comparison of the feature pixel blocks of the first top layer image and the feature pixel blocks of the second top layer image comprises:
[0015] A plurality of first search regions with the same size as the first top layer image are determined in the second top layer image.
[0016] For each first search region, each feature pixel block of the first top layer image is compared with a feature pixel block at a corresponding position in the first search region.
[0017] Optionally, the process of comparing each layer image of the search image pyramid except the top layer image comprises:
[0018] The reference coordinates of a preset reference point in the matching area of the last layer search image are determined.
[0019] A second search region of the current layer search image is determined according to the reference coordinates.
[0020] The feature pixel blocks on the template image corresponding to the current layer search image are compared with the feature pixel blocks in the second search region.
[0021] Optionally, the calculation formula of the similarity between the feature pixel block of the template image and the feature pixel block at the corresponding position of the search image is:
[0022]
[0023] Wherein, L represents the similarity of the feature pixel block of the template image and the feature pixel block of the corresponding position of the search image, t represents the pixel value of the sampling pixel point in the feature pixel block on the template image, t1 represents the pixel value of the pixel point except the sampling pixel point in the feature pixel block on the template image, s represents the pixel value of the sampling pixel point in the feature pixel block on the search image, and s1 represents the pixel value of the pixel point except the sampling pixel point in the feature pixel block on the search image.
[0024] Another aspect of the embodiment of the present application further provides a matching device of a template image, which comprises:
[0025] An image acquisition unit is configured to acquire the gray scale of a template image, a template image pyramid generated based on the gray scale of the template image, the gray scale of a search image, and a search image pyramid generated based on the gray scale of the search image, wherein the image layers of the template image pyramid and the search image pyramid are the same;
[0026] A pixel block determination unit is configured to determine a plurality of sampling pixel points and the corresponding feature pixel blocks of each sampling pixel point in the first top layer image of the template image pyramid and the second top layer image of the search image pyramid respectively according to a set sampling interval.
[0027] A pixel block comparison unit is configured to compare the feature pixel blocks of the first top layer image with the feature pixel blocks of the second top layer image to obtain a top layer matching region with the highest similarity to the first top layer image in the second top layer image.
[0028] A target region matching unit is configured to compare the top layer matching region in each layer image of the search image pyramid except the top layer image layer by layer until a bottom layer matching region with the highest similarity to the bottom layer image of the template image pyramid is determined in the bottom layer image of the search image pyramid as the target matching region of the template image on the search image.
[0029] Optionally, the process of determining the feature pixel block corresponding to the sampling point comprises:
[0030] Determining the pixel block of the square composed of the sampling pixel point and the surrounding eight pixel points.
[0031] If the number of the pixel points on at least one side of the pixel block, whose pixel difference absolute value is higher than the preset segmentation threshold, reaches the preset number, the pixel block is determined as the feature pixel block.
[0032] Another aspect of the embodiment of the present application further provides an electronic device comprising a processor and a memory.
[0033] The memory is configured to store a program;
[0034] The processor executes the program to implement the method.
[0035] Another aspect of the embodiment of the present application also provides a computer readable storage medium, the storage medium stores a program, and the program is executed by a processor to implement the method.
[0036] The embodiment of the present application also discloses a computer program product or a computer program, which comprises computer instructions stored in a computer readable storage medium. A processor of a computer device can read the computer instructions from the computer readable storage medium, and the processor executes the computer instructions, so that the computer device executes the foregoing method.
[0037] The present application first acquires a template image and an image pyramid thereof after grayscale processing, and acquires a search image and an image pyramid thereof after grayscale processing, the image pyramids of the two images have the same number of image layers; in a first top layer image of the template image pyramid and a second top layer image of the search image pyramid, a plurality of sampling pixel points and a feature pixel block corresponding to each sampling pixel point are determined according to a set sampling interval, respectively, the feature pixel block is divided, and then comparison is performed based on the feature pixel block, without the need to compare the whole image, so that the amount of calculation is greatly reduced, the matching region of the template image in the search image is accurately and quickly determined; the feature pixel block of the first top layer image is compared with the feature pixel block of the second top layer image, to obtain a top layer matching region in the second top layer image, which has the highest similarity with the first top layer image; according to the top layer matching region, layer-by-layer comparison is performed on each layer image of the search image pyramid except the top layer image, and according to the feature pixel block, layer-by-layer downward search comparison is performed, which can resist the influence of light noise to a certain extent, until a bottom layer matching region in a bottom layer image of the search image pyramid is determined, which has the highest similarity with the bottom layer image of the template image pyramid, as a target matching region of the template image on the search image. BRIEF DESCRIPTION OF DRAWINGS
[0038] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the following will briefly introduce the drawings needed to be used in the embodiment description. Obviously, the drawings in the following description are only some embodiments of the present application, and other drawings can also be obtained by those skilled in the art without any creative effort on the basis of these drawings.
[0039] Figure 1 A flowchart of a matching method of a template image provided by the embodiment of the present application is shown in the figure.
[0040] Figure 2A structural block diagram of a template image matching device provided by an embodiment of the present application. DETAILED DESCRIPTION
[0041] In order to make the objectives, technical solutions and advantages of the present application clearer, the present application will be further described in detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and should not be used to limit the present application.
[0042] Referring to Figure 1 The embodiment of the present application provides a template image matching method, and specifically includes the following steps.
[0043] Step S100: acquiring a gray scale of a template image, a template image pyramid generated based on the gray scale of the template image, a gray scale of a search image and a search image pyramid generated based on the gray scale of the search image.
[0044] Specifically, the template image after gray scale processing can be acquired, and then the image pyramid is constructed based on the template image. Similarly, the search image after gray scale processing can be acquired, and then the image pyramid is constructed based on the search image. The image layers of the template image pyramid and the search image pyramid can be the same.
[0045] Step S110: in the first top layer image of the template image pyramid and the second top layer image of the search image pyramid, a plurality of sampling pixel points and a feature pixel block corresponding to each sampling pixel point are determined according to a set sampling interval.
[0046] Specifically, the top layer image of the template image pyramid can be taken as the first top layer image, and the top layer image of the search image pyramid can be taken as the second top layer image. Then, a plurality of sampling pixel points are determined on the first top layer image and the second top layer image according to a set sampling interval.
[0047] Then, the feature pixel block of each sampling point is determined according to a set feature block forming condition.
[0048] Further, the two images corresponding to each layer of the template image pyramid and the search image pyramid can also determine the sampling points and the feature pixel blocks according to a set sampling interval, and then the subsequent comparison is performed.
[0049] It should be noted that the sampling interval can be set by the user according to the actual situation. In an optional embodiment, the feature pixel block condition of the search image can be determined in advance before the matching process, and it is determined whether each pixel point of the search image can form a feature pixel block. In this case, the sampling interval of the search image can be 1, that is, each pixel point of the search image can be used as a sampling pixel point, and then it is determined whether each sampling pixel point can form a feature pixel block. The sampling interval of the template image can be determined according to the specific situation. If the feature pixel block conditions of the search region of the search image and the template image need to be determined in the matching process, the sampling intervals of the two can be consistent, so that the feature pixel blocks of the search region of the search image and the template image can correspond to each other.
[0050] Step S120: Comparing the feature pixel blocks of the first top layer image with the feature pixel blocks of the second top layer image to obtain a top layer matching region in the second top layer image that has the highest similarity with the first top layer image.
[0051] Specifically, the first top layer image and the second top layer image can be compared from top to bottom and from left to right in terms of the feature pixel blocks, and then the region in the second top layer image that has the highest similarity with the first top layer image can be determined as the top layer matching region.
[0052] Step S130: Comparing the top layer matching region in each layer image of the search image pyramid except the top layer image layer by layer until a bottom layer matching region in the bottom layer image of the search image pyramid that has the highest similarity with the bottom layer image of the template image pyramid is determined as the target matching region of the template image on the search image.
[0053] Specifically, the comparison process of each layer image of the image pyramid can refer to the comparison process of the top layer image, and for each layer search image, the comparison region with the template image can be determined according to the matching region of the previous layer.
[0054] After the layer-by-layer comparison, the matching region in the bottom layer image of the search image pyramid that has the highest similarity with the bottom layer image of the template image pyramid can be determined, and the matching region on the bottom layer image can be used as the target matching region of the template image on the search image.
[0055] In some embodiments of the present application, the process of determining a plurality of sampling pixel points and the feature pixel block corresponding to each sampling pixel point according to the set sampling interval is introduced in the above step S110, and the process of determining each feature pixel block will be described in detail.
[0056] Specifically, the following steps can be included:
[0057] S1, determining a pixel block of a square formed by the sampling pixel point and eight pixel points around the sampling pixel point.
[0058] Specifically, since each pixel point is a square, the sampling pixel point and eight pixel points around the sampling pixel point can form a large square pixel block.
[0059] S2, if there are three pixel points on at least one side of the pixel block, and the number of pixel points with an absolute value of pixel difference between the three pixel points and a target pixel point higher than a preset segmentation threshold reaches a preset number, the pixel block is determined as a feature pixel block.
[0060] Specifically, the size of the segmentation threshold can determine the number of generated feature blocks. The larger the segmentation threshold, the fewer the generated feature blocks. The smaller the segmentation threshold, the more the generated feature blocks.
[0061] After the template image and the search image are applied, the size of the segmentation threshold can determine the number of feature blocks generated by the two images.
[0062] Since the number of pixels in the top layer images of the two image pyramids is small and the pixel value difference is small, in order to ensure that a sufficient number of feature blocks are generated to improve the accuracy of matching, the segmentation threshold of the top layer images can be set to be small. In the images closer to the bottom layer, the number of pixels is larger and the pixel value difference is larger. Different segmentation thresholds can be set for each layer of images to generate a reasonable number of feature blocks.
[0063] After the segmentation threshold is determined, a plurality of pixel blocks can be obtained on the template image and the search image. For each pixel block, when at least one side of the pixel block meets the set feature condition, the pixel block can be determined as a feature pixel block.
[0064] The above set feature condition can include that there are three pixel points on one side of the pixel block, and the number of pixel points with an absolute value of pixel difference between the three pixel points and a target pixel point higher than a preset segmentation threshold reaches a preset number.
[0065] It should be noted that the target pixel point can be located outside the pixel block, and the target pixel point is adjacent to the pixel block. In addition, the three target pixel points corresponding to the three pixel points on one side can be on the same straight line.
[0066] In addition, the size of the feature pixel block can not be limited to a square region with three pixel points as one side, but can also be a square region with other number of pixel points as one side, for example, a square region with five pixel points or seven pixel points as one side, and a square region with other number of pixel points as one side.
[0067] In order to more specifically describe the process of determining the feature pixel block, a specific example is introduced as follows.
[0068] Specifically, assuming that the segmentation threshold corresponding to the top image is 5 and the preset number is 2. If there are at least one edge on the four edges of a certain pixel block, and the number of absolute values of pixel differences between three pixel points on the edge and the corresponding target pixel points respectively exceeds 5, reaches 2 or more (i.e. 3), then the pixel block can be determined as a feature pixel block.
[0069] In some embodiments of the present application, the process of comparing the feature pixel blocks of the first top image with the feature pixel blocks of the second top image is introduced in the above step S120. Next, the process of comparing the feature pixel blocks will be further described.
[0070] Specifically, the following steps can be included:
[0071] S1, determining a plurality of first search regions with the same range size as the first top image in the second top image.
[0072] Specifically, the search image is generally larger than the template image, so the search image can be divided into a plurality of first search regions, and the range size of each first search region can be the same as that of the first top image.
[0073] S2, for each first search region, comparing each feature pixel block of the first top image with the feature pixel block at the corresponding position of the first search region.
[0074] Specifically, since the range size of the first search region can be the same as that of the first top image, the feature pixel blocks at the same position can be compared in meaning, and then the comparison results of all feature pixel blocks are summarized to obtain the similarity between the first top image and each first search region.
[0075] If there are some positions on the first top image or a certain first search region that do not generate feature pixel blocks, then the positions can not be compared, and the comparison can be performed when feature pixel blocks are generated at the same positions of the first top image and the first search region.
[0076] Next, the process of calculating the similarity between the feature pixel blocks is described.
[0077] Specifically, the calculation formula of the similarity between the feature pixel block of the template image and the feature pixel block at the corresponding position of the search image can be expressed as follows:
[0078]
[0079] Wherein, L represents the similarity of the feature pixel block of the template image and the feature pixel block of the corresponding position of the search image, t represents the pixel value of the sampling pixel point in the feature pixel block on the template image, t1 represents the pixel value of the pixel point except the sampling pixel point in the feature pixel block on the template image, s represents the pixel value of the sampling pixel point in the feature pixel block on the search image, and s1 represents the pixel value of the pixel point except the sampling pixel point in the feature pixel block on the search image.
[0080] Since there are eight pixel points around the sampling pixel point, the feature pixel block on the template image can be compared with the feature pixel block on the search image eight times, and the pixel points at the same position are compared each time, if one of the two cases in the above formula is met, the similarity is added by 1, if all the eight pixel points meet one of the two cases in the above formula, the similarity is added by 8.
[0081] Further, after the comparison of the top layer image is completed, the top layer matching area can be obtained, and the process of layer-by-layer comparison based on the top layer matching area can include the following steps:
[0082] S1, determining the reference coordinates of the preset reference point in the matching area of the search image of the last layer.
[0083] Specifically, the preset reference point in the matching area of the last layer can be any point in the matching area, for example, the pixel point at the top left corner of the matching area, the center pixel point of the matching area, and other optional reference points. In an optional embodiment, the pixel point at the top left corner of the matching area is taken as the reference point.
[0084] S2, determining the second search area of the search image of the current layer according to the reference coordinates.
[0085] Specifically, the matching area of the last layer is the area with the highest similarity to the template image in the image of the last layer, so the search area of the current layer can be determined according to the reference point coordinates of the matching area of the last layer. Further, the area in the current layer image within a set range centered on the reference point can be taken as the second search area.
[0086] The embodiment of the application can magnify the reference point coordinates by two times, and take the magnified coordinates as the center to take the area within a set range as the second search area, wherein the set range is, for example, a square area with each side composed of 5 pixel points centered on the magnified coordinates, the range size of the area can be recorded as 5*5, and the range size of the second search area can also be 7*7, 8*8, and the like.
[0087] S3, comparing the feature pixel block on the template image corresponding to the search image of the current layer with the feature pixel block on the second search area.
[0088] Specifically, the comparison process of the feature pixel block can refer to the comparison process of the feature pixel block of the top image, which will not be repeated here.
[0089] The present application divides the images of different layers into different feature pixel blocks with different segmentation thresholds, compares the feature pixel blocks, and can obtain the similarity between the feature pixel blocks. Compared with the existing comparison of all pixel points, the speed of the comparison process can be obviously improved, and efficient matching is realized.
[0090] Next, the template matching process of the present application will be described with specific examples.
[0091] Step 1: Load the template image and the search image, and convert the template image and the search image into grayscale images.
[0092] Step 2: Set the number of image pyramid layers, and use the image pyramid technology for the template image and the search image. In this embodiment, the number of pyramid layers is set to 4.
[0093] Step 3: Set a reasonable segmentation threshold. The segmentation threshold determines the difficulty of generating feature blocks of the template image and the search image. If the set threshold is low, the generated feature blocks are more, which affects the matching speed. If the set threshold is high, the number of generated feature blocks is small, which affects the accuracy of matching. Because on the image pyramid, the image close to the top layer of the pyramid and including the top layer of the pyramid has fewer pixels and smaller pixel size difference than the original image, and the image close to the bottom layer of the pyramid and including the bottom layer of the pyramid has more pixels and larger pixel size difference, that is, the closer to the bottom layer of the image, the closer to the original image, and the bottom layer of the image is completely consistent with the original image, therefore the segmentation threshold should be set higher and higher from the top layer to the bottom layer. At the same time, the reasonable generation condition of the feature block should be set, that is, the absolute value of the difference between the pixel value on the edge and the outer edge pixel value should exceed the segmentation threshold, and the number of generated feature blocks should be reasonable. If the set number is small, the generated feature blocks are more, which affects the matching speed. If the set number is large, the number of generated feature blocks is small, which affects the accuracy of matching. In this embodiment, the number is set to 2. In this embodiment, the segmentation thresholds from the bottom layer of the image to the top layer of the image are set to 25, 15, 10 and 5 respectively.
[0094] Step 4: Start searching and matching, and compare the template image and the search image from top to bottom and from left to right. For the 3*3 feature block in this embodiment, the specific similarity calculation method is as follows:
[0095] 1) Interval sampling, and the sampling interval is set to 4;
[0096] 2) The square with the sampling pixel point as the center, and the specific size is 3*3;
[0097] The three pixels on each side of a 3x3 square pixel block centered on the sampled pixel are compared with the pixels outside the square. Specifically, this can include: if the absolute value of the pixel difference between the three pixels on at least one of the four sides and the three pixels on the outer side exceeds a preset number of the segmentation thresholds for that layer, then nine pixels of size 3x3 centered on the sampled pixel are considered as a feature pixel block. In this embodiment, the preset number is 2. If the sampled pixel can form a feature block on both the template image and the search image, then the next step of similarity measurement is performed; otherwise, the process moves to the next sampling point to calculate the similarity.
[0098] 3) If the sampling points can form pixel blocks on both the search image and the template image, then the similarity measurement formula is as follows:
[0099]
[0100] Where L represents the similarity between two feature pixel blocks. In this embodiment, 3*3 sampling is used. If the feature block in the template image is exactly the same as the corresponding feature pixel block in the search image, the similarity of the feature pixel block is 8; if they are completely unrelated, the similarity is 0. t1 and s1 represent the pixels surrounding the sampling point in the search area of the template image and the search image, respectively. In this embodiment, t1 and s1 represent the eight pixels excluding the sampling pixel point.
[0101] 4) Finally, the similarity of all feature pixel blocks can be summed to obtain the final similarity between the search regions of the template image and the search image. The specific formula is as follows:
[0102] n=∑L
[0103] n represents the final similarity score of the region.
[0104] Step 5: Find the coordinates of the top left corner of the region with the highest similarity in the top layer image and pass it to the next layer image.
[0105] Step 6: Derive the new coordinates from the calculation results of the previous image. The specific formula is as follows:
[0106] (X new ,Y new )=(2*X old ,2*Y old )
[0107] Where X old With Y old X represents the x and y coordinates of the reference point for the matching region in the previous image layer. new With Y newThe horizontal and vertical coordinates representing the image search area of the next layer, search and match in the range of 5*5 centered on the new coordinates, the specific calculation method is the method step of Step 4, extract the feature pixel block of the image, and calculate the similarity on the corresponding feature pixel block.
[0108] Step 7: Calculate the reference point coordinates of the matching area with the maximum similarity of the bottom layer image, and mark the matching area as the target matching area, and the template matching is completed.
[0109] Reference Figure 2 The embodiment of the application provides a template image matching device, which comprises:
[0110] An image acquisition unit is configured to acquire the gray scale of a template image, a template image pyramid generated based on the gray scale of the template image, the gray scale of a search image, and a search image pyramid generated based on the gray scale of the search image, wherein the template image pyramid and the search image pyramid have the same number of image layers;
[0111] A pixel block determination unit is configured to determine a plurality of sampling pixels and a feature pixel block corresponding to each sampling pixel in a first top layer image of the template image pyramid and a second top layer image of the search image pyramid according to a set sampling interval, respectively.
[0112] A pixel block comparison unit is configured to compare the feature pixel block of the first top layer image with the feature pixel block of the second top layer image to obtain a top layer matching area with the highest similarity to the first top layer image in the second top layer image.
[0113] A target area matching unit is configured to compare each layer image of the search image pyramid except the top layer image according to the top layer matching area, until a bottom layer matching area with the highest similarity to the bottom layer image of the template image pyramid is determined in the bottom layer image of the search image pyramid, as a target matching area of the template image on the search image.
[0114] The embodiment of the application further discloses a computer program product or a computer program, which comprises computer instructions stored in a computer readable storage medium. A processor of a computer device can read the computer instructions from the computer readable storage medium, and the processor executes the computer instructions, so that the computer device executes the method shown in the embodiment of the application. Figure 1
[0115] In some alternative embodiments, the function / operations mentioned in the block diagrams can not occur in the order mentioned in the operational illustrations. For example, depending on the involved function / operation, two blocks shown in succession can in fact be executed substantially concurrently or the blocks can sometimes be executed in reverse order, depending upon the functionality / operations involved. Furthermore, embodiments presented and described in the flowcharts are only examples of implementing the present application. Alternative embodiments are possible where functions described as portions of independent operations are implemented as a combined operation or functions described as a combined operation are implemented as separate operations. The flowcharts can also represent code segments when executed that provide the processes described and / or illustrated therein. Alternatively, the flowcharts can also represent program steps in a procedural, object-oriented, or other programming language object- oriented programming language.
[0116] Furthermore, although the present application is described in the context of functional modules, it is understood that one or more of the functions and / or features described can be integrated in a single physical device and / or software module, or one or more functions and / or features can be implemented in separate physical devices or software modules. It is also understood that detailed discussion of the actual implementation of each module is unnecessary to an understanding of the present application. Rather, the actual implementation is within the routine skill of engineers familiar with the attributes, functions, and internal relationships of the various functional modules disclosed herein. Accordingly, the present application is not limited to the implementations illustrated herein but is intended to be limited only by the claims attached hereto and by their equivalents. It is understood that the specific order or hierarchy of functions and / or features described is an example and this order or hierarchy can be different, for example, where hardware or software is concerned. It is also understood that the multiple implementations or configurations described herein are illustrative and not limiting, and that many other implementations or configurations can be made by persons of ordinary skill in the art with the benefit of this disclosure, such implementations or configurations being encompassed by the scope of the application.
[0117] The functions described can be implemented in software, firmware, hardware, or any combination thereof. If implemented in software, the functions can be stored or transmitted over as one or more instructions or code on a computer-readable medium. Computer-readable media include both computer storage media and communication media including any medium that facilitates transfer of a computer program from one place to another. A storage medium can be any available medium that can be accessed by a general purpose or special purpose computer. By way of example, and not limitation, such computer-readable media can comprise RAM, ROM, EEPROM, CD-ROM or other optical disk storage, magnetic disk storage or other magnetic storage devices, or any other medium that can be used to carry or store desired program code means in the form of instructions or data structures and that can be accessed by a general-purpose or special-purpose computer, or a general-purpose or special-purpose processor. Also, any connection is properly termed a computer-readable medium. For example, if the software is transmitted from a website, server, or other remote source using a coaxial cable, fiber optic cable, twisted pair, digital subscriber line (DSL), or other
[0118] The logic and / or steps represented in the flowcharts and / or described herein, for example, can be embodied in non-transitory computer-readable media, executed by one or more computing devices, and / or in any other way. The logic and / or steps represented in the flowcharts and / or described herein, for example, can be considered a list of executable instructions for implementing logic functions, and can be embodied in any computer-readable medium for use by or in connection with an instruction execution system, apparatus, or device, such as a computer-based system, processor- containing system, or other system that can fetch the instructions from the instruction execution system, apparatus, or device and execute the instructions. For purposes of this specification, a "computer-readable medium" can be any apparatus that can contain, store, communicate, propagate, or transport the program for use by or in connection with the instruction execution system, apparatus, or device. The computer-readable medium can be, for example but not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device. More specific examples (a non-exhaustive list) of the computer-readable medium include the following: an electrical connection (electronic) having one or more wires, a portable computer diskette (magnetic), a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or Flash memory), an optical fiber (optical), and a portable compact disc read-only memory (CDROM). Additionally, the computer-readable medium can even be paper or another suitable medium upon which the program is printed, as the program can be electronically captured, for example via an optical scanner, then compiled, interpreted, or otherwise processed, and stored in a computer memory in a form that can be later executed by a computer. In this context, a "computer-readable medium" can be any means that can store the program for use by or in connection with the instruction execution system, apparatus, or device.
[0119] The foregoing description of various embodiments of the application has been presented for the purposes of illustration and description. It is not intended to be exhaustive or to limit the application to the precise form disclosed, and various modifications and variations are possible in light of the above teachings. It is intended that the scope of the application be limited not with this detailed description, but rather by the claims appended hereto.
[0120] It will be appreciated that portions of the present application can be implemented in hardware, software, firmware, or a combination thereof. In the above embodiments, multiple steps or methods can be implemented in software or firmware stored in a memory and executed by a suitable instruction execution system. For example, if implemented in hardware, and in another embodiment, any of the following technologies known in the art, or a combination thereof, can be used: discrete logic circuitry having logic gates for implementing logic functions upon an application of data signals, application specific integrated circuits having appropriate combinational logic gates, programmable gate arrays (PGA), field programmable gate arrays (FPGA), and the like.
[0121] In the description of the present specification, the description of the terms "one embodiment", "some embodiments", "an example", "a specific example", or "some examples" and the like means that the specific features, structures, materials or characteristics described in connection with the embodiment or example are included in at least one embodiment or example of the present application. In the present specification, illustrative expressions of the above terms do not necessarily refer to the same embodiment or example. Also, the specific features, structures, materials or characteristics described can be combined in any appropriate manner in one or more embodiments or examples.
[0122] While the embodiments of the application have been shown and described, it is to be understood that the embodiments described are merely exemplary and are not to be construed as limiting the scope of the application. The scope of the application is defined by the appended claims and their equivalents.
[0123] The above is a specific description of the preferred embodiment of the present application, but the present application is not limited to the described embodiment, and those skilled in the art can make various equivalent modifications or replacements without departing from the spirit of the present application, and these equivalent modifications or replacements are all included in the scope defined by the claims of the present application.
Claims
1. A method for matching template images, characterized in that, include: The grayscale of a template image, a template image pyramid generated using the grayscale of the template image, the grayscale of a search image, and a search image pyramid generated using the grayscale of the search image are obtained, wherein the template image pyramid and the search image pyramid have the same number of image layers; In the first top-level image of the template image pyramid and the second top-level image of the search image pyramid, multiple sampling pixels and feature pixel blocks corresponding to each sampling pixel are determined according to a set sampling interval. The feature pixel blocks of the first top-level image are compared with the feature pixel blocks of the second top-level image to obtain the top-level matching region in the second top-level image that has the highest similarity to the first top-level image. Based on the top-level matching region, each layer of the search image pyramid except the top-level image is compared layer by layer until the bottom-level image of the search image pyramid is determined to have the highest similarity to the bottom-level image of the template image pyramid, which is then used as the target matching region of the template image on the search image. The process of determining the feature pixel block corresponding to the sampling point includes: Determine the square pixel block formed by the sampled pixel and its eight surrounding pixels; If at least one of the four sides of the pixel block has three pixels, and the number of pixels whose absolute difference with the target pixel is higher than a preset segmentation threshold reaches a preset number, then the pixel block is determined as a feature pixel block; different segmentation thresholds are set for each image layer to generate different numbers of feature pixel blocks. Wherein, the target pixel is located outside the pixel block, and the target pixel is adjacent to the pixel block; The formula for calculating the similarity between the feature pixel blocks of the template image and the feature pixel blocks at corresponding positions in the search image is as follows: in, This represents the similarity between the feature pixel blocks of the template image and the feature pixel blocks at corresponding positions in the search image. This represents the pixel value of the sampled pixel point in the feature pixel block on the template image. This represents the pixel value of the pixels in the feature pixel block on the template image, excluding the sampled pixels. This represents the pixel value of the sampled pixel point in the feature pixel block on the search image. This represents the pixel value of the pixel points other than the sampled pixel points in the feature pixel block on the search image.
2. The template image matching method according to claim 1, characterized in that, The step of comparing the feature pixel blocks of the first top-level image with the feature pixel blocks of the second top-level image includes: In the second top-level image, determine a plurality of first search regions with the same size as the range of the first top-level image; For each of the first search regions, each feature pixel block of the first top-level image is compared with the feature pixel block at the corresponding position in the first search region.
3. The template image matching method according to claim 1, characterized in that, The process of comparing images in each layer of the search image pyramid, excluding the top layer image, includes: Determine the reference coordinates of the preset reference point in the matching region of the search image in the previous layer; The second search area of the search image in this layer is determined based on the reference coordinates; The feature pixel blocks on the template image corresponding to the search image in this layer are compared with the feature pixel blocks on the second search area.
4. A template image matching device, characterized in that, include: An image acquisition unit is used to acquire the grayscale of a template image, a template image pyramid generated using the grayscale of the template image, the grayscale of a search image, and a search image pyramid generated using the grayscale of the search image, wherein the template image pyramid and the search image pyramid have the same number of image layers. The pixel block determination unit is used to determine multiple sampling pixels and feature pixel blocks corresponding to each sampling pixel in the first top-level image of the template image pyramid and the second top-level image of the search image pyramid according to a set sampling interval. The pixel block comparison unit is used to compare the feature pixel blocks of the first top layer image with the feature pixel blocks of the second top layer image to obtain the top layer matching region in the second top layer image that has the highest similarity to the first top layer image. The target region matching unit is used to compare the top-level matching region layer by layer in the search image pyramid except for the top-level image, until the bottom-level matching region with the highest similarity to the bottom-level image of the template image pyramid is determined in the bottom-level image of the search image pyramid, and is used as the target matching region of the template image in the search image. The process of determining the feature pixel block corresponding to the sampling point includes: Determine the square pixel block formed by the sampled pixel and its eight surrounding pixels; If at least one of the four sides of the pixel block contains three pixels whose absolute pixel difference with the adjacent pixels outside the pixel block exceeds a preset segmentation threshold, then the pixel block is identified as a feature pixel block. Different segmentation thresholds are set for each image layer to generate different numbers of feature pixel blocks. The formula for calculating the similarity between the feature pixel blocks of the template image and the feature pixel blocks at corresponding positions in the search image is as follows: in, This represents the similarity between the feature pixel blocks of the template image and the feature pixel blocks at corresponding positions in the search image. This represents the pixel value of the sampled pixel point in the feature pixel block on the template image. This represents the pixel value of the pixels in the feature pixel block on the template image, excluding the sampled pixels. This represents the pixel value of the sampled pixel point in the feature pixel block on the search image. This represents the pixel value of the pixel points other than the sampled pixel points in the feature pixel block on the search image.
5. An electronic device, characterized in that, Including the processor and memory; The memory is used to store programs; The processor executes the program to implement the method as described in any one of claims 1 to 3.
6. A computer-readable storage medium, characterized in that, The storage medium stores a program that is executed by a processor to implement the method as described in any one of claims 1 to 3.
7. A computer program product, comprising a computer program, characterized in that, When the computer program is executed by a processor, it implements the method as described in any one of claims 1 to 3.
Citation Information
Patent Citations
Template matching method, system and device based on normalized cross-correlation and medium
CN113205145A