A shape matching method, system, electronic device and storage medium based on NCC template matching

By preprocessing and edge detection enhancement algorithms on the target image, the shape and contour superposition are optimized and NCC matching is repeated, which solves the accuracy problem of template matching in complex environments in the prior art, and achieves higher matching success rate and system stability.

CN120070926BActive Publication Date: 2025-08-15SHENZHEN SEICHITECH TECHN CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202510541551.7
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2025-04-28
Publication Date
2025-08-15
Estimated Expiration
2045-04-28

AI Technical Summary

Technical Problem

The existing NCC-based template matching method handles the blurred, occlusion or illumination changes in the target shape in the image, and the NCC value is prone to distortion, resulting in failure of matching and difficult to meet the complex and changeable practical application needs.

Method used

By preprocessing the target image, the shape profile is extracted and superimposed on the target image, the shape features are optimized using edge detection and enhancement algorithms. If the matching degree is insufficient, the superimposes and re-NCC matching is performed until the preset standard is reached.

Benefits of technology

It improves the success rate and accuracy of template matching, enhances the stability of the system in complex environments, and reduces misjudgment and misjudgment.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120070926B_ABST
    Figure CN120070926B_ABST
Patent Text Reader

Abstract

The present application discloses a shape matching method, system, electronic device, and storage medium based on NCC template matching, which are used to improve the accuracy of NCC template matching. The shape matching method based on NCC template matching in the present application includes: preprocessing a target image to obtain a preprocessed image; then extracting a shape contour from the preprocessed image based on an edge detection algorithm and an edge enhancement algorithm; then superimposing the shape contour on the target image to obtain an image to be detected; further performing NCC matching on the image to be detected and a pre-set template to obtain a matching degree; if the matching degree is less than a preset standard, then re-superimposing the shape contour on the target image based on the superposition enhancement algorithm and re-performing NCC matching; repeating the steps of re-superimposing the shape contour on the target image based on the superposition enhancement algorithm and re-performing NCC matching until the matching degree is greater than or equal to the preset standard.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The embodiments of the present application relate to the field of image matching technology, and in particular to a shape matching method, system, electronic device, and storage medium based on NCC template matching. Background Art

[0002] Template matching, a key research area, plays a vital role in today's rapidly developing fields of computer vision, image processing, and pattern recognition. Its core principle is to accurately locate specific patterns within an image and compare and match them with pre-defined templates. This technology is widely used in a variety of key areas, such as target detection, where it can be used to identify specific people or objects in security monitoring; object recognition, where it facilitates the precise identification and classification of parts on industrial production lines; and robotic navigation, where it helps robots identify specific landmarks or obstacles in their surroundings, enabling autonomous navigation. These numerous application scenarios fully demonstrate the significant value and broad applicability of template matching technology.

[0003] Currently, there are many methods for template matching, among which the template matching method based on NCC (normalized correlation coefficient) is relatively common. This method divides the image to be matched into several small areas, calculates the NCC value between these small areas and the template one by one, and then determines the position of the template in the image to be matched based on the location of the maximum NCC value. When processing high-definition images, this method can effectively achieve accurate matching and obtain good results. However, when the target shape in the image is blurred, partially obscured, or affected by changes in light intensity and angle, the calculated NCC value is easily distorted, making it impossible to accurately determine the true position of the template, ultimately leading to matching failure and making it difficult to meet the complex and changing needs of practical applications. Summary of the Invention

[0004] The present application discloses a shape matching method, system, electronic device and storage medium based on NCC template matching, which are used to improve the accuracy of NCC template matching.

[0005] The first aspect of the present application discloses a shape matching method based on NCC template matching, comprising:

[0006] Preprocessing the target image to obtain a preprocessed image;

[0007] Extracting the shape contour of the preprocessed image according to an edge detection algorithm and an edge enhancement algorithm;

[0008] Superimposing the shape outline onto the target image to obtain an image to be detected;

[0009] Performing NCC matching on the image to be detected and the preset template to obtain a matching degree;

[0010] If the matching degree is less than the preset standard, the shape outline is re-superimposed on the target image according to the superposition enhancement algorithm, and NCC matching is performed again;

[0011] Repeat the steps of re-superimposing the shape outline onto the target image according to the superposition enhancement algorithm and re-performing NCC matching until the matching degree is greater than or equal to the preset standard.

[0012] Optionally, extracting the shape contour of the preprocessed image according to an edge detection algorithm and an edge enhancement algorithm includes:

[0013] Calculate the first-order derivative of the target image according to the Sobel operator to obtain the x-direction convolution result D x And the y-direction convolution result D y ;

[0014] Merge the x-direction convolution results D x And the y-direction convolution result D y , get the merged result;

[0015] Normalizing the merged result to a preset range to obtain a normalized result, wherein the preset range is pre-set according to the number of bits of the target image;

[0016] According to a preset threshold, setting the part of the normalized result that is less than the preset threshold to zero to obtain a zero-setting result;

[0017] The zeroing result is enhanced according to an edge enhancement algorithm to obtain a shape outline.

[0018] Optionally, the merging of the x-direction convolution results D x And the y-direction convolution result D y , the merged results include:

[0019] Get the merging formula, which is as follows:

[0020] ;

