Shape matching method, device, computer equipment and storage device
By downsampling and gradient information processing on the template image and the region image to be matched, the edge probability position and the probability matching position are calculated, which solves the problem of slow shape matching speed in the existing technology and achieves a faster matching process.
Patent Information
- Application Number
- CN202111308810.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-11-05
- Publication Date
- 2024-08-30
- Estimated Expiration
- 2041-11-05
AI Technical Summary
Existing shape matching methods have the problem of slow matching speed in practical applications. This is mainly due to the large patch size of the template image and the region image to be matched, which causes the image pyramid matching process to take a long time.
By downsampling the template image and the image of the area to be matched N-1 times, an image pyramid containing N layers is generated, and the gradient information and preset contrast are used to calculate the edge probability position and probability matching position to reduce the calculation amount of matching search. Improve matching speed.
By determining the edge probability position and probability matching position, the traversal search calculation amount during image pyramid matching is reduced, and the matching speed is significantly accelerated.
Smart Images

Figure CN114219951B
Abstract
Description
Technical Field
[0001] The present application relates to the field of machine vision technology, and in particular to a shape matching method, a shape matching device, a computer device and a storage device. Background Art
[0002] Machine vision is to use machines to replace human eyes to make measurements and judgments. The matching method commonly used in machine vision is template matching. Template matching can be divided into grayscale matching and shape matching. When performing shape matching, you need to first create a template image of the target object to be identified, and then place the template image in the image of the area to be matched for traversal search to compare the template image with the image of the area to be matched.
[0003] Since the slice sizes of the template image and the image in the area to be matched are relatively large, when actually performing shape matching, image pyramids are first extracted for the template image and the image in the area to be matched, and matching is performed at the top layer of the image pyramid of the image in the area to be matched to find the matching position of the top layer of the image pyramid of the image in the area to be matched, and then the matching positions of the upper layer of the image pyramid of the image in the area to be matched are mapped to the next layer of the image pyramid of the image in the area to be matched layer by layer to obtain the candidate area of the next layer of the image pyramid of the image in the area to be matched, and matching is performed in the candidate area of the next layer of the image pyramid of the image in the area to be matched with the same layer in the image pyramid of the template image to obtain the matching position of the next layer of the image pyramid of the image in the area to be matched, until the first layer of the image.
[0004] The existing shape matching has the problem of slow matching speed. Summary of the invention
[0005] In view of this, in order to solve the above technical problems, the present application provides a shape matching method, device, computer equipment and storage device.
[0006] To achieve the above object, the present application provides a shape matching method, which includes:
[0007] Downsampling the template image N-1 times to obtain a first image pyramid including N layers of images, and downsampling the image in the area to be matched N-1 times to obtain a second image pyramid including N layers of images, wherein the first layer image of the first image pyramid is the template image, the first layer image of the second image pyramid is the image in the area to be matched, and N is an integer greater than or equal to 2;
[0008] Obtaining the x-direction gradient and the y-direction gradient of all pixel points in the Nth layer image of the second image pyramid, as well as a preset contrast;
[0009] Calculate the gradient amplitude of each pixel point in the Nth layer image of the second image pyramid according to the x-direction gradient and the y-direction gradient of all pixel points in the Nth layer image of the second image pyramid;
[0010] Determine, according to a preset contrast and a gradient amplitude of each pixel point in the Nth layer image of the second image pyramid, a mask image for describing all probability positions of edge points in the Nth layer image of the second image pyramid as an edge probability position mask image of the Nth layer image of the second image pyramid;
[0011] Determine, according to the number and distribution range information of edge points of the Nth layer image of the first image pyramid and the edge probability position mask image of the Nth layer image of the second image pyramid, a mask image used to describe all probability matching positions in the Nth layer image of the second image pyramid as the probability matching position mask image of the Nth layer image of the second image pyramid;
[0012] Taking the area where all probability matching positions described by the probability matching position mask image of the Nth layer image of the second image pyramid are located as the target matching area of the Nth layer image of the second image pyramid, calculating the correlation score of the Nth layer image of the first image pyramid in the target matching area of the Nth layer image of the second image pyramid as the Nth layer image matching score, and taking the pixel point corresponding to the correlation score greater than the preset score threshold in the Nth layer image matching score as the Nth layer image matching result;
[0013] Obtain a target matching region of the i-1 layer image of the second image pyramid according to the matching result mapping of the i-1 layer image, calculate a correlation score of the i-1 layer image of the first image pyramid in the target matching region of the i-1 layer image of the second image pyramid as the i-1 layer image matching score, and take a pixel point corresponding to a correlation score greater than a preset score threshold in the i-1 layer image matching score as the i-1 layer image matching result; wherein 3≤i≤N and i is an integer;
[0014] According to the matching result mapping of the second layer image, the target matching area of the image in the area to be matched is obtained, and the correlation score of the template image in the target matching area of the image in the area to be matched is calculated as the matching score of the first layer image. The pixel point corresponding to the maximum correlation score in the matching score of the first layer image is output as the matching result between the image in the area to be matched and the template image.
[0015] In order to solve the above technical problems, another technical solution adopted by the present application is to provide a shape matching device, which includes an image pyramid generation module, a mask image generation module and a matching module, wherein:
[0016] An image pyramid generation module is used to perform N-1 down-sampling on the template image to obtain a first image pyramid including N layers of images, and perform N-1 down-sampling on the image of the area to be matched to obtain a second image pyramid including N layers of images, wherein the first layer image of the first image pyramid is the template image, the first layer image of the second image pyramid is the image of the area to be matched, and N is an integer greater than or equal to 2;
[0017] A mask image generation module, used to obtain the x-direction gradient and the y-direction gradient of all pixel points in the Nth layer image of the second image pyramid, and a preset contrast;
[0018] The mask image generation module is further used to calculate the gradient amplitude of each pixel point in the Nth layer image of the second image pyramid according to the x-direction gradient and the y-direction gradient of all pixel points in the Nth layer image of the second image pyramid;
[0019] The mask image generating module is further used to determine, according to a preset contrast and a gradient amplitude of each pixel point in the Nth layer image of the second image pyramid, a mask image for describing all probability positions of edge points in the Nth layer image of the second image pyramid as an edge probability position mask image of the Nth layer image of the second image pyramid;
[0020] The mask image generation module is further used to determine, based on the number and distribution range information of edge points of the Nth layer image of the first image pyramid and the edge probability position mask image of the Nth layer image of the second image pyramid, a mask image used to describe all probability matching positions in the Nth layer image of the second image pyramid as the probability matching position mask image of the Nth layer image of the second image pyramid;
[0021] a matching module, configured to use the area where all probability matching positions described by the probability matching position mask image of the Nth layer image of the second image pyramid are located as the target matching area of the Nth layer image of the second image pyramid, calculate the correlation score of the Nth layer image of the first image pyramid in the target matching area of the Nth layer image of the second image pyramid as the Nth layer image matching score, and use the pixel points corresponding to the correlation scores greater than a preset score threshold in the Nth layer image matching score as the Nth layer image matching result;
[0022] The matching module is further used to obtain the target matching area of the i-1 layer image of the second image pyramid according to the matching result mapping of the i-1 layer image, calculate the correlation score of the i-1 layer image of the first image pyramid in the target matching area of the i-1 layer image of the second image pyramid as the i-1 layer image matching score, and use the pixel points corresponding to the correlation scores of the i-1 layer image matching scores that are greater than a preset score threshold as the i-1 layer image matching results; wherein 3≤i≤N and i is an integer;
[0023] The matching module is also used to obtain the target matching area of the image to be matched according to the matching result mapping of the second layer image, calculate the correlation score of the template image in the target matching area of the image to be matched as the first layer image matching score, and output the pixel point corresponding to the maximum correlation score in the first layer image matching score as the matching result between the image to be matched and the template image.
[0024] In order to solve the above technical problems, another technical solution adopted by the present application is to provide a computer device, which includes a memory and a processor, wherein the memory stores program data; the program data can be executed by the processor to implement any one of the above methods.
[0025] In order to solve the above technical problems, another technical solution adopted by the present application is to provide a storage device, which stores program data, and the program data can be executed by a processor to implement any one of the above methods.
[0026] Beneficial effect: Different from the prior art, when matching the Nth layer image, the present application determines the edge probability position mask image of the Nth layer image of the second image pyramid, and determines the probability matching position mask image of the Nth layer image of the second image pyramid according to the number and distribution range information of the edge points of the Nth layer image of the first image pyramid and the edge probability position mask image of the Nth layer image of the second image pyramid; uses the area where all probability matching positions described by the probability matching position mask image of the Nth layer image of the second image pyramid are located as the target matching area of the Nth layer image of the second image pyramid, and then completes subsequent matching operations according to the target matching area. Compared with traversing and searching the entire Nth layer image of the second image pyramid, the present application reduces the amount of calculation, thereby speeding up the matching speed. BRIEF DESCRIPTION OF THE DRAWINGS
[0027] Figure 1 is a schematic diagram of the front section of the process of the shape matching method embodiment of the present application;
[0028] Figure 2 is a schematic diagram of the latter stage of the process of the shape matching method embodiment of the present application;
[0029] Figure 3 is a schematic diagram of a template image and an image of a region to be matched in an embodiment of a shape matching method of the present application;
[0030] Figure 4 is a schematic diagram of a first image pyramid and a second image pyramid in an embodiment of a shape matching method of the present application;
[0031] Figure 5is a schematic diagram of an Nth layer image of a first image pyramid and an Nth layer image of a second image pyramid in an embodiment of a shape matching method of the present application;
[0032] Figure 6 is a schematic diagram of an edge image of an N-th layer image of a first image pyramid and an edge probability position mask image of an N-th layer image of a second image pyramid in an embodiment of a shape matching method of the present application;
[0033] Figure 7 is a schematic diagram of the position of one of the square comparison areas in the edge probability position mask map of the Nth layer image of the second image pyramid in the shape matching method embodiment of the present application;
[0034] Figure 8 is a schematic diagram of the position of another square comparison area in the edge probability position mask image of the Nth layer image in the shape matching method embodiment of the present application;
[0035] Fig. 9 is a schematic diagram of the position of another square comparison area in the edge probability position mask image of the Nth layer image of the second image pyramid in the shape matching method embodiment of the present application;
[0036] Fig.10 is a schematic diagram of a probability matching position mask image of the Nth layer image of the second image pyramid obtained in step S152 of the shape matching method embodiment of the present application;
[0037] Fig.11 is a schematic diagram of a target matching area in an Nth layer image of a second image pyramid in an embodiment of a shape matching method of the present application;
[0038] Fig.12 is a structural schematic diagram of the shape matching device of the present application;
[0039] Fig.13 is a schematic diagram of the structure of a computer device embodiment of the present application;
[0040] Fig.14 It is a schematic diagram of the structure of a storage device embodiment of the present application. DETAILED DESCRIPTION
[0041] In order to enable those skilled in the art to better understand the technical solution of the present application, the present application is further described in detail below in conjunction with the accompanying drawings and specific implementation methods. Obviously, the described implementation methods are only part of the implementation methods of the present application, rather than all the implementation methods. Based on the implementation methods in the present application, all other implementation methods obtained by ordinary technicians in the field without making creative work are within the scope of protection of the present application.
[0042] See also Figure 1-Figure 2 , Figure 1 is a schematic diagram of the front section of the process of the shape matching method embodiment of the present application, Figure 2 is a schematic diagram of the latter stage of the process of the shape matching method embodiment of the present application, such as Figure 1-Figure 2 As shown, the shape matching method of the present application includes at least the following steps:
[0043] Step S110: down-sampling the template image N-1 times to obtain a first image pyramid including N layers of images, and down-sampling the image in the area to be matched N-1 times to obtain a second image pyramid including N layers of images.
[0044] by Figure 3-Figure 4 Take this as an example to illustrate: Figure 3 is a schematic diagram of a template image and an image of a region to be matched in an embodiment of a shape matching method of the present application; Figure 4 Schematic diagram of a first image pyramid and a second image pyramid of an embodiment of a shape matching method of the present application.
[0045] Figure 3 The image marked as 100 is the template image, and the image marked as 200 is the image of the area to be matched. Since the template image 100 and the image of the area to be matched 200 are large in size, in actual matching, the original image is first downsampled to obtain an image pyramid. When the original image is the template image 100, the image pyramid obtained is as follows: Figure 4 When the original image is the image 200 of the area to be matched, the image pyramid obtained is as follows: Figure 4 The first image pyramid A and the second image pyramid B may both have N layers of images, where N is an integer greater than or equal to 2. Figure 4 As shown, the first layer image A1 of the first image pyramid A is the template image 100, and the first layer image B1 of the second image pyramid B is the image 200 of the area to be matched. The N layers of images of the first image pyramid A are obtained by downsampling the template image 100 N-1 times, and the N layers of images of the second image pyramid B are obtained by downsampling the image 200 of the area to be matched N-1 times. The image pyramid can be a collection of original images and images reduced to 1 / 2, 1 / 4, 1 / 8... of the original size. For an image pyramid with N layers of images, the first layer image is also called the bottom layer image, and the Nth layer image is also called the top layer image. In the direction from the first layer image to the Nth layer image, the area of the image above the first layer image can be one quarter of the area of the next layer image. For example, in an application example, the areas of the first layer image to the Nth layer image can be respectively: Wherein, M is the width of the first layer image, and N is the height of the first layer image.
[0046] There are generally two sampling methods for down-sampling the original image, namely Gaussian sampling and Laplace sampling. Among them, the image pyramid formed by Gaussian sampling is a Gaussian pyramid, and the image pyramid formed by Laplace sampling is a Laplace pyramid. The difference between Gaussian sampling and Laplace sampling is that Gaussian sampling uses low-pass (Gaussian) filtering, while Laplace sampling uses band-pass (Laplace) filtering. Compared with band-pass filtering, low-pass filtering is simpler to implement, and the use of which filter has no obvious effect on the application effect of template matching. In this embodiment, Gaussian sampling is used as an example for explanation.
[0047] Specifically, during the downsampling of the original image, for a given j-th layer image G j The j+1th layer image G can be obtained by following steps S111 to S112 j+1 , where 1≤j≤N.
[0048] Step S111: Use the Gaussian kernel to process the j-th layer image G j Perform smoothing filtering (convolution), the Gaussian kernel is shown in the following formula (1):
[0049]
[0050] Step S112: Remove the j-th layer image G j All even rows and even columns of the j+1th layer image G j+1 .
[0051] In this step, the j-th layer image G j After removing the even rows and even columns of j+1 The length of the j-th layer image G before removal j The j+1th layer image G is obtained by half the length of j+1 The width is the j-th layer image G before removal j Half the width of . That is, the j+1th layer image G j+1 The area of the j-th layer image G j One quarter of the area.
[0052] Step S120: Obtaining the x-direction gradient and the y-direction gradient of all pixel points in the Nth layer image of the second image pyramid, and a preset contrast.
[0053] In this step, the x-direction gradient and the y-direction gradient of each pixel point in the Nth layer image of the second image pyramid may be calculated by using the Sobel operator.
[0054] The preset contrast may be a parameter pre-entered by the user. If the edge of the image in the area to be matched is clear, the preset contrast may be set higher. If the edge contrast of the image in the area to be matched is not large, that is, the edge of the image in the area to be matched is relatively blurred, the preset contrast may be set lower.
[0055] In one implementation, the preset contrast may be a minimum resolvable contrast (MRC). For the minimum resolvable contrast, reference may be made to the relevant description in the prior art.
[0056] Step S130: calculating the gradient magnitude of each pixel in the Nth layer image of the second image pyramid according to the x-direction gradient and the y-direction gradient of all the pixel points in the Nth layer image of the second image pyramid.
[0057] In this step, the gradient amplitude of the pixel points in the Nth layer image of the second image pyramid satisfies the following formula (2):
[0058]
[0059] Among them, |G f (μ N ,ν N )| is the coordinate of the Nth layer image of the second image pyramid (μ N ,ν N )’s pixel gradient amplitude, The coordinates of the Nth layer image of the second image pyramid are (μ N ,ν N )’s pixel point in the x direction, The coordinates of the Nth layer image of the second image pyramid are (μ N ,ν N )’s y-direction gradient.
[0060] Step S140: determining a mask image for describing all probability positions of edge points in the Nth layer image of the second image pyramid according to a preset contrast and the gradient amplitude of each pixel point in the Nth layer image of the second image pyramid as an edge probability position mask image of the Nth layer image of the second image pyramid.
[0061] In this step, the smaller the gradient amplitude corresponding to a pixel point, the smaller the possibility that the pixel point is an edge point and the greater the possibility that it is noise; the larger the gradient amplitude corresponding to a pixel point, the greater the possibility that the pixel point is an edge point and the smaller the possibility that it is noise. When the gradient amplitude of a pixel point is less than the preset contrast, the pixel point cannot be an edge point; when the gradient amplitude of a pixel point is greater than the preset contrast, the pixel point may be an edge point. In this step, the gradient amplitude of the pixel point in the Nth layer image of the second image pyramid can be compared with the preset contrast, and the pixel point corresponding to the gradient amplitude greater than the preset contrast in the Nth layer image of the second image pyramid is used as the probability position of the edge point. According to all the probability positions of the edge points in the Nth layer image of the second image pyramid, a mask image for describing all the probability positions of the edge points in the Nth layer image of the second image pyramid is generated as the edge probability position mask image of the Nth layer image of the second image pyramid.
[0062] by Figure 5-Figure 6 Take this as an example to illustrate: Figure 5 is a schematic diagram of an Nth layer image of a first image pyramid and an Nth layer image of a second image pyramid in an embodiment of a shape matching method of the present application; Figure 6 It is a schematic diagram of the edge image of the Nth layer image of the first image pyramid and the edge probability position mask image of the Nth layer image of the second image pyramid of the shape matching method embodiment of the present application. Specifically, in the edge probability position mask image BN1 of the Nth layer image BN of the second image pyramid, the grayscale value of the pixel points used to describe the probability position of the edge points in the Nth layer image BN of the second image pyramid is 1 (white), and the grayscale value of the pixel points other than the pixel points used to describe the probability position of the edge points in the Nth layer image BN of the second image pyramid is 0 (black). Therefore, in the edge probability position mask image BN1 of the Nth layer image BN of the second image pyramid, all the pixel points with a grayscale value of 1 describe all the probability positions of the edge points in the Nth layer image BN of the second image pyramid.
[0063] Step S150: According to the number and distribution range information of the edge points of the Nth layer image of the first image pyramid and the edge probability position mask image of the Nth layer image of the second image pyramid, determine a mask image used to describe all probability matching positions in the Nth layer image of the second image pyramid as the probability matching position mask image of the Nth layer image of the second image pyramid.
[0064] The probabilistic matching position is the position where a matching result may occur.
[0065] Further, step S150 may include step S151 to step S152.
[0066] Step S151: according to the number and distribution range information of the edge points of the Nth layer image of the first image pyramid, obtaining the matching position of the edge probability position mask image of the Nth layer image of the first image pyramid in the Nth layer image of the second image pyramid as the probability matching position of the Nth layer image of the second image pyramid.
[0067] Further, step S151 may include steps S1511 to S1514.
[0068] Step S1511: Obtain the number of edge points of the Nth layer image of the first image pyramid and the length of the diagonal line of the image border.
[0069] In this embodiment, edge detection may be performed on the Nth layer image of the first image pyramid by using a Canny operator to obtain all edge points of the Nth layer image of the first image pyramid, and the number of edge points of the Nth layer image of the first image pyramid is recorded.
[0070] by Figure 5-Figure 6 Taking an example to illustrate, all edge points of the Nth layer image AN of the first image pyramid obtained by the Canny operator can exist in the form of edge image AN1 of the Nth layer image AN of the first image pyramid. The number of edge points of the Nth layer image of the first image pyramid is obtained by calculating the number of edge points in the edge image AN1 of the Nth layer image AN of the first image pyramid.
[0071] Step S1512: Determine the side length of the square comparison area according to the length of the diagonal line of the image border of the Nth layer image of the first image pyramid.
[0072] Step S1513: traverse each square comparison area in the edge probability position mask image of the Nth layer image of the second image pyramid, calculate the number of pixel points used to describe the probability position of the edge point contained in each square comparison area as the number of comparison points, and assign the number of comparison points to the pixel points in the corresponding square comparison area respectively.
[0073] by Figure 6-Figure 9 Take this as an example to illustrate: Figure 7 is a schematic diagram of the position of one of the square comparison areas in the edge probability position mask map of the Nth layer image of the second image pyramid in the shape matching method embodiment of the present application;
[0074] Figure 8 is a schematic diagram of the position of another square comparison area in the edge probability position mask image of the Nth layer image in the shape matching method embodiment of the present application; Fig. 9It is a schematic diagram of the position of another square comparison area in the edge probability position mask image of the Nth layer image of the second image pyramid in the shape matching method embodiment of the present application.
[0075] The square comparison area C is defined as any square area in the edge probability position mask image BN1 of the Nth layer image of the second image pyramid. The side length of the square comparison area may be equal to the length of the diagonal line of the image frame of the Nth layer image of the first image pyramid.
[0076] In a specific embodiment, Figure 6-Figure 9 As shown, the number of comparison points is assigned to the upper left pixel c1 of the corresponding square comparison area C. In an alternative embodiment of assigning the number of comparison points to the upper left pixel c1 of the corresponding square comparison area C, the number of comparison points may also be assigned to other pixel points of the corresponding square comparison area C, such as the center pixel point, the lower left pixel point, or other pixel points in the corresponding square comparison area C.
[0077] In one embodiment, the pixel size of the edge probability position mask image BN1 of the Nth layer image of the second image pyramid is T×Y, where T is the width of the edge probability position mask image BN1 of the Nth layer image of the second image pyramid, and Y is the height of the edge probability position mask image BN of the Nth layer image of the second image pyramid. The pixel size of the Nth layer image of the first image pyramid is Q×K, where Q is the width of the Nth layer image of the first image pyramid, and K is the height of the Nth layer image of the first image pyramid. In this way, the size of the square comparison area C can be H×H, where H is the side length of the square comparison area C, and H can be a positive integer and satisfies the following formula (3):
[0078]
[0079] Among them, Min(T,Y) is the minimum value of T and Y, is not less than The smallest integer, in this embodiment Take this as an example for illustration. Of course, in other embodiments, H may also take other values that satisfy the above formula (3). Then the total number Z of square comparison areas C in the edge probability position mask image BN1 of the second image pyramid may satisfy the following formula (4):
[0080] Z=(T-H+1)×(Y-H+1)················(4)
[0081] In this embodiment, each square comparison area C in the edge probability position mask image BN1 of the Nth layer image of the second image pyramid is traversed, and the number of pixel points contained in each square comparison area C for describing the probability position of the edge point is calculated, which is performed in sequence by moving pixel by pixel.
[0082] Step S1514: Obtain pixel points in the edge probability position mask image of the Nth layer image of the second image pyramid whose number of comparison points is greater than the number of edge points of the Nth layer image of the first image pyramid as matching positions of the Nth layer image of the first image pyramid in the edge probability position mask image of the Nth layer image of the second image pyramid.
[0083] by Figure 6-Figure 9 For example, in the above step S1513, each square comparison area C in the edge probability position mask image BN1 of the Nth layer image of the second image pyramid is traversed, and the number of pixel points used to describe the probability position of the edge point contained in each square comparison area C is calculated. The number of pixel points used to describe the probability position of the edge point in the edge probability position mask image BN1 of the Nth layer image of the second image pyramid contained in the square comparison area C may have the following two results: The first result is as follows Figure 7 and Figure 8 contrast Figure 6 As shown, the number of pixel points used to describe the probability position of edge points in the edge probability position mask image BN1 of the Nth layer image of the second image pyramid contained in the square comparison area C is greater than the number of edge points in the edge image AN1 of the Nth layer image of the first image pyramid; the second result is as follows Fig. 9 contrast Figure 6 As shown, the number of pixel points used to describe the probability positions of edge points in the edge probability position mask image BN1 of the Nth layer image of the second image pyramid contained in the square comparison area C is less than or equal to the number of edge points in the edge image AN1 of the Nth layer image of the first image pyramid.
[0084] In the above two results, when the first result occurs, Figure 7 and Figure 8 contrast Figure 6 As shown, in the edge probability position mask image BN1 of the Nth layer image of the second image pyramid, the pixel point c1 corresponding to the square comparison area C can be the matching position of the edge probability position mask image BN1 of the Nth layer image of the first image pyramid in the Nth layer image of the second image pyramid.
[0085] In other embodiments, the number of pixel points used to describe the probability positions of edge points in the edge probability position mask image BN1 of the Nth layer image of the second image pyramid contained in the square comparison area C is greater than the number of edge points of the Nth layer image of the first image pyramid. This may be because the number of pixel points used to describe the probability positions of edge points in the edge probability position mask image BN1 of the Nth layer image of the second image pyramid contained in the square comparison area C is greater than the product of the number of edge points of the Nth layer image of the first image pyramid and the confusion threshold of the Nth layer image.
[0086] The confusion threshold of the N-th layer image is greater than 0 and less than or equal to 1. The size of the confusion threshold of the N-th layer image can be adjusted according to the calculation accuracy of the number of pixel points used to describe the probability position of the edge point in the edge probability position mask image BN1 of the N-th layer image of the second image pyramid contained in the square comparison area C and the calculation accuracy of the number of edge points of the N-th layer image of the first image pyramid. When the calculation accuracy of the number of pixel points used to describe the probability position of the edge point in the edge probability position mask image BN1 of the N-th layer image of the second image pyramid contained in the square comparison area C is large and / or the calculation accuracy of the number of edge points of the N-th layer image of the first image pyramid is large, the confusion threshold of the N-th layer image can be set to be larger, and when the calculation accuracy of the number of pixel points used to describe the probability position of the edge point in the edge probability position mask image BN1 of the N-th layer image of the second image pyramid contained in the square comparison area C is small and / or the calculation accuracy of the number of edge points of the N-th layer image of the first image pyramid is small, the confusion threshold of the N-th layer image can be set to be smaller.
[0087] Of course, in this embodiment, the confusion threshold of the Nth layer image can be numerically equal to the preset score threshold of the Nth layer image. This can prevent the probability matching position from being missed, and can more comprehensively obtain all the probability matching positions that meet the preset score threshold requirements. In this embodiment, the confusion threshold of the Nth layer image and the preset score threshold of the Nth layer image can be 0.75.
[0088] Step S152: generating a probability matching position mask image of the Nth level image of the second image pyramid for describing all probability matching positions of the Nth level image of the second image pyramid based on all probability matching positions of the Nth level image of the acquired second image pyramid.
[0089] by Fig.10 Take this as an example to illustrate: Fig.10 Schematic diagram of the probability matching position mask image of the Nth layer image of the second image pyramid obtained in step S152 of the shape matching method embodiment of the present application.
[0090] Specifically, in the probability matching position mask image BN2 of the Nth layer image of the second image pyramid, the grayscale value of the pixel points used to describe the probability matching position in the Nth layer image of the second image pyramid is 1 (white), and the grayscale value of the pixel points other than the pixel points used to describe the probability matching position in the Nth layer image of the second image pyramid is 0 (black). Therefore, in the probability matching position mask image BN2 of the Nth layer image of the second image pyramid, all the pixel points with a grayscale value of 1 describe all the probability matching positions of the Nth layer image of the second image pyramid.
[0091] Step S160: using the area where all probability matching positions described by the probability matching position mask image of the Nth layer image of the second image pyramid are located as the target matching area of the Nth layer image of the second image pyramid, calculating the correlation score of the Nth layer image of the first image pyramid in the target matching area of the Nth layer image of the second image pyramid as the Nth layer image matching score, and taking the pixel points corresponding to the correlation scores greater than the preset score threshold in the Nth layer image matching score as the Nth layer image matching result.
[0092] In this step, Figure 10-11 Take this as an example to illustrate: Fig.11 It is a schematic diagram of a target matching area in an Nth layer image of a second image pyramid in an embodiment of a shape matching method of the present application.
[0093] contrast Fig.10 and Fig.11 , the dotted area marked by d in the Nth layer image BN of the second image pyramid is the target matching area in the Nth layer image BN of the second image pyramid.
[0094] In this step, based on the effect of the probability matching position mask image BN2 of the Nth layer image of the second image pyramid, the area d where all the probability matching positions in the Nth layer image BN of the second image pyramid are located can be defined in the Nth layer image BN of the second image pyramid as the target matching area d of the Nth layer image BN of the second image pyramid.
[0095] Step S170: mapping the target matching area of the i-1 layer image of the second image pyramid according to the matching result of the i-1 layer image, calculating the correlation score of the i-1 layer image of the first image pyramid in the target matching area of the i-1 layer image of the second image pyramid as the i-1 layer image matching score, and taking the pixel points corresponding to the correlation scores of the i-1 layer image matching scores that are greater than a preset score threshold as the i-1 layer image matching results; wherein 3≤i≤N and i is an integer;
[0096] Step S180: Obtain the target matching area of the image in the area to be matched according to the matching result mapping of the second layer image, calculate the correlation score of the template image in the target matching area of the image in the area to be matched as the matching score of the first layer image, and output the pixel point corresponding to the maximum correlation score in the matching score of the first layer image as the matching result between the image in the area to be matched and the template image.
[0097] Beneficial effects of the above embodiments: In the above embodiments of the present application, by determining the edge probability position mask image of the Nth layer image of the second image pyramid, the probability matching position mask image of the Nth layer image of the second image pyramid is determined according to the number and distribution range information of the edge points of the Nth layer image of the first image pyramid and the edge probability position mask image of the Nth layer image of the second image pyramid; the area where all probability matching positions described by the probability matching position mask image of the Nth layer image of the second image pyramid are located is used as the target matching area of the Nth layer image of the second image pyramid, and then the subsequent matching operation is completed according to the target matching area. Compared with traversing and searching the entire Nth layer image of the second image pyramid, the present application reduces the amount of calculation, thereby speeding up the matching speed.
[0098] Further, before the step of calculating the correlation score of the Nth layer image of the first image pyramid in the target matching area of the Nth layer image of the second image pyramid as the Nth layer image matching score, steps S11 to S12 are included;
[0099] Step S11: extracting each edge point in the Nth layer image of the first image pyramid, and calculating the x-direction gradient and the y-direction gradient of all edge points in the Nth layer image of the first image pyramid.
[0100] In this embodiment, the Canny operator may be used to perform edge detection on the N-th layer image of the first image pyramid, to obtain all edge points of the N-th layer image of the first image pyramid, and to record the number of edge points of the N-th layer image of the first image pyramid. The Sobel operator may be used to calculate the x-direction gradient and the y-direction gradient of all edge points in the N-th layer image of the first image pyramid.
[0101] by Figure 5-Figure 6 For example, all edge points of the N-th layer image AN of the first image pyramid obtained by the Canny operator may exist in the form of an edge image AN1 of the N-th layer image AN of the first image pyramid.
[0102] Step S12: performing noise filtering and normalization processing on the x-direction gradients and y-direction gradients of all the pixels in the N-th layer image of the second image pyramid according to the preset contrast and the gradient amplitude of each pixel in the N-th layer image of the second image pyramid, and performing normalization processing on the x-direction gradients and y-direction gradients of all the edge points in the N-th layer image of the first image pyramid.
[0103] Further, the step of calculating the correlation score of the Nth layer image of the first image pyramid in the target matching area of the Nth layer image of the second image pyramid as the Nth layer image matching score includes step S13.
[0104] Step S13: Based on the normalized x-direction gradients and y-direction gradients of all edge points in the N-th layer image of the first image pyramid and the x-direction gradients and y-direction gradients of all pixel points in the N-th layer image of the second image pyramid after noise filtering and normalization, calculate the correlation score of the N-th layer image of the first image pyramid in the target matching area of the N-th layer image of the second image pyramid as the N-th layer image matching score.
[0105] Further, before the step of calculating the correlation score of the m-th layer image of the first image pyramid in the target matching area of the m-th layer image of the second image pyramid as the m-th layer image matching score, steps S21 to S24 are included. Wherein, 1≤m≤N-1 and m is an integer,
[0106] Step S21: extracting edge points in the m-th layer image of the first image pyramid, and calculating the x-direction gradient and the y-direction gradient of all edge points in the m-th layer image of the first image pyramid.
[0107] Step S22: Obtaining the x-direction gradient and the y-direction gradient of all pixel points in the m-th layer image of the second image pyramid.
[0108] Step S23: calculating the gradient amplitude of each pixel in the m-th layer image of the second image pyramid according to the x-direction gradient and the y-direction gradient of all the pixel points in the m-th layer image of the second image pyramid.
[0109] Step S24: performing noise filtering and normalization processing on the x-direction gradients and y-direction gradients of all the pixels in the m-th layer image of the second image pyramid according to the preset contrast and the gradient amplitude of each pixel in the m-th layer image of the second image pyramid, and performing normalization processing on the x-direction gradients and y-direction gradients of all the edge points in the m-th layer image of the first image pyramid.
[0110] Further, the step of calculating the correlation score of the m-th layer image of the first image pyramid in the target matching area of the m-th layer image of the second image pyramid as the m-th layer image matching score includes step S25.
[0111] Step S25: Based on the normalized x-direction gradients and y-direction gradients of all edge points in the m-th layer image of the first image pyramid and the x-direction gradients and y-direction gradients of all pixel points in the m-th layer image of the second image pyramid after noise filtering and normalization, calculate the correlation score of the m-th layer image of the first image pyramid in the target matching area of the m-th layer image of the second image pyramid as the m-th layer image matching score.
[0112] Beneficial effects of this embodiment: Since the smaller the gradient amplitude corresponding to a pixel point, the less likely the pixel point is to be an edge point and the more likely it is to be a noise point, and the larger the gradient amplitude of a pixel point, the more likely the pixel point is to be an edge point and the less likely it is to be a noise point. Therefore, in this embodiment, by performing noise filtering and normalization processing on the x-direction gradients and y-direction gradients of all pixels in the m-th layer image of the second image pyramid according to the preset contrast and the gradient amplitudes of each pixel point in the m-th layer image of the second image pyramid, the gradients of the noise points are cleared to zero, thereby effectively eliminating the interference of the noise points on the subsequent calculation of the correlation score and accelerating the matching speed.
[0113] Furthermore, in the above embodiment, the normalized x-direction gradients of all edge points in the q-th layer image of the first image pyramid satisfy the following formula (5):
[0114]
[0115] Among them, (x q ,y q ) are the coordinates of the edge points in the qth layer image of the first image pyramid, The coordinates of the normalized x-direction gradients of all edge points in the q-th layer image of the first image pyramid corresponding to the q-th layer image of the first image pyramid are (x q ,y q )’s x-direction gradient at the edge point; The x-direction gradient of all edge points in the q-th layer image of the first image pyramid before normalization corresponds to the coordinates in the q-th layer image of the first image pyramid (x q ,y q )’s x-direction gradient at the edge point, The coordinates of the y-direction gradient of all edge points in the q-th layer image of the first image pyramid before normalization processing in the q-th layer image of the first image pyramid are (xq ,y q )’s y-direction gradient at the edge point.
[0116] The normalized y-direction gradients of all edge points in the q-th layer image of the first image pyramid satisfy the following formula (6):
[0117]
[0118] Among them, (x q ,y q ) is the coordinate of any edge point in the qth layer image of the first image pyramid, The coordinates of the normalized y-direction gradient of all edge points in the q-th layer image of the first image pyramid corresponding to the q-th layer image of the first image pyramid are (x q ,y q )’s y-direction gradient at the edge point; The x-direction gradient of all edge points in the q-th layer image of the first image pyramid before normalization corresponds to the coordinates in the q-th layer image of the first image pyramid (x q ,y q )’s x-direction gradient at the edge point, The coordinates of the y-direction gradient of all edge points in the q-th layer image of the first image pyramid before normalization processing in the q-th layer image of the first image pyramid are (x q ,y q )’s y-direction gradient at the edge point.
[0119] Furthermore, the step of performing noise filtering and normalization processing on the x-direction gradients and y-direction gradients of all pixels in the q-th layer image of the second image pyramid according to the preset contrast and the gradient amplitude of each pixel in the q-th layer image of the second image pyramid includes step S31.
[0120] Step S31: performing noise filtering and normalization processing on the x-direction gradient and the y-direction gradient of all the pixels in the q-th layer image of the second image pyramid. The x-direction gradient of all the pixels in the q-th layer image of the second image pyramid after the noise filtering and normalization processing satisfies the following formula (7):
[0121]
[0122] Among them, (μ q ,ν q ) is the coordinate of any pixel point in the qth layer image of the second image pyramid, is the x-direction gradient of all pixels in the qth layer image of the second image pyramid after noise filtering and normalization, corresponding to the coordinate (μq ,ν q )’s pixel point in the x direction, is the x-direction gradient of all pixels in the qth layer image of the second image pyramid before noise filtering and normalization, corresponding to the coordinate (μ q ,ν q )’s pixel point in the x direction, is the y-direction gradient of all pixels in the qth layer image of the second image pyramid before noise filtering and normalization, corresponding to the coordinate (μ q ,ν q )’s y-direction gradient, |G f (μ q ,ν q )| is the coordinate of the qth layer image of the second image pyramid (μ q ,ν q ) pixel gradient amplitude, C min The preset contrast.
[0123] The y-direction gradient of all pixels in the qth layer image of the second image pyramid after noise filtering and normalization satisfies the following formula (8):
[0124]
[0125] Among them, (μ q ,ν q ) is the coordinate of any pixel point in the qth layer image of the second image pyramid, is the y-direction gradient of all pixels in the qth layer image of the second image pyramid after noise filtering and normalization, corresponding to the coordinate (μ q ,ν q )’s pixel point in the y direction, is the x-direction gradient of all pixels in the qth layer image of the second image pyramid before noise filtering and normalization, corresponding to the coordinate (μ q ,ν q )’s pixel point in the x direction, is the y-direction gradient of all pixels in the qth layer image of the second image pyramid before noise filtering and normalization, corresponding to the coordinate (μ q ,ν q )’s y-direction gradient, |G f (μ q ,ν q )| is the coordinate of the qth layer image of the second image pyramid (μ q ,ν q ) pixel gradient amplitude, C minThe preset contrast.
[0126] Further, based on the normalized x-direction gradients and y-direction gradients of all edge points in the q-th layer image of the first image pyramid and the x-direction gradients and y-direction gradients of all pixel points in the q-th layer image of the second image pyramid after noise filtering and normalization, a step of calculating the correlation score of the q-th layer image of the first image pyramid in the target matching area of the q-th layer image of the second image pyramid as the q-th layer image matching score includes step S32.
[0127] Step S32: Calculate the correlation score of the qth layer image of the first image pyramid in the target matching area of the qth layer image of the second image pyramid as the qth layer image matching score, and the correlation score of the qth layer image of the first image pyramid in the target matching area of the qth layer image of the second image pyramid satisfies the following formula (9):
[0128]
[0129] Among them, (w q ,s q ) is the coordinate of any pixel point in the target matching area of the qth layer image of the second image pyramid, γ(w q ,s q ) is the correlation score of the qth layer image of the first image pyramid in the target matching area of the qth layer image of the second image pyramid corresponding to the coordinate (w q ,s q )’s correlation score on the pixel, E q is the set of edge points in the qth layer image of the first image pyramid, (x q ,y q ) is the set E q The coordinates of an edge point in is the x-direction gradient of all pixels in the qth layer image of the second image pyramid after noise filtering and normalization, corresponding to the coordinate (w q +x q ,s q +y q )’s pixel point in the x direction, is the normalized x-direction gradient of all edge points in the qth layer image of the first image pyramid corresponding to the coordinate (x q ,y q )’s x-direction gradient at the edge point, is the y-direction gradient of all pixels in the qth layer image of the second image pyramid after noise filtering and normalization, corresponding to the coordinate (w q +x q,s q +y q )’s pixel point in the y direction, is the normalized y-direction gradient of all edge points in the qth layer image of the first image pyramid corresponding to the coordinate (x q ,y q )’s y-direction gradient at the edge point, |E q | is the number of edge points in the set of edge points in the qth layer image of the first image pyramid.
[0130] Beneficial effects of this embodiment: Since the smaller the gradient amplitude corresponding to a pixel point, the less likely the pixel point is to be an edge point and the more likely it is to be a noise point, and the larger the gradient amplitude of a pixel point, the more likely the pixel point is to be an edge point and the less likely it is to be a noise point. Therefore, in this embodiment, by performing noise filtering and normalization processing on the x-direction gradient and the y-direction gradient of all the pixels in the qth layer image of the second image pyramid according to the preset contrast and the gradient amplitude of each pixel in the qth layer image of the second image pyramid, 1≤q≤N and q is an integer, the gradient of the noise point is cleared to zero, thereby effectively eliminating the interference of the noise point on the subsequent calculation of the correlation score and accelerating the matching speed.
[0131] See also Fig.12 , Fig.12 It is a structural schematic diagram of the shape matching device of the present application.
[0132] like Fig.12 As shown, the shape matching device 20 includes an image pyramid generating module 21 , a mask image generating module 22 and a matching module 23 .
[0133] The image pyramid generation module 21 is used to downsample the template image N-1 times to obtain a first image pyramid containing N layers of images, and to downsample the image in the area to be matched N-1 times to obtain a second image pyramid containing N layers of images, wherein the first layer image of the first image pyramid is the template image, and the first layer image of the second image pyramid is the image in the area to be matched, and N is an integer greater than or equal to 2.
[0134] The mask image generation module 22 is used to obtain the x-direction gradient and the y-direction gradient of all pixel points in the Nth layer image of the second image pyramid, as well as a preset contrast.
[0135] The mask image generating module 22 is further configured to calculate the gradient amplitude of each pixel point in the Nth layer image of the second image pyramid according to the x-direction gradient and the y-direction gradient of all the pixel points in the Nth layer image of the second image pyramid.
[0136] The mask image generating module 22 is further used to determine, according to a preset contrast and a gradient amplitude of each pixel point in the Nth layer image of the second image pyramid, a mask image for describing all probability positions of edge points in the Nth layer image of the second image pyramid as an edge probability position mask image of the Nth layer image of the second image pyramid.
[0137] The mask image generating module 22 is further used to determine, based on the number and distribution range information of edge points of the Nth layer image of the first image pyramid and the edge probability position mask image of the Nth layer image of the second image pyramid, a mask image used to describe all probability matching positions in the Nth layer image of the second image pyramid as the probability matching position mask image of the Nth layer image of the second image pyramid.
[0138] The matching module 23 is used to use the area where all probability matching positions described by the probability matching position mask image of the Nth layer image of the second image pyramid are located as the target matching area of the Nth layer image of the second image pyramid, calculate the correlation score of the Nth layer image of the first image pyramid in the target matching area of the Nth layer image of the second image pyramid as the Nth layer image matching score, and use the pixel points corresponding to the correlation scores greater than the preset score threshold in the Nth layer image matching score as the Nth layer image matching results.
[0139] The matching module 23 is further used to obtain the target matching area of the i-1th layer image of the second image pyramid according to the matching result mapping of the i-th layer image, calculate the correlation score of the i-1th layer image of the first image pyramid in the target matching area of the i-1th layer image of the second image pyramid as the i-1th layer image matching score, and take the pixel points corresponding to the correlation scores of the i-1th layer image matching scores that are greater than a preset score threshold as the i-1th layer image matching results; wherein 3≤i≤N and i is an integer.
[0140] The matching module 23 is also used to obtain the target matching area of the image in the area to be matched according to the matching result mapping of the second layer image, calculate the correlation score of the template image in the target matching area of the image in the area to be matched as the first layer image matching score, and output the pixel point corresponding to the maximum correlation score in the first layer image matching score as the matching result between the image in the area to be matched and the template image.
[0141] Furthermore, the matching module 23 is also used to perform steps S11 to S12 of the above embodiment before calculating the correlation score of the Nth layer image of the first image pyramid in the target matching area of the Nth layer image of the second image pyramid as the Nth layer image matching score.
[0142] The step in which the matching module 23 calculates the correlation score of the th layer image of the first image pyramid in the target matching area of the Nth layer image of the second image pyramid as the Nth layer image matching score may include step S13 of the above embodiment.
[0143] Before the step of calculating the correlation score of the m-th layer image of the first image pyramid in the target matching area of the m-th layer image of the second image pyramid as the m-th layer image matching score, the matching module 23 may include steps S21 to S24 of the above embodiment, where 1≤m≤N-1 and m is an integer.
[0144] The step in which the matching module 23 calculates the correlation score of the mth layer image of the first image pyramid in the target matching area of the mth layer image of the second image pyramid as the mth layer image matching score includes step S25 of the above embodiment.
[0145] Beneficial effects of the above embodiments: In the above embodiments of the present application, by determining the edge probability position mask image of the Nth layer image of the second image pyramid, according to the number and distribution range information of the edge points of the Nth layer image of the first image pyramid and the edge probability position mask image of the Nth layer image of the second image pyramid, the probability matching position mask image of the Nth layer image of the second image pyramid is determined; the area where all probability matching positions described by the probability matching position mask image of the Nth layer image of the second image pyramid are located is used as the target matching area of the Nth layer image of the second image pyramid, and then the subsequent matching operation is completed according to the target matching area. Compared with traversing and searching the entire Nth layer image of the second image pyramid, the present application reduces the amount of calculation, thereby speeding up the matching speed; in addition, since the smaller the gradient amplitude corresponding to a pixel point, the less likely the pixel point is to be an edge point, and the more likely it is to be a noise point, the larger the gradient amplitude of a pixel point, the more likely the pixel point is to be an edge point, and the less likely it is to be a noise point. Therefore, in this embodiment, the x-direction gradient and y-direction gradient of all pixels in the qth layer image of the second image pyramid are subjected to noise filtering and normalization according to the preset contrast and the gradient amplitude of each pixel in the qth layer image of the second image pyramid, so as to clear the gradient of the noise point to zero, thereby effectively eliminating the interference of the noise point on the subsequent calculation of the correlation score and accelerating the matching speed. Wherein, 1≤q≤N and q is an integer.
[0146] See also Fig.13 , Fig.13 It is a structural diagram of a computer device embodiment of the present application.
[0147] like Fig.13As shown, the computer device 2 may include a memory 210 and a processor 220. The processor 220 is electrically coupled to the memory 210. The memory 210 is used to store program data. The program data can be loaded and executed by the processor 220, thereby implementing the shape matching method of the above embodiment of the present application.
[0148] See also Fig.14 , Fig.14 It is a schematic diagram of the structure of a storage device embodiment of the present application.
[0149] like Fig.14 As shown, the storage device 3 may include at least one storage block 31, and the program data is stored in at least one storage block 31, or in part of the storage blocks 31. The program data can be executed by a processor to implement the shape matching method of the above embodiment.
[0150] The storage device 3 in this embodiment can be as follows Fig.13 The memory 210 of the computer device 2. In other implementations, it can also be a computer-readable storage medium such as a USB disk, a network disk, a storage hard disk, etc. with a storage function. In addition, it can also be a terminal, a server, etc. with a storage function.
[0151] The above are only implementation methods of the present application, and are not intended to limit the patent scope of the present application. Any equivalent structure or equivalent process transformation made using the contents of the present application specification and drawings, or directly or indirectly applied in other related technical fields, are also included in the patent protection scope of the present application.
Claims
1. A shape matching method, characterized in that: The shape matching method comprises: Downsampling the template image N-1 times to obtain a first image pyramid including N layers of images, and downsampling the image in the area to be matched N-1 times to obtain a second image pyramid including N layers of images, wherein the first layer image of the first image pyramid is the template image, the first layer image of the second image pyramid is the image in the area to be matched, and N is an integer greater than or equal to 2; Obtaining the x-direction gradient and the y-direction gradient of all pixel points in the Nth layer image of the second image pyramid, and a preset contrast; Calculating the gradient amplitude of each pixel point in the Nth layer image of the second image pyramid according to the x-direction gradient and the y-direction gradient of all pixel points in the Nth layer image of the second image pyramid; determining, according to the preset contrast and the gradient amplitude of each pixel point in the Nth layer image of the second image pyramid, a mask image for describing all probability positions of edge points in the Nth layer image of the second image pyramid as an edge probability position mask image of the Nth layer image of the second image pyramid; Determining, according to the number and distribution range information of edge points of the Nth layer image of the first image pyramid and the edge probability position mask image of the Nth layer image of the second image pyramid, a mask image used to describe all probability matching positions in the Nth layer image of the second image pyramid as the probability matching position mask image of the Nth layer image of the second image pyramid; Taking the area where all probability matching positions described by the probability matching position mask image of the N-th layer image of the second image pyramid are located as the target matching area of the N-th layer image of the second image pyramid, calculating the correlation score of the N-th layer image of the first image pyramid in the target matching area of the N-th layer image of the second image pyramid as the N-th layer image matching score, and taking the pixel point corresponding to the correlation score greater than the preset score threshold in the N-th layer image matching score as the N-th layer image matching result; Obtain a target matching region of the i-1 layer image of the second image pyramid according to the i-1 layer image matching result mapping, calculate a correlation score of the i-1 layer image of the first image pyramid in the target matching region of the i-1 layer image of the second image pyramid as the i-1 layer image matching score, and take a pixel point corresponding to a correlation score greater than a preset score threshold in the i-1 layer image matching score as the i-1 layer image matching result; wherein 3≤i≤N and i is an integer; The target matching area of the image in the area to be matched is obtained according to the second layer image matching result mapping, the correlation score of the template image in the target matching area of the image in the area to be matched is calculated as the first layer image matching score, and the pixel point corresponding to the maximum correlation score in the first layer image matching score is output as the matching result between the image in the area to be matched and the template image.
2. The shape matching method according to claim 1, characterized in that: Before the step of calculating the correlation score of the N-th layer image of the first image pyramid in the target matching area of the N-th layer image of the second image pyramid as the N-th layer image matching score, the method includes: Extracting each edge point in the Nth layer image of the first image pyramid, and calculating the x-direction gradient and the y-direction gradient of all edge points in the Nth layer image of the first image pyramid; performing noise filtering and normalization processing on the x-direction gradients and y-direction gradients of all the pixel points in the N-th layer image of the second image pyramid according to the preset contrast and the gradient amplitude of each pixel point in the N-th layer image of the second image pyramid, and performing normalization processing on the x-direction gradients and y-direction gradients of all the edge points in the N-th layer image of the first image pyramid; The step of calculating the correlation score of the N-th layer image of the first image pyramid in the target matching area of the N-th layer image of the second image pyramid as the N-th layer image matching score comprises: Calculate, based on the normalized x-direction gradients and y-direction gradients of all edge points in the N-th layer image of the first image pyramid and the x-direction gradients and y-direction gradients of all pixel points in the N-th layer image of the second image pyramid after noise filtering and normalization, a correlation score of the N-th layer image of the first image pyramid in the target matching area of the N-th layer image of the second image pyramid as the N-th layer image matching score; Before the step of calculating the correlation score of the m-th layer image of the first image pyramid in the target matching area of the m-th layer image of the second image pyramid as the m-th layer image matching score, the method includes: Extracting each edge point in the m-th layer image of the first image pyramid, and calculating the x-direction gradient and the y-direction gradient of all edge points in the m-th layer image of the first image pyramid; Obtaining the x-direction gradient and the y-direction gradient of all pixel points in the m-th layer image of the second image pyramid; Calculating the gradient amplitude of each pixel point in the m-th layer image of the second image pyramid according to the x-direction gradient and the y-direction gradient of all pixel points in the m-th layer image of the second image pyramid; performing noise filtering and normalization processing on the x-direction gradients and y-direction gradients of all the pixels in the m-th layer image of the second image pyramid according to the preset contrast and the gradient amplitude of each pixel in the m-th layer image of the second image pyramid, and performing normalization processing on the x-direction gradients and y-direction gradients of all the edge points in the m-th layer image of the first image pyramid; The step of calculating a correlation score of the m-th layer image of the first image pyramid in the target matching area of the m-th layer image of the second image pyramid as the m-th layer image matching score comprises: Calculate, based on the normalized x-direction gradients and y-direction gradients of all edge points in the m-th layer image of the first image pyramid and the x-direction gradients and y-direction gradients of all pixel points in the m-th layer image of the second image pyramid after noise filtering and normalization, a correlation score of the m-th layer image of the first image pyramid in the target matching area of the m-th layer image of the second image pyramid as the m-th layer image matching score; Here, 1≤m≤N-1 and m is an integer.
3. The shape matching method according to claim 2, characterized in that: The step of performing noise filtering and normalization processing on the x-direction gradients and the y-direction gradients of all the pixels in the q-th layer image of the second image pyramid according to the preset contrast and the gradient amplitude of each pixel in the q-th layer image of the second image pyramid comprises: Noise filtering and normalization are performed on the x-direction gradients and y-direction gradients of all pixels in the q-th layer image of the second image pyramid, and the x-direction gradients of all pixels in the q-th layer image of the second image pyramid after noise filtering and normalization satisfy the following formula: Among them, (μ q ,ν q ) are the coordinates of the pixel points in the qth layer image of the second image pyramid, is the x-direction gradient of all pixels in the qth layer image of the second image pyramid after noise filtering and normalization, corresponding to the coordinate (μ q ,ν q )’s pixel point in the x direction, is the x-direction gradient of all pixels in the qth layer image of the second image pyramid before noise filtering and normalization, corresponding to the coordinate (μ q ,ν q )’s pixel point in the x direction, is the y-direction gradient of all pixels in the qth layer image of the second image pyramid before noise filtering and normalization processing, corresponding to the coordinate (μ q ,ν q )’s y-direction gradient, |G f (μ q ,ν q )| is the coordinate of the qth layer image of the second image pyramid (μ q ,ν q ) pixel gradient amplitude, C min The preset contrast ratio; The y-direction gradient of all pixels in the q-th layer image of the second image pyramid after noise filtering and normalization satisfies the following formula: Among them, (μ q ,ν q ) are the coordinates of the pixel points in the qth layer image of the second image pyramid, is the y-direction gradient of all pixels in the qth layer image of the second image pyramid after noise filtering and normalization, corresponding to the coordinate (μ q ,ν q )’s pixel point in the y direction, is the x-direction gradient of all pixels in the qth layer image of the second image pyramid before noise filtering and normalization, corresponding to the coordinate (μ q ,ν q )’s pixel point in the x direction, is the y-direction gradient of all pixels in the qth layer image of the second image pyramid before noise filtering and normalization processing, corresponding to the coordinate (μ q ,ν q )’s y-direction gradient, |G f (μ q ,ν q )| is the coordinate of the qth layer image of the second image pyramid (μ q ,ν q )’s pixel gradient amplitude; Here, 1≤q≤N and q is an integer.
4. The shape matching method according to claim 1, characterized in that: The step of determining, according to the preset contrast and the gradient amplitude of each pixel point in the Nth layer image of the second image pyramid, a mask image for describing all probability positions of edge points in the Nth layer image of the second image pyramid as an edge probability position mask image of the Nth layer image of the second image pyramid comprises: A mask image for describing all probability positions of edge points in an N-th layer image of the second image pyramid is determined as an edge probability position mask image of an N-th layer image of the second image pyramid, wherein the gradient amplitude of the pixel points at the probability positions of the edge points is greater than the preset contrast.
5. The shape matching method according to claim 1, characterized in that: The step of determining, based on the number and distribution range information of edge points of the Nth layer image of the first image pyramid and the edge probability position mask image of the Nth layer image of the second image pyramid, a mask image for describing all probability matching positions in the Nth layer image of the second image pyramid as the probability matching position mask image of the Nth layer image of the second image pyramid comprises: According to the number and distribution range information of the edge points of the Nth layer image of the first image pyramid, obtaining a matching position of the Nth layer image of the first image pyramid in the edge probability position mask image of the Nth layer image of the second image pyramid as a probability matching position of the Nth layer image of the second image pyramid; Based on all the acquired probabilistic matching positions of the Nth layer image of the second image pyramid, a probabilistic matching position mask image of the Nth layer image of the second image pyramid for describing all the probabilistic matching positions of the Nth layer image of the second image pyramid is generated.
6. The shape matching method according to claim 5, characterized in that: The step of obtaining, according to the number and distribution range information of edge points of the Nth layer image of the first image pyramid, a matching position of the Nth layer image of the first image pyramid in the edge probability position mask image of the Nth layer image of the second image pyramid as a probability matching position of the Nth layer image of the second image pyramid comprises: Obtaining the number of edge points of the Nth layer image of the first image pyramid and the length of the diagonal line of the image border; Determine the side length of the square comparison area according to the length of the diagonal line of the image border of the Nth layer image of the first image pyramid; Traversing each square comparison area in the edge probability position mask image of the Nth layer image of the second image pyramid, calculating the number of pixel points used to describe the probability position of the edge point contained in each square comparison area as the number of comparison points, and assigning the number of comparison points to the pixel points in the corresponding square comparison area respectively; Pixel points in the edge probability position mask image of the Nth layer image of the second image pyramid whose number of comparison points is greater than the number of edge points of the Nth layer image of the first image pyramid are obtained as matching positions of the Nth layer image of the first image pyramid in the edge probability position mask image of the Nth layer image of the second image pyramid.
7. The shape matching method according to claim 6, characterized in that: The step of generating a probability matching position mask image of the Nth layer image of the second image pyramid for describing all probability matching positions of the Nth layer image of the second image pyramid based on all probability matching positions of the Nth layer image of the second image pyramid obtained comprises: In the probability matching position mask image of the Nth layer image of the second image pyramid, the grayscale value of the pixel points used to describe the probability matching position in the Nth layer image of the second image pyramid is 1, and the grayscale value of the pixel points other than the pixel points used to describe the probability matching position in the Nth layer image of the second image pyramid is 0.
8. A shape matching device, characterized in that: The shape matching device comprises: An image pyramid generation module is used to perform N-1 down-sampling on the template image to obtain a first image pyramid including N layers of images, and perform N-1 down-sampling on the image in the area to be matched to obtain a second image pyramid including N layers of images, wherein the first layer image of the first image pyramid is the template image, the first layer image of the second image pyramid is the image in the area to be matched, and N is an integer greater than or equal to 2; a mask image generation module, used to obtain the x-direction gradient and the y-direction gradient of all pixel points in the Nth layer image of the second image pyramid, and a preset contrast; The mask image generation module is further used to calculate the gradient amplitude of each pixel point in the Nth layer image of the second image pyramid according to the x-direction gradient and the y-direction gradient of all pixel points in the Nth layer image of the second image pyramid; The mask image generating module is further used to determine, according to the preset contrast and the gradient amplitude of each pixel point in the Nth layer image of the second image pyramid, a mask image for describing all probability positions of edge points in the Nth layer image of the second image pyramid as an edge probability position mask image of the Nth layer image of the second image pyramid; The mask image generating module is further used to determine, according to the number and distribution range information of the edge points of the Nth layer image of the first image pyramid and the edge probability position mask image of the Nth layer image of the second image pyramid, a mask image used to describe all probability matching positions in the Nth layer image of the second image pyramid as the probability matching position mask image of the Nth layer image of the second image pyramid; a matching module, configured to use an area where all probability matching positions described by the probability matching position mask image of the Nth layer image of the second image pyramid are located as a target matching area of the Nth layer image of the second image pyramid, calculate a correlation score of the Nth layer image of the first image pyramid in the target matching area of the Nth layer image of the second image pyramid as an Nth layer image matching score, and use a pixel point corresponding to a correlation score greater than a preset score threshold in the Nth layer image matching score as an Nth layer image matching result; The matching module is further used to obtain a target matching area of the i-1 layer image of the second image pyramid according to the i-1 layer image matching result mapping, calculate the correlation score of the i-1 layer image of the first image pyramid in the target matching area of the i-1 layer image of the second image pyramid as the i-1 layer image matching score, and use the pixel points corresponding to the correlation scores of the i-1 layer image matching scores that are greater than a preset score threshold as the i-1 layer image matching results; wherein 3≤i≤N and i is an integer; The matching module is also used to obtain the target matching area of the image in the area to be matched according to the second layer image matching result mapping, calculate the correlation score of the template image in the target matching area of the image in the area to be matched as the first layer image matching score, and output the pixel point corresponding to the maximum correlation score in the first layer image matching score as the matching result of the image in the area to be matched and the template image.
9. A computer device, characterized in that: The computer device comprises: A memory storing program data; and a processor, wherein the program data can be executed by the processor to implement the method according to any one of claims 1 to 7.
10. A storage device, characterized in that: The storage device stores program data, and the program data can be executed by a processor to implement the method according to any one of claims 1 to 7.
Citation Information
Patent Citations
Image template matching method and device and storage device
CN112508037A
Template matching algorithm based on edge and gradient feature
WO2021017361A1
Image segmentation method and apparatus, electronic device and readable storage medium
WO2021120695A1