[0021] Among them, I is the merge result, D x is the x-direction convolution result, D y is the convolution result in the y direction;

[0022] The merging result is calculated according to the merging formula.

[0023] Optionally, enhancing the zeroing result according to an edge enhancement algorithm to obtain a shape contour includes:

[0024] Obtain an edge enhancement formula, which is as follows:

[0025] ;

[0026] Wherein, (x, y) is the coordinate of the pixel to be enhanced in the zeroing result, G (x,y) is the enhancement result of the pixel point (x, y) to be enhanced, I (x,y) is the merged result corresponding to the pixel point (x, y) to be enhanced, S1 is the first enhancement coefficient, and O1 is the first enhancement offset;

[0027] An enhancement result of each pixel to be enhanced in the zero-setting result is calculated according to the edge enhancement formula, and a plurality of the enhancement results constitute a shape contour.

[0028] Optionally, superimposing the shape outline onto the target image to obtain the image to be detected includes:

[0029] When the mean value of the shape contour is greater than the background mean value of the target image, a calculation is performed according to a first superposition formula to obtain an image to be detected. The first superposition formula is: , where G is the image to be detected, G1 is the target image, and G2 is the shape outline;

[0030] When the mean value of the shape contour is less than the background mean value of the target image, the image to be detected is obtained by calculation according to the second superposition formula, where the second superposition formula is: , where G is the image to be detected, G1 is the target image, and G2 is the shape outline.

[0031] Optionally, the re-superimposing the shape outline onto the target image according to the superposition enhancement algorithm includes:

[0032] When the mean value of the shape contour is greater than the background mean value of the target image, the image to be detected is obtained by calculation according to the third superposition formula, which is: , where G is the image to be detected, G1 is the target image, G2 is the shape outline, S2 is the second enhancement coefficient, and O2 is the second enhancement offset;

[0033] When the mean value of the shape contour is less than the background mean value of the target image, the image to be detected is obtained by calculation according to the fourth superposition formula, which is: , where G is the image to be detected, G1 is the target image, G2 is the shape outline, S3 is the third enhancement coefficient, and O3 is the third enhancement offset.

[0034] Optionally, the preprocessing includes at least one of the following: mean filtering noise reduction processing, median filtering noise reduction processing and Gaussian filtering noise reduction processing.

[0035] The second aspect of the present application discloses a shape matching system based on NCC template matching, comprising:

[0036] A preprocessing unit, used for preprocessing the target image to obtain a preprocessed image;

[0037] A shape contour unit, configured to extract a shape contour of the preprocessed image based on an edge detection algorithm and an edge enhancement algorithm;

[0038] An image to be detected unit, configured to superimpose the shape outline onto the target image to obtain an image to be detected;

[0039] A matching unit, configured to perform NCC matching between the image to be detected and a preset template to obtain a matching degree;

[0040] a re-execution unit, configured to re-superimpose the shape outline onto the target image and re-perform NCC matching according to an overlay enhancement algorithm if the matching degree is less than a preset standard;

[0041] The repeating unit is used to repeatedly execute the steps of re-superimposing the shape outline onto the target image according to the superposition enhancement algorithm and re-performing NCC matching until the matching degree is greater than or equal to the preset standard.

[0042] A third aspect of the present application provides an electronic device, including:

[0043] processor, memory, input and output units, and buses;

[0044] The processor is connected to the memory, input and output units, and the bus;

[0045] The memory stores a program, and the processor calls the program to execute the first aspect and any optional shape matching method based on NCC template matching in the first aspect.

[0046] In a fourth aspect, the present application provides a computer-readable storage medium on which a program is stored. When the program is executed on a computer, the shape matching method based on the first aspect and any optional NCC template matching method of the first aspect is executed.

[0047] It can be seen from the above technical solutions that the embodiments of the present application have the following advantages:

[0048] The shape matching method based on NCC template matching provided in this application first preprocesses the target image to obtain a preprocessed image; then, based on an edge detection algorithm and an edge enhancement algorithm, it extracts the shape outline of the preprocessed image; then, it superimposes the shape outline onto the target image to obtain an image to be detected; further, the image to be detected is matched with a pre-set template to obtain a matching degree; if the matching degree is less than a preset standard, the shape outline is re-superimposed onto the target image according to the superposition enhancement algorithm, and NCC matching is re-performed; and the steps of re-superimposing the shape outline onto the target image according to the superposition enhancement algorithm and re-performing NCC matching are repeated until the matching degree is greater than or equal to the preset standard. This shape matching method extracts and superimposes the shape outline by using an edge detection algorithm and an edge enhancement algorithm, which can highlight the key shape features of the target object. This allows for more accurate finding of areas similar to the template during NCC matching, even if the target object is blurred or obscured to a certain extent. When the matching degree of the first NCC matching is less than the preset standard, the superposition enhancement algorithm is introduced, and the steps of shape contour superposition and re-matching are repeated until a satisfactory matching effect is achieved. This greatly improves the success rate and accuracy of template matching, thereby enhancing the stability and reliability of the entire system in complex environments and reducing misjudgments and missed judgments caused by matching failures. BRIEF DESCRIPTION OF THE DRAWINGS

[0049] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the following briefly introduces the drawings required for use in the embodiments or descriptions of the prior art. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without any creative work.

[0050] Figure 1 This is a schematic diagram of an embodiment of the shape matching method based on NCC template matching in this application;

[0051] Figure 2 A schematic diagram of an embodiment of a method for extracting shape contours from a pre-processed image according to the present application;

[0052] Figure 3 This is a schematic diagram of another embodiment of the shape matching method based on NCC template matching in this application;

[0053] Figure 4 This is a schematic diagram of another embodiment of the shape matching method based on NCC template matching in this application;

[0054] Figure 5 This is a schematic diagram of an embodiment of a shape matching system based on NCC template matching in this application;

[0055] Figure 6 This is a schematic diagram of an embodiment of an electronic device of the present application. DETAILED DESCRIPTION

[0056] In the following description, specific details such as specific system structures and techniques are provided for purposes of illustration rather than limitation to facilitate a thorough understanding of the embodiments of the present application. However, it will be apparent to those skilled in the art that the present application may be implemented in other embodiments without these specific details. In other cases, detailed descriptions of well-known systems, devices, circuits, and methods are omitted to avoid obscuring the description of the present application with unnecessary detail.

[0057] It should be understood that when used in the present application specification, the term "comprising" indicates the presence of described features, wholes, steps, operations, elements and / or components, but does not exclude the presence or addition of one or more other features, wholes, steps, operations, elements, components and / or their collections.

[0058] It should also be understood that the term “and / or” used in the present specification refers to any combination and all possible combinations of one or more of the associated listed items, and includes these combinations.

[0059] As used in this specification, the term "if" can be interpreted as "when" or "upon" or "in response to determining" or "in response to detecting" depending on the context. Similarly, the phrase "if it is determined" or "if [described condition or event] is detected" can be interpreted as meaning "upon determination" or "in response to determining" or "upon detection of [described condition or event]" or "in response to detecting [described condition or event]" depending on the context.

[0060] In addition, in the description of the present application, the terms "first", "second", "third", etc. are only used to distinguish the description and cannot be understood as indicating or implying relative importance.

[0061] References to "one embodiment" or "some embodiments" in this specification mean that a particular feature, structure, or characteristic described in conjunction with that embodiment is included in one or more embodiments of the present application. Thus, phrases such as "in one embodiment," "in some embodiments," "in other embodiments," and "in other embodiments" appearing in various places in this specification do not necessarily refer to the same embodiment, but rather mean "one or more but not all embodiments," unless otherwise specifically emphasized. The terms "including," "comprising," "having," and variations thereof all mean "including but not limited to," unless otherwise specifically emphasized.

[0062] Template matching is a key research area in computer vision, image processing, and pattern recognition. The goal of template matching is to find specific patterns in an image and compare and match them with a pre-set template. This technology has wide applications in target detection, object recognition, and robot navigation. Various template matching methods exist, a common one being based on normalized correlation coefficient (NCC) template matching. The basic idea of this method is to first divide the image to be matched into several small regions, then calculate the NCC value between each small region and the template, and finally determine the template's position in the image to be matched based on the location of the maximum NCC value. This method works well for high-resolution images. However, existing template matching methods based on NCC template matching have limitations when processing images in certain special circumstances. For example, when the target shape in the image is blurred, occluded, or the lighting changes, the NCC value may be distorted, resulting in matching failure.

[0063] Based on this, the present application discloses a shape matching method, system, electronic device and storage medium based on NCC template matching, which are used to improve the accuracy of NCC template matching.

[0064] The following will be combined with the drawings in the embodiments of this application to clearly and completely describe the technical solutions in this application. Obviously, the embodiments described are only part of the embodiments of this application, not all of them. Based on the embodiments in this application, all other embodiments obtained by ordinary technicians in this field without making creative efforts are within the scope of protection of this application.

[0065] The method of the present application can be applied to a server, device, terminal or other device with logic processing capability, and the present application does not limit this. For the convenience of description, the following description is based on the example of the execution subject being a terminal.

[0066] See also Figure 1 The present application provides an embodiment of a shape matching method based on NCC template matching, comprising:

[0067] 101, preprocessing the target image to obtain a preprocessed image;

[0068] In this embodiment, in order to improve image quality, remove noise, adjust brightness and contrast, etc., make the image more suitable for subsequent processing steps, and improve the accuracy of shape contour extraction and template matching, the target image can be preprocessed first. The preprocessing includes at least one of the following: mean filter noise reduction processing, median filter noise reduction processing, and Gaussian filter noise reduction processing. Gaussian filter noise reduction processing performs weighted averaging on the pixel values of each pixel point in the image and its neighborhood, where the weights conform to the Gaussian distribution, and can effectively smooth the image and remove Gaussian noise. Median filter noise reduction processing sorts the pixel values in the pixel neighborhood and takes the median value as the new value of the pixel point, which is more effective in removing salt and pepper noise.

[0069] In addition to the noise reduction mentioned above, you can also adjust the brightness and contrast of the target image through methods such as linear transformation or histogram equalization. Linear transformation multiplies and adds each pixel value of the image based on given gain and offset values, changing the overall brightness and contrast of the image. Histogram equalization, on the other hand, enhances the image's contrast by redistributing the image's grayscale histogram, thereby making the details in the image clearer.

[0070] 102, extracting the shape contour of the preprocessed image according to an edge detection algorithm and an edge enhancement algorithm;

[0071] In this embodiment, in order to highlight the edge information of the target object in the image and provide key feature information for subsequent matching with the template, the shape contour of the pre-processed image obtained in step 101 should be extracted. The edge detection algorithm may include the Sobel operator or the Canny edge detection algorithm. Using the Sobel operator, convolution calculations are performed on the pre-processed image in the x and y directions respectively to obtain the approximate first-order derivatives (D) of the pre-processed image in the two directions. x and D y ), then calculates the gradient magnitude and direction. Locations with larger magnitudes typically correspond to image edges. The Canny edge detection algorithm first smooths the image using a Gaussian filter, then calculates the gradient magnitude and direction. It then performs non-maximum suppression to remove pixels that are not local maxima. Finally, it uses dual-threshold detection and edge connection to produce a clear edge image.

[0072] Based on the above edge detection algorithm, the strength and clarity of the edge can be further enhanced. For example, the grayscale values of edge pixels can be weighted amplified, or methods such as the Laplace operator can be used to make the edge more prominent, thereby more accurately extracting the shape and outline of the target object.

[0073] 103, superimposing the shape outline onto the target image to obtain an image to be detected;

[0074] In this embodiment, an image fusion method can be used to superimpose the shape outline onto the target image with a certain degree of transparency or weight. For example, for a binary shape outline image (outline pixels are white and the background is black), the grayscale value of the white outline pixels can be added to the pixel value of the corresponding position in the target image at a certain ratio, or the transparency of the pixels can be set to make the outline appear clearer on the target image while not affecting other information in the target image, thereby obtaining the image to be detected. Step 103 integrates the extracted shape outline information into the target image, making the characteristics of the target object more prominent, which helps to improve the accuracy and success rate of the subsequent NCC matching.

[0075] 104, performing NCC matching on the image to be detected and the preset template to obtain a matching degree;

[0076] In this embodiment, it should be noted that when the target is clear and a standard image of the target object is readily available, a standard sample image can be directly used as a template. In cases where no standard image is readily available, particularly when the image content is complex or a specific target area needs to be detected, a template can be obtained through manual annotation. If a database containing a large number of images is available, and these images have been classified according to specific categories, a representative image from that specific category can be selected as a template. In step 104, the image to be detected is first divided into several small areas (typically areas of the same size as a pre-set template). Then, for each small area, the NCC value between it and the template is calculated. After calculating the NCC values for all small areas, the maximum NCC value and its corresponding position are found. This position is the initial matching position of the template in the image to be detected, and the maximum NCC value is the matching degree of this match.

[0077] It should also be noted that the NCC value in this embodiment can be calculated according to the following formula:

[0078] ;

[0079] Among them, m is the sum of the number of pixels in the image to be detected and the template, (u, v) is the coordinate of the pixel, S m(u,v) is the NCC value (i.e. NCC matching degree), is the mean gradient in the x direction, is the mean gradient in the y direction, is the pixel point (u+x i , v+y i ) in the x-direction, is the pixel point (u+x i , v+y i ) in the y-direction.

[0080] 105, if the matching degree is less than the preset standard, the shape outline is re-superimposed on the target image according to the superposition enhancement algorithm, and NCC matching is performed again;

[0081] In this embodiment, it should be noted that the preset standard is set according to the target image and actual needs, and requires a higher matching operation. The preset standard can be above 0.9 (the matching degree value is between 0 and 1). When the result of the first NCC matching is not ideal (the matching degree is less than the preset standard), the feature information of the shape contour in the target image is further enhanced and the matching is attempted again to improve the matching degree and achieve more accurate template positioning. Specifically, the contrast of the shape contour can be increased, or the width of the shape contour can be expanded (by performing an expansion operation on the contour pixels) to make it more prominent in the image. For example, a morphological expansion operation is used to expand the edge of the shape contour outward by a certain pixel width to make the shape features of the target object more obvious. The enhanced shape contour is then re-superimposed on the target image according to the method of step 103 to obtain a new image to be detected, and the NCC matching process of step 104 is performed again to calculate a new matching degree.

[0082] 106 , repeatedly performing the steps of re-superimposing the shape outline onto the target image according to the superposition enhancement algorithm and re-performing the NCC matching until the matching degree is greater than or equal to a preset standard.

[0083] In this embodiment, the matching degree is continuously improved by iteratively optimizing the shape outline overlay and NCC matching process until a satisfactory match is achieved. This ensures that the template is accurately positioned within the target image, achieving high-precision matching even in complex situations such as image blur, occlusion, or illumination variations. Step 105 is executed repeatedly, with each iteration further optimizing the shape outline overlay based on the previous matching results, continuously adjusting the target image's feature information, and re-performing NCC matching until the calculated matching degree is greater than or equal to a pre-set standard. At this point, the optimal matching position of the template within the target image has been found, completing the entire template matching process.

[0084] The shape matching method based on NCC template matching provided in this application first preprocesses the target image to obtain a preprocessed image; then, based on an edge detection algorithm and an edge enhancement algorithm, it extracts the shape outline of the preprocessed image; then, it superimposes the shape outline onto the target image to obtain an image to be detected; further, the image to be detected is matched with a pre-set template to obtain a matching degree; if the matching degree is less than a preset standard, the shape outline is re-superimposed onto the target image based on the superposition enhancement algorithm and NCC matching is re-performed; and the steps of re-superimposing the shape outline onto the target image based on the superposition enhancement algorithm and NCC matching are repeated until the matching degree is greater than or equal to the preset standard. This shape matching method extracts and superimposes the shape outline by using an edge detection algorithm and an edge enhancement algorithm, which can highlight the key shape features of the target object. This allows for more accurate finding of areas similar to the template during NCC matching, even if the target object is blurred or obscured to a certain extent. When the matching degree of the first NCC matching is less than the preset standard, the superposition enhancement algorithm is introduced, and the steps of shape contour superposition and re-matching are repeated until a satisfactory matching effect is achieved. This greatly improves the success rate and accuracy of template matching, thereby enhancing the stability and reliability of the entire system in complex environments and reducing misjudgments and missed judgments caused by matching failures.

[0085] See also Figure 2 , the present application provides an embodiment of a method for extracting shape contours of a preprocessed image, comprising:

[0086] 201, calculating the first-order derivative of the target image according to the Sobel operator to obtain the x-direction convolution result Dx and the y-direction convolution result Dy;

[0087] In this embodiment, the Sobel operator is a discrete differential operator used for edge detection. It detects edges by calculating the gradient of each pixel in the image. The Sobel operator contains two convolution kernels, one for detecting edges in the horizontal direction (x direction) and the other for detecting edges in the vertical direction (y direction). Based on the x-direction convolution kernel, the entire image is traversed and convolution operation is performed to obtain the x-direction convolution result D x Similarly, according to the y-direction convolution kernel, traverse the entire image and perform convolution operation to obtain the y-direction convolution result D y .

[0088] Among them, the convolution kernel in the x direction is ; The convolution kernel in the y direction is .

[0089] 202, merge the x-direction convolution results D x And the y-direction convolution result D y , get the merged result;

[0090] In this embodiment, a merging formula is obtained, and the merging formula is as follows: ; Among them, I is the merge result, D x is the convolution result in the x direction, D y is the convolution result in the y direction. The merged result is then calculated using the merge formula. This results in an image that combines the x and y direction information. The value of each pixel reflects the gradient at that point, and areas with larger gradients usually correspond to image edges.

[0091] 203, normalizing the merged result to a preset range to obtain a normalized result, where the preset range is pre-set according to the number of bits of the target image;

[0092] In this embodiment, the merged result value is mapped to a specific range to facilitate subsequent processing and comparison. For example, if the target image is an 8-bit grayscale image (pixel value range is 0-255), the merged result can be normalized to the range of 0-255.

[0093] 204, according to a preset threshold, setting the portion of the normalized result that is smaller than the preset threshold to zero to obtain a zero-setting result;

[0094] In this embodiment, a threshold value T is pre-set based on the specific application scenario. This threshold value can be determined through experimentation or experience. For example, by observing the histogram of the image, a value that can better separate edge and non-edge areas can be selected as the threshold value. For the I value in the normalized result image, if I ≤ T, the I value is set to 0, otherwise it remains unchanged. In this way, a zero-set result image is obtained, in which areas with a value of 0 are considered non-edge areas, while other non-zero value areas may be edges or areas related to edges.

[0095] 205 , enhancing the zeroing result according to an edge enhancement algorithm to obtain a shape outline.

[0096] In this embodiment, an edge enhancement formula is obtained, and the edge enhancement formula is as follows: ; Among them, (x, y) is the coordinate of the pixel to be enhanced in the zero-setting result, G (x,y) is the enhancement result of the pixel point (x, y) to be enhanced, I (x,y) is the merged result corresponding to the pixel point (x, y) to be enhanced, S1 is the first enhancement coefficient, and O1 is the first enhancement offset. Then, the enhancement result of each pixel point to be enhanced in the zeroed result is calculated according to the edge enhancement formula. Multiple enhancement results constitute the shape outline.

[0097] Steps 201 to 205 use a variety of methods to optimize and improve edge detection and shape contour extraction, which together make the final shape contour more accurate, clear, complete, and have good versatility and stability, thereby providing more reliable feature information for image processing tasks such as NCC template matching based on shape contours, and improving the effect and efficiency of the entire image processing process.

[0098] Reference Figure 3 In step 103, the shape outline is superimposed on the target image to obtain the image to be detected, which may specifically include, but is not limited to, the following:

[0099] 301. When the mean value of the shape outline is greater than the background mean value of the target image, a calculation is performed according to a first superposition formula to obtain an image to be detected. The first superposition formula is: , where G is the image to be detected, G1 is the target image, and G2 is the shape outline;

[0100] In this embodiment, it is first necessary to calculate the mean of the shape outline and the background mean of the target image. When calculating the shape outline mean, all pixel values in the shape outline image can be added together and then divided by the total number of pixels. For the background mean of the target image, the background area in the target image (for example, an area away from the target object) can be selected and the mean of the pixel values in the area can be calculated. If the mean of the shape outline is greater than the background mean of the target image, it means that the shape outline is more prominent relative to the background, and then addition superposition is adopted. For each corresponding pixel position in the target image G1 and the shape outline G2, the pixel value of the image to be detected G at that position is calculated by the following method: In this way, the shape outline is superimposed on the target image, making the shape outline of the target object more obvious in the target image, thereby enhancing the characteristics of the target object and helping subsequent operations such as template matching to more accurately identify the target.

[0101] 302. When the mean value of the shape outline is less than the background mean value of the target image, a second superposition formula is used to calculate and obtain the image to be detected. The second superposition formula is: , where G is the image to be detected, G1 is the target image, and G2 is the shape contour.

[0102] In this embodiment, when the mean value of the shape outline is less than the background mean value of the target image, it indicates that the shape outline is darker or less obvious relative to the background. In this case, subtraction superposition is used. The calculation process of the second superposition formula is as follows: For each corresponding pixel position in the target image G1 and the shape outline G2, the pixel value of the image to be detected at that position is calculated as follows: Through this subtraction operation, the difference between the shape outline and the background can be highlighted to a certain extent, making the shape outline relatively more prominent in the target image. Even if the shape outline is originally relatively dark or inconspicuous, its recognizability in the target image can be enhanced in this way, providing more favorable conditions for subsequent template matching and improving the accuracy and success rate of matching.

[0103] These two steps adopt different superposition methods according to the relationship between the shape contour mean and the target image background mean. Both of them are aimed at better integrating the shape contour information into the target image and enhancing the characteristics of the target object to adapt to different image conditions, thereby improving the effect and adaptability of the entire image processing process.

[0104] Reference Figure 4 In step 105, re-superimposing the shape outline onto the target image according to the superposition enhancement algorithm may specifically include, but is not limited to, the following:

[0105] 401. When the mean value of the shape outline is greater than the background mean value of the target image, a calculation is performed according to a third superposition formula to obtain an image to be detected. The third superposition formula is: , where G is the image to be detected, G1 is the target image, G2 is the shape outline, S2 is the second enhancement coefficient, and O2 is the second enhancement offset;

[0106] 402. When the mean value of the shape outline is less than the background mean value of the target image, calculate according to the fourth superposition formula to obtain the image to be detected. The fourth superposition formula is: , where G is the image to be detected, G1 is the target image, G2 is the shape outline, S3 is the third enhancement coefficient, and O3 is the third enhancement offset.

[0107] In this embodiment, similar to steps 301 to 302, superposition is performed in two different situations based on the size of the mean value of the shape outline and the background mean value of the target image. The specific judgment methods for the two situations will not be described here. The prerequisite for executing step 105 is that the matching degree is less than the preset standard. In this case, it is indicated that the superposition method in step 103 cannot meet the actual matching requirements and superposition should be performed again. Unlike the superposition in step 103, two sets of enhancement coefficients and enhancement offsets are introduced in steps 401 and 402 to enhance and adjust the superposition effect. By adopting different superposition formulas based on the relationship between the mean value of the shape outline and the background mean value of the target image, and introducing enhancement coefficients S2 and S3, and offsets O2 and O3, the superposition effect of the shape outline on the target image can be more flexibly adjusted to adapt to different image features and processing requirements, further highlighting the shape outline, providing more targeted and optimized image data for subsequent operations such as template matching, and improving the accuracy and effect of image processing. For example, when the shape outline is brighter than the background, the third overlay formula can be used to enhance the shape outline while adjusting the overall brightness and contrast as needed; when the shape outline is darker than the background, the fourth overlay formula can better highlight the shape outline through subtraction and adjustment of the enhancement coefficient and offset, making it more obvious and easy to identify in the target image.

[0108] The above embodiment describes the shape matching method based on NCC template matching provided by the present application. The following describes the shape matching system, electronic device, and storage medium based on NCC template matching provided by the present application:

[0109] See also Figure 5 The present application provides an embodiment of a shape matching system based on NCC template matching, comprising:

[0110] The preprocessing unit 501 is used to preprocess the target image to obtain a preprocessed image;

[0111] A shape contour unit 502 is used to extract the shape contour of the pre-processed image according to an edge detection algorithm and an edge enhancement algorithm;

[0112] The image to be detected unit 503 is used to superimpose the shape outline on the target image to obtain the image to be detected;

[0113] The matching unit 504 is used to perform NCC matching between the image to be detected and the preset template to obtain a matching degree;

[0114] a re-execution unit 505 for re-superimposing the shape outline onto the target image and re-performing NCC matching according to an overlay enhancement algorithm if the matching degree is less than a preset standard;

[0115] The repeating unit 506 is configured to repeatedly execute the steps of re-superimposing the shape outline onto the target image according to the superposition enhancement algorithm and re-performing the NCC matching until the matching degree is greater than or equal to a preset standard.

[0116] Optionally, the shape outline unit 502 is specifically used to:

[0117] Calculate the first-order derivative of the target image according to the Sobel operator to obtain the x-direction convolution result D x And the y-direction convolution result D y ;

[0118] Merge the x-direction convolution results D x And the y-direction convolution result D y , get the merged result;

[0119] Normalizing the merged result to a preset range to obtain a normalized result, where the preset range is pre-set according to the number of bits of the target image;

[0120] According to a preset threshold, the part of the normalized result that is smaller than the preset threshold is set to zero to obtain a zero-setting result;

[0121] The zeroing result is enhanced according to the edge enhancement algorithm to obtain the shape contour.

[0122] Optionally, the shape outline unit 502 is specifically configured to:

[0123] Get the merge formula, which is as follows:

[0124] ;

[0125] Among them, I is the merge result, D x is the convolution result in the x direction, D y is the convolution result in the y direction;

[0126] Calculate the merge result according to the merge formula.

[0127] Optionally, the shape outline unit 502 is specifically configured to:

[0128] Get the edge enhancement formula, which is as follows:

[0129] ;

[0130] Among them, (x, y) is the coordinate of the pixel to be enhanced in the zero-setting result, G (x,y) is the enhancement result of the pixel point (x, y) to be enhanced, I (x,y) is the merged result corresponding to the pixel point (x, y) to be enhanced, S1 is the first enhancement coefficient, and O1 is the first enhancement offset;

[0131] The enhancement result of each pixel to be enhanced in the zero-setting result is calculated according to the edge enhancement formula, and multiple enhancement results constitute the shape contour.

[0132] Optionally, the image to be detected unit 503 is specifically configured to:

[0133] When the mean value of the shape contour is greater than the background mean value of the target image, the image to be detected is obtained by calculation according to the first superposition formula. The first superposition formula is: , where G is the image to be detected, G1 is the target image, and G2 is the shape outline;

[0134] When the mean value of the shape contour is less than the background mean value of the target image, the image to be detected is obtained by calculation according to the second superposition formula. The second superposition formula is: , where G is the image to be detected, G1 is the target image, and G2 is the shape contour.

[0135] Optionally, the re-execution unit 505 is specifically configured to:

[0136] When the mean value of the shape contour is greater than the background mean value of the target image, the image to be detected is obtained by calculation according to the third superposition formula. The third superposition formula is: , where G is the image to be detected, G1 is the target image, G2 is the shape outline, S2 is the second enhancement coefficient, and O2 is the second enhancement offset;

[0137] When the mean value of the shape outline is less than the background mean value of the target image, the image to be detected is obtained by calculation according to the fourth superposition formula. The fourth superposition formula is: , where G is the image to be detected, G1 is the target image, G2 is the shape outline, S3 is the third enhancement coefficient, and O3 is the third enhancement offset.

[0138] Optionally, the preprocessing includes at least one of the following: mean filtering noise reduction processing, median filtering noise reduction processing, and Gaussian filtering noise reduction processing.

[0139] See also Figure 6 , the present application provides an electronic device, comprising:

[0140] Processor 601 , memory 602 , input / output unit 603 , and bus 604 .

[0141] The processor 601 is connected to the memory 602 , the input and output unit 603 , and the bus 604 .

[0142] The memory 602 stores a program, and the processor 601 calls the program to execute the following Figures 1 to 4 The shape matching method based on NCC template matching in any of the illustrated embodiments.

[0143] The present application provides a computer-readable storage medium, wherein a program is stored on the computer-readable storage medium, and when the program is executed on a computer, the program performs the following operations: Figures 1 to 4 The shape matching method based on NCC template matching in any of the illustrated embodiments.

[0144] Those skilled in the art will clearly understand that, for the convenience and brevity of description, the specific working processes of the systems, devices and units described above can refer to the corresponding processes in the aforementioned method embodiments and will not be repeated here.

[0145] In the several embodiments provided in this application, it should be understood that the disclosed systems, devices and methods can be implemented in other ways. For example, the device embodiments described above are merely schematic. For example, the division of the units is merely a logical function division. In actual implementation, there may be other division methods, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be an indirect coupling or communication connection through some interfaces, devices or units, which can be electrical, mechanical or other forms.

[0146] The units described as separate components may or may not be physically separate, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed across multiple network units. Some or all of these units may be selected to achieve the purpose of this embodiment according to actual needs.

[0147] In addition, the functional units in the various embodiments of the present application may be integrated into a single processing unit, or each unit may exist physically separately, or two or more units may be integrated into a single unit. The aforementioned integrated units may be implemented in the form of hardware or software functional units.

[0148] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present application, or the part that contributes to the prior art, or all or part of the technical solution can be embodied in the form of a software product. The computer software product is stored in a storage medium and includes several instructions for enabling a computer device (which can be a personal computer, server, or network device, etc.) to execute all or part of the steps of the method described in each embodiment of the present application. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM, read-only memory), random access memory (RAM, random access memory), disk or optical disk, and other media that can store program code.

Claims

1. A shape matching method based on NCC template matching, characterized in that: The shape matching method comprises: Preprocessing the target image to obtain a preprocessed image; Extracting the shape contour of the preprocessed image according to an edge detection algorithm and an edge enhancement algorithm; When the mean value of the shape contour is greater than the background mean value of the target image, a calculation is performed according to a first superposition formula to obtain an image to be detected. The first superposition formula is: , where G is the image to be detected, G1 is the target image, and G2 is the shape outline. When the mean of the shape outline is less than the background mean of the target image, the image to be detected is obtained by calculation according to the second superposition formula, which is: , where G is the image to be detected, G1 is the target image, and G2 is the shape outline; Performing NCC matching on the image to be detected and the preset template to obtain a matching degree; If the matching degree is less than the preset standard, the shape outline is re-superimposed on the target image according to the superposition enhancement algorithm, and NCC matching is performed again; The step of re-superimposing the shape outline onto the target image according to the superposition enhancement algorithm includes: when the mean value of the shape outline is greater than the background mean value of the target image, performing calculation according to a third superposition formula to obtain the image to be detected, wherein the third superposition formula is: , where G is the image to be detected, G1 is the target image, G2 is the shape outline, S2 is the second enhancement coefficient, and O2 is the second enhancement offset; when the mean value of the shape outline is less than the background mean value of the target image, the image to be detected is obtained by calculation according to the fourth superposition formula, which is: , where G is the image to be detected, G1 is the target image, G2 is the shape outline, S3 is the third enhancement coefficient, and O3 is the third enhancement offset; Repeat the steps of re-superimposing the shape outline onto the target image according to the superposition enhancement algorithm and re-performing NCC matching until the matching degree is greater than or equal to the preset standard.

2. The shape matching method according to claim 1, characterized in that: Extracting the shape contour of the pre-processed image according to the edge detection algorithm and the edge enhancement algorithm comprises: Calculate the first-order derivative of the target image according to the Sobel operator to obtain the x-direction convolution result D x And the y-direction convolution result D y ; Merge the x-direction convolution results D x And the y-direction convolution result D y , get the merged result; Normalizing the merged result to a preset range to obtain a normalized result, wherein the preset range is pre-set according to the number of bits of the target image; According to a preset threshold, setting the part of the normalized result that is less than the preset threshold to zero to obtain a zero-setting result; The zeroing result is enhanced according to an edge enhancement algorithm to obtain a shape outline.

3. The shape matching method according to claim 2, characterized in that: The merging of the x-direction convolution results D x And the y-direction convolution result D y , the merged results include: Get the merging formula, which is as follows: ; Among them, I is the merge result, D x is the x-direction convolution result, D y is the convolution result in the y direction; The merging result is calculated according to the merging formula.

4. The shape matching method according to claim 2, characterized in that: The step of enhancing the zeroing result according to the edge enhancement algorithm to obtain the shape contour comprises: Obtain an edge enhancement formula, which is as follows: ; Wherein, (x, y) is the coordinate of the pixel to be enhanced in the zeroing result, G (x,y) is the enhancement result of the pixel point (x, y) to be enhanced, I (x,y) is the merged result corresponding to the pixel point (x, y) to be enhanced, S1 is the first enhancement coefficient, and O1 is the first enhancement offset; An enhancement result of each pixel to be enhanced in the zero-setting result is calculated according to the edge enhancement formula, and a plurality of the enhancement results constitute a shape contour.

5. The shape matching method according to claim 1, characterized in that: The preprocessing includes at least one of the following: mean filtering noise reduction processing, median filtering noise reduction processing and Gaussian filtering noise reduction processing.

6. A shape matching system based on NCC template matching, characterized in that: The shape matching system comprises: A preprocessing unit, used for preprocessing the target image to obtain a preprocessed image; A shape contour unit, configured to extract a shape contour of the preprocessed image based on an edge detection algorithm and an edge enhancement algorithm; The image unit to be detected is used to calculate according to a first superposition formula to obtain the image to be detected when the mean value of the shape contour is greater than the background mean value of the target image. The first superposition formula is: , where G is the image to be detected, G1 is the target image, and G2 is the shape outline. When the mean of the shape outline is less than the background mean of the target image, the image to be detected is obtained by calculation according to the second superposition formula, which is: , where G is the image to be detected, G1 is the target image, and G2 is the shape outline; A matching unit, configured to perform NCC matching between the image to be detected and a preset template to obtain a matching degree; a re-execution unit, configured to re-superimpose the shape outline onto the target image and re-perform NCC matching according to an overlay enhancement algorithm if the matching degree is less than a preset standard; The re-execution unit is specifically configured to: when the mean value of the shape contour is greater than the background mean value of the target image, perform calculation according to a third superposition formula to obtain an image to be detected, wherein the third superposition formula is: , where G is the image to be detected, G1 is the target image, G2 is the shape outline, S2 is the second enhancement coefficient, and O2 is the second enhancement offset; when the mean value of the shape outline is less than the background mean value of the target image, the image to be detected is obtained by calculation according to the fourth superposition formula, which is: , where G is the image to be detected, G1 is the target image, G2 is the shape outline, S3 is the third enhancement coefficient, and O3 is the third enhancement offset; The repeating unit is used to repeatedly execute the steps of re-superimposing the shape outline onto the target image according to the superposition enhancement algorithm and re-performing NCC matching until the matching degree is greater than or equal to the preset standard.

7. An electronic device, characterized in that: The electronic device comprises: processor, memory, input and output units, and buses; The processor is connected to the memory, the input and output unit, and the bus; The memory stores a program, and the processor calls the program to execute the shape matching method based on NCC template matching according to any one of claims 1 to 5.

8. A computer-readable storage medium, characterized in that The computer-readable storage medium stores a program, and when the program is executed on a computer, the shape matching method based on NCC template matching according to any one of claims 1 to 5 is executed.

Citation Information

Patent Citations

  • Image template matching method and device based on domestic CPU and opencv

    CN116563582A

  • Image time identifier identification method based on template matching

    CN118397239A