A contour matching method based on differential chain code and computer program product
By calculating and segmenting the contour point set using the differential chain code method, combined with singular value decomposition, fast and robust contour matching is achieved, solving the problems of slow speed and limited applicability in existing technologies.
Patent Information
- Application Number
- CN202410881714.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-02
- Publication Date
- 2026-11-24
- Estimated Expiration
- 2044-07-02
AI Technical Summary
Existing contour matching methods are slow and have limited applicability, making it difficult to effectively match non-closed contours.
The differential chain code method is adopted. By calculating the differential chain code array of the ordered contour point set in the image, the short differential chain code array is processed in segments, the long differential chain code array is traversed using a sliding window, the sub-cost array is fused, and the matching part is determined by combining the singular value decomposition method.
It improves the speed and robustness of contour matching, enables matching of non-closed contours, and reduces the impact of noise on matching results.
Smart Images

Figure CN118982691B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of image processing technology, and in particular to a contour matching method and computer program product based on differential chain code. Background Technology
[0002] Contour invariance is one of the main features of an image, and contour matching is an important method for object recognition. Currently, there are many methods for contour matching, including feature matching methods based on corner extraction, scale-invariant curve parameterization methods, and matching methods based on the similarity of local contour curvature. However, these methods either can only achieve closed contour matching or are computationally complex and relatively slow.
[0003] To address the aforementioned issues, improving the speed of contour matching while expanding the applicability of contour matching methods has become a pressing problem for those skilled in the art. Summary of the Invention
[0004] The purpose of this invention is to provide a contour matching method and computer program product based on differential chain code, so as to solve or at least partially solve the technical problems mentioned in the background art.
[0005] To achieve this objective, the present invention adopts the following technical solution: In a first aspect, the present invention provides a contour matching method based on differential chain code, comprising: Calculate the differential chain code array of an ordered set of contour points in an image; wherein the calculated differential chain code array includes a long differential chain code array corresponding to a first object and a short differential chain code array corresponding to a second object; The short differential chain code array is segmented sequentially to obtain a multi-segment subsequence array; Using subsequence arrays as sliding windows, the long difference chain code array is traversed one by one to obtain multiple subcost arrays with the same length as the long difference chain code array; Merge all sub-cost arrays to form the total cost array; Based on the total cost array, determine the part of the first object that matches the second object.
[0006] Optionally, the calculation of the differential chain code array of the ordered contour point set specifically involves: Calculate the differential chain code of each contour point in the ordered contour point set sequentially; The calculation method for the differential chain code of each contour point specifically includes: Establish a pre-defined correspondence between angles and differential chain codes; Make each contour point to be calculated form a vector with each of its two adjacent contour points, and obtain the angle between the two vectors. Based on the included angle and the corresponding relationship, the differential chain code of the contour point to be calculated is determined.
[0007] Optionally, before calculating the differential chain code array of the ordered contour point set, the method further includes: The contour is smoothed to obtain an initial smooth contour; For the initial smooth contour point set, sampling is performed in an orderly manner along its contour line at predetermined intervals to obtain the ordered contour point set.
[0008] Optionally, in the step of using a sub-sequence array as a sliding window to traverse the long difference chain code array and obtaining multiple sub-cost arrays with the same length as the long difference chain code array, the calculation formula for each cost value in the sub-cost array is as follows: in, Let j represent the current position of the sliding window, i be the index of the differential chain code in the subsequence array, and n be the length of the subsequence array. It is the differential chain code in the long differential chain code array.
[0009] Optionally, before fusing all sub-cost arrays to form the total cost array, the process further includes: Smooth each sub-cost array; The method for smoothing the sub-cost array is as follows: Starting from the beginning of the sub-cost array, take the minimum value of d consecutive cost values and replace the cost value at the middle position of the d consecutive cost values, until all cost values of the sub-cost array have been traversed, and a new sub-cost array is generated. Where d is an odd number greater than 1 and less than n.
[0010] Optionally, each cost value in the total cost array The calculation formula is: + in, For the x-th sub-cost array, is the length of the x-th subsequence array, m is the total number of subsequence arrays, and the value in square brackets is the index of the cost value in the subcost array.
[0011] Optionally, determining the part on the first object that matches the second object based on the total cost array specifically includes: Select the indices of all cost values in the total cost array whose cost value is less than a predetermined cost threshold; Based on the selected index, determine the starting positions of several parts on the first object corresponding to the long differential chain code array that may match the second object corresponding to the short differential chain code array.
[0012] Optionally, after determining the starting positions of several parts on the first object corresponding to the long differential chain code array that may match the second object corresponding to the short differential chain code array based on the selected index, the method further includes: The ordered contour point set of the second object is used to form corresponding point pairs with each of the possible matching parts; The transformation matrix is calculated using the singular value decomposition method to transform the corresponding point pairs, and the average distance between the corresponding point pairs after the transformation is calculated. The optimal matching location on the first object is determined based on the average distance between corresponding point pairs after transformation.
[0013] Optionally, d is 9.
[0014] Secondly, the present invention also provides a computer program product, including a computer program / instruction, characterized in that, when the computer program / instruction is executed by a processor, it implements the above-described contour matching method based on differential chain code.
[0015] Compared with the prior art, the beneficial effects of the present invention are as follows: This invention proposes a contour matching method based on differential chain code, which transforms the contour matching problem into a differential chain code matching problem. This method is faster than existing contour matching methods and is no longer limited to matching only closed contours, thus further improving the robustness of the algorithm. Attached Figure Description
[0016] To more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0017] Figure 1 A flowchart of a contour matching method based on differential chain code provided in an embodiment of the present invention.
[0018] Figure 2a This is a schematic diagram of a contour before smoothing, provided as an embodiment of the present invention.
[0019] Figure 2b This is a schematic diagram of a contour after smoothing, provided as an embodiment of the present invention.
[0020] Figure 3This is a schematic diagram of an ordered set of contour points sampled for a contour, provided in an embodiment of the present invention.
[0021] Figure 4 This is a schematic diagram illustrating the statistical rules for the included angle of vectors in an ordered contour point set, as provided in an embodiment of the present invention.
[0022] Figure 5 This is a schematic diagram illustrating the correspondence between differential chain codes and angles, provided as an embodiment of the present invention.
[0023] Figure 6 This invention provides a vector graph of an ordered set of noisy contour points.
[0024] Figure 7 This is a schematic diagram illustrating a method for traversing a sub-cost array, as provided in an embodiment of the present invention.
[0025] Figure 8 This is a schematic diagram illustrating the calculation process of a cost value according to an embodiment of the present invention.
[0026] Figure 9 This is a schematic diagram illustrating a statistical method for calculating the total cost value, as provided in an embodiment of the present invention.
[0027] Figure 10 This is a cost distribution diagram of the total cost array provided in an embodiment of the present invention.
[0028] Figure 11a This is a schematic diagram of a local contour matching scenario for an open-loop contour provided in an embodiment of the present invention.
[0029] Figure 11b for Figure 11a The matching results are shown in the image.
[0030] Figure 12 A flowchart of another contour matching method based on differential chain code provided in an embodiment of the present invention.
[0031] Figure 13 A flowchart of another contour matching method based on differential chain code provided in an embodiment of the present invention. Detailed Implementation
[0032] To make the objectives, features, and advantages of this invention more apparent and understandable, the technical solutions of the embodiments of this invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the embodiments described below are only some embodiments of this invention, and not all embodiments. Based on the embodiments of this invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this invention.
[0033] Example 1: Please refer to Figure 1 , Figure 1 A flowchart of a contour matching method based on differential chain code is provided for an embodiment of the present invention. The method specifically includes: Step 110: Smooth the contour to obtain an initial smooth contour.
[0034] Please refer to Figure 2a and Figure 2b , Figure 2a This is a schematic diagram of a contour before smoothing, provided by an embodiment of the present invention. Figure 2b This is a schematic diagram of a contour after smoothing, provided by an embodiment of the present invention; Noise in the contour has a significant impact on the uniformity of the subsequent sampling point set and is a major factor affecting the matching results. Therefore, it is necessary to smooth the contour before sampling. In this embodiment, the mean of the nearest point set is used for smoothing. Figure 2a and Figure 2b The images above show the contours before and after smoothing. Comparing the two images, it can be seen that the noise level of the contours after smoothing is significantly improved.
[0035] Step 120: For the initial smooth contour point set, sample along its contour line at predetermined intervals to obtain an ordered contour point set.
[0036] Please refer to Figure 3 , Figure 3 This is a schematic diagram of an ordered set of contour points sampled for a contour, provided in an embodiment of the present invention. In this step, it is necessary to ensure that the two point sets are ordered and have the same / similar uniformity. For this embodiment, the sampling method for the ordered contour point set is to uniformly sample the contour line at a predetermined interval, and the sampling effect is as follows: Figure 3 As shown; here, the predetermined spacing is a fixed value set in advance, which can be adapted to different application scenarios.
[0037] Step 130: Calculate the differential chain code array of the ordered contour point set in the image.
[0038] This embodiment uses differential chain code to represent the contour point set, but the differential chain code calculation method in this step is slightly different from the traditional method. For details, please refer to Figure 4 and Figure 5 , Figure 4 This is a schematic diagram illustrating the statistical rules for the included angle of vectors in an ordered contour point set, as provided in an embodiment of the present invention. Figure 5 A schematic diagram illustrating the correspondence between differential chain codes and angles provided in an embodiment of the present invention; like Figure 4As shown, assuming that contour points p1, p2, and p3 are three consecutive points in an ordered set of contour points, contour points p1, p2, and p3 constitute... and Two vectors; Compared to The deflection angle, that is, the angle θ between the two vectors, is obtained through... Figure 5 The correspondence shown is converted into differential chain code to express the contour point p2; For a closed-loop profile, each point corresponds to a differential chain code; for an open-loop profile, all points except the first and last endpoints have corresponding differential chain codes. Therefore, for an open-loop profile, the first and last endpoints can be filled with preset values. In this step, for the case of an open-loop profile, the differential chain codes of the first and last endpoints are expressed as 0.
[0039] Step 140: Segment the short differential chain code array in sequence to obtain a multi-segment subsequence array.
[0040] The ordered nature of differential chain codes can lead to noise sensitivity issues, such as... Figure 6 As shown, Figure 6 A vector graph of a noisy, ordered set of contour points is provided for an embodiment of the present invention; Figure 6 In the differential chain code, after the noise point p3 of point set P is matched with q3 of point set Q, the subsequent matching point pairs will be misaligned. That is, the error generated by the noise is transitive, and the longer the differential chain code, the more misaligned points there are and the greater the error. To suppress error propagation, the method segments the short differential chain codes sequentially, reducing the impact of transitivity by decreasing the array length. It should be noted that the length mentioned in this embodiment is different from the traditional dimension length. The length mentioned in this embodiment specifically refers to the length of the differential chain code array, that is, the total number of differential chain codes contained in the array. For ease of understanding, the target object to be matched is defined as the first object, and the object to be matched is defined as the second object. In this embodiment, it is necessary to determine whether the second object can match the first object. Furthermore, it is also necessary to determine which part of the second object and the first object can match. Therefore, the length of the differential chain code array corresponding to the second object is generally less than the length of the differential chain code array of the first object. For ease of explanation, in this embodiment, the longer differential chain code array is referred to as the long differential chain code array, and the shorter differential chain code array is referred to as the short differential chain code array.
[0041] Step 150: Use the subsequence array as a sliding window to traverse the long difference chain code array one by one to obtain multiple subcost arrays.
[0042] Please refer to Figure 7 , Figure 7 This is a schematic diagram illustrating a method for traversing a sub-cost array according to an embodiment of the present invention. Figure 8 A schematic diagram of a cost value calculation process provided in an embodiment of the present invention; The subsequence array obtained in step 140 is used to match the long differential chain code array. During matching, the subsequence array is used as a sliding window, sliding one unit length at a time, such as... Figure 7 As shown, the long differential chain code array is traversed one by one to obtain the sub-cost array corresponding to each sub-sequence array. The length of the sub-cost array is the same as the length of the long differential chain code array. The formula for calculating the cost value of each index of the sub-cost array is as follows: in, Let j represent the current position of the sliding window, i be the index of the differential chain code in the subsequence array, and n be the length of the subsequence array. The differential chain codes in the long differential chain code array; For example, such as Figure 7 As shown, when j is 1, the sliding window is at the initial position and has not slid. For c1, When j is 2, for c2, the sliding window has slid by 1 unit. And so on.
[0043] Step 160: Smooth each sub-cost array.
[0044] like Figure 8 As shown, Figure 8 A schematic diagram of a cost value calculation process provided in an embodiment of the present invention; like Figure 8 As shown, if there are no noise points, the sub-cost array should be all 0. However, because of a noise point, a segment of the entire cost array is not 0. Therefore, it is necessary to reduce the impact of noise on the cost array. The method adopted in this embodiment is to smooth each sub-cost array. Specifically, the method for smoothing the sub-cost array is as follows: Starting from the beginning of the sub-cost array, take the minimum value of d consecutive cost values and replace the cost value at the middle position of the d consecutive cost values, until all cost values of the sub-cost array have been traversed, and a new sub-cost array is generated. Where d is an odd number greater than 1 and d is less than n; For example, Figure 8 The example uses d = 3 and n = 5 to illustrate this; Figure 8In the original sub-cost array, the values are: (0, 1, 3, 4, 4, 4, 3, 1, 0, ..., 0). The first cost value of the smoothed new sub-cost array is filled with the minimum value 0 among 0, 1, and 3, so the first cost value of the new sub-cost array is 0. The second cost value is filled with the minimum value 0 among "0, 1, 3" and placed in the middle position of "0, 1, 3", which is "1" in the original sub-cost array, so the second cost value of the new sub-cost array is also 0. The third cost value is filled with the minimum value 1 among "1, 3, 4" and placed in the middle position of "1, 3, 4", which is "3" in the original sub-cost array, so the third cost value of the new sub-cost array is also 1. And so on, the new sub-cost array is: (0, 0, 1, 3, 4, 3, 1, 0, 0, ..., 0). After the sliding process, the noise impact is significantly reduced.
[0045] Step 170: Merge all sub-cost arrays to form the total cost array.
[0046] The cost values in the total cost array The calculation formula is: + in, For the x-th sub-cost array, Let x be the length of the x-th subsequence array, m be the total number of subsequence arrays, and the value in the square brackets in the calculation formula is the index of the cost value in the corresponding subcost array; For example, please refer to Figure 9 , Figure 9 This is a schematic diagram illustrating a statistical method for calculating the total cost value provided in an embodiment of the present invention, which is an application example of the above calculation formula.
[0047] Step 180: Determine the possible matching parts based on the total cost array.
[0048] Based on the total cost array, the corresponding cost distribution map can be drawn; please refer to [reference needed]. Figure 10 , Figure 10 The cost distribution map of the total cost array provided in this embodiment of the invention is as follows: Due to the denoising process used in the ascent step, the final cost distribution map is as follows. Figure 10 The graph shown is a series of segments with an increasing and decreasing pattern. The possible matching parts on the first object can be intuitively obtained from the cost distribution map. This step retains the positions with smaller costs and takes the center position of the line segment as the starting position of the possible match; specifically, this step can be implemented as follows: Step 1: Select the indices of all cost values in the total cost array whose cost value is less than the predetermined cost threshold; Step 2: Based on the selected index, determine the starting positions of several parts on the first object corresponding to the long differential chain code array that may match the second object corresponding to the short differential chain code array.
[0049] Step 190: Match the second object with each of the possible matching parts one by one to determine the optimal matching part on the first object.
[0050] Please refer to Figure 11a and Figure 11b , Figure 11a This is a schematic diagram of a local contour matching scenario for an open-loop contour provided by an embodiment of the present invention. Figure 11b for Figure 11a The matching results are shown in the image. like Figure 11a and Figure 11b As shown, a segmented fuzzy matching method is used to process the local contour, dividing the sampling point set into 6 segments, each with 30 points, and setting d to 9. Figure 11a The partial outline in the upper right corner (the second object) eventually matched the part of the dashed box of the first object; Specifically, the ordered contour point set of the second object is paired with each of the possible matching parts to form corresponding point pairs; The transformation matrix is calculated using the singular value decomposition method to transform the corresponding point pairs, and the average distance between the corresponding point pairs after the transformation is calculated. The optimal matching part on the first object is determined based on the average distance between corresponding point pairs after transformation. In the above embodiments, the singular value decomposition method is a conventional algorithm for calculating the transformation matrix, so it will not be described in detail in this embodiment; Since the contour matching method in this embodiment adopts a temporal fuzzy matching strategy, the obtained results may have positions that are similar to the local contour shape, or there may be incorrect matching positions. In order to eliminate incorrect matching, this embodiment constructs a set of corresponding point pairs with the local point set and each possible matching position, calculates the transformation matrix using the singular value decomposition method, evaluates the quality of matching by statistically analyzing the average distance of the corresponding point pairs after transformation, and finally retains the matching parts with smaller distances, thereby determining the optimal matching parts on the first object.
[0051] This embodiment proposes a contour matching method based on differential chain codes, which transforms the contour matching problem into a differential chain code matching problem. This method offers fast matching speed and is not limited to matching closed contours. Since differential chain codes are ordered, they are sensitive to noise. This method adopts a segmented contour matching approach, dividing the contour into multiple segments for sequential matching. Several steps are added to suppress noise and eliminate incorrect matches, which greatly reduces the impact of noise on the matching results and improves the robustness of the algorithm.
[0052] Example 2: This invention also provides a computer-readable storage medium storing at least one instruction, which is loaded and executed by a processor to implement a contour matching method based on differential chain code.
[0053] like Figure 12 As shown, Figure 12 This is a flowchart of another contour matching method based on differential chain code provided in an embodiment of the present invention; the contour matching method based on differential chain code specifically includes: Step 210: Smooth the contour to obtain an initial smooth contour.
[0054] Noise in the contour has a significant impact on the uniformity of the subsequent sampling point set and is a major factor affecting the matching results. Therefore, it is necessary to smooth the contour before sampling, as smoothing significantly improves the noise level of the contour.
[0055] Step 220: For the initial smooth contour point set, sample along its contour line at predetermined intervals to obtain an ordered contour point set.
[0056] In this step, it is necessary to ensure that the two point sets are ordered and have the same / similar uniformity. For this embodiment, the sampling method of the ordered contour point set is to uniformly sample the contour line at a predetermined interval. Here, the predetermined interval is a fixed value set in advance, which can be adaptively selected according to different application scenarios.
[0057] Step 230: Calculate the differential chain code array of the ordered contour point set in the image.
[0058] This embodiment uses differential chain code to represent the contour point set, but the differential chain code calculation method in this step is slightly different from the traditional method. like Figure 4 As shown, assuming that contour points p1, p2, and p3 are three consecutive points in an ordered set of contour points, contour points p1, p2, and p3 constitute... and Two vectors; Compared to The deflection angle, that is, the angle θ between the two vectors, is obtained through... Figure 5 The correspondence shown is converted into differential chain code to express the contour point p2; For a closed-loop profile, each point corresponds to a differential chain code; for an open-loop profile, all points except the first and last endpoints have corresponding differential chain codes. Therefore, for an open-loop profile, the first and last endpoints can be filled with preset values. In this step, for the case of an open-loop profile, the differential chain codes of the first and last endpoints are expressed as 0.
[0059] Step 240: Segment the short differential chain code array in sequence to obtain a multi-segment subsequence array.
[0060] The ordered nature of differential chain codes can lead to noise sensitivity issues. Figure 6 In the differential chain code, after the noise point p3 of point set P is matched with q3 of point set Q, the subsequent matching point pairs will be misaligned. That is, the error generated by the noise is transitive, and the longer the differential chain code, the more misaligned points there are and the greater the error. To suppress error propagation, the method segments the short differential chain codes sequentially, reducing the impact of transitivity by decreasing the array length. It should be noted that the length mentioned in this embodiment is different from the traditional dimension length. The length mentioned in this embodiment specifically refers to the length of the differential chain code array, that is, the total number of differential chain codes contained in the array. For ease of understanding, the target object to be matched is defined as the first object, and the object to be matched is defined as the second object. In this embodiment, it is necessary to determine whether the second object can match the first object. Furthermore, it is also necessary to determine which part of the second object and the first object can match. Therefore, the length of the differential chain code array corresponding to the second object is generally less than the length of the differential chain code array of the first object. For ease of explanation, in this embodiment, the longer differential chain code array is referred to as the long differential chain code array, and the shorter differential chain code array is referred to as the short differential chain code array.
[0061] Step 250: Use the subsequence array as a sliding window to traverse the long difference chain code array one by one to obtain multiple subcost arrays.
[0062] The subsequence array obtained in step 240 is used to match the long differential chain code array. During matching, the subsequence array is used as a sliding window, sliding one unit length at a time. Figure 7 As shown, the long differential chain code array is traversed one by one to obtain the sub-cost array corresponding to each sub-sequence array. The length of the sub-cost array is the same as the length of the long differential chain code array. The formula for calculating the cost value of each index of the sub-cost array is as follows: in, Let j represent the current position of the sliding window, i be the index of the differential chain code in the subsequence array, and n be the length of the subsequence array. The differential chain codes in the long differential chain code array; For example, such as Figure 7 As shown, when j is 1, the sliding window is at the initial position and has not slid. For c1, When j is 2, for c2, the sliding window has slid by 1 unit. And so on.
[0063] Step 260: Smooth each sub-cost array.
[0064] like Figure 8 As shown, if there are no noise points, the sub-cost array should be all 0. However, because of a noise point, a segment of the entire cost array is not 0. Therefore, it is necessary to reduce the impact of noise on the cost array. The method adopted in this embodiment is to smooth each sub-cost array. Specifically, the method for smoothing the sub-cost array is as follows: Starting from the beginning of the sub-cost array, take the minimum value of d consecutive cost values and replace the cost value at the middle position of the d consecutive cost values, until all cost values of the sub-cost array have been traversed, and a new sub-cost array is generated. Where d is an odd number greater than 1 and d is less than n; After the sliding process, the noise impact is significantly reduced.
[0065] Step 270: Merge all sub-cost arrays to form the total cost array.
[0066] The cost values in the total cost array The calculation formula is: + in, For the x-th sub-cost array, Let x be the length of the x-th subsequence array, m be the total number of subsequence arrays, and the value in the square brackets in the calculation formula be the index of the cost value in the corresponding subcost array.
[0067] Step 280: Determine the possible matching parts based on the total cost array.
[0068] Based on the total cost array, the corresponding cost distribution map can be drawn; for example... Figure 10 The value distribution map shown is a graph with segments and a pattern of increasing and decreasing values. The possible matching parts on the first object can be intuitively obtained from the cost distribution map. This step retains the positions with smaller costs and takes the center position of the line segment as the starting position of the possible match; specifically, this step can be implemented as follows: Step 1: Select the indices of all cost values in the total cost array whose cost value is less than the predetermined cost threshold; Step 2: Based on the selected index, determine the starting positions of several parts on the first object corresponding to the long differential chain code array that may match the second object corresponding to the short differential chain code array.
[0069] Step 290: Match the second object with each of the possible matching parts one by one to determine the optimal matching part on the first object.
[0070] Specifically, the ordered contour point set of the second object is paired with each of the possible matching parts to form corresponding point pairs; The transformation matrix is calculated using the singular value decomposition method to transform the corresponding point pairs, and the average distance between the corresponding point pairs after the transformation is calculated. The optimal matching part on the first object is determined based on the average distance between corresponding point pairs after transformation. Since the contour matching method in this embodiment adopts a temporal fuzzy matching strategy, the obtained results may have positions that are similar to the local contour shape, or there may be incorrect matching positions. In order to eliminate incorrect matching, this embodiment constructs a set of corresponding point pairs with the local point set and each possible matching position, calculates the transformation matrix using the singular value decomposition method, evaluates the quality of matching by statistically analyzing the average distance of the corresponding point pairs after transformation, and finally retains the matching parts with smaller distances, thereby determining the optimal matching parts on the first object.
[0071] This embodiment proposes a computer-readable storage medium in which instructions stored in the storage medium are loaded and executed by a processor to implement the contour matching method based on differential chain code provided in this embodiment. This method has a fast matching speed, is not limited to matching closed contours, and greatly reduces the impact of noise on the matching results.
[0072] Example 3: This invention also provides a computer program product, including a computer program / instruction, which, when executed by a processor, implements a contour matching method based on differential chain codes.
[0073] like Figure 13 As shown, Figure 13 A flowchart of another contour matching method based on differential chain code provided in an embodiment of the present invention; the contour matching method based on differential chain code specifically includes: Step 310: Smooth the contour to obtain an initial smooth contour.
[0074] Noise in the contour has a significant impact on the uniformity of the subsequent sampling point set and is a major factor affecting the matching results. Therefore, it is necessary to smooth the contour before sampling, as smoothing significantly improves the noise level of the contour.
[0075] Step 320: For the initial smooth contour point set, sample along its contour line at predetermined intervals to obtain an ordered contour point set.
[0076] In this step, it is necessary to ensure that the two point sets are ordered and have the same / similar uniformity. For this embodiment, the sampling method of the ordered contour point set is to uniformly sample the contour line at a predetermined interval. Here, the predetermined interval is a fixed value set in advance, which can be adaptively selected according to different application scenarios.
[0077] Step 330: Calculate the differential chain code array of the ordered contour point set in the image.
[0078] This embodiment uses differential chain code to represent the contour point set, but the differential chain code calculation method in this step is slightly different from the traditional method. like Figure 4 As shown, assuming that contour points p1, p2, and p3 are three consecutive points in an ordered set of contour points, contour points p1, p2, and p3 constitute... and Two vectors; Compared to The deflection angle, that is, the angle θ between the two vectors, is obtained through... Figure 5 The correspondence shown is converted into differential chain code to express the contour point p2; For a closed-loop profile, each point corresponds to a differential chain code; for an open-loop profile, all points except the first and last endpoints have corresponding differential chain codes. Therefore, for an open-loop profile, the first and last endpoints can be filled with preset values. In this step, for the case of an open-loop profile, the differential chain codes of the first and last endpoints are expressed as 0.
[0079] Step 340: Divide the short differential chain code array into segments in order to obtain a multi-segment subsequence array.
[0080] The ordered nature of differential chain codes can lead to noise sensitivity issues. Figure 6 In the differential chain code, after the noise point p3 of point set P is matched with q3 of point set Q, the subsequent matching point pairs will be misaligned. That is, the error generated by the noise is transitive, and the longer the differential chain code, the more misaligned points there are and the greater the error. To suppress error propagation, the method segments the short differential chain codes sequentially, reducing the impact of transitivity by decreasing the array length. It should be noted that the length mentioned in this embodiment is different from the traditional dimension length. The length mentioned in this embodiment specifically refers to the length of the differential chain code array, that is, the total number of differential chain codes contained in the array. For ease of understanding, the target object to be matched is defined as the first object, and the object to be matched is defined as the second object. In this embodiment, it is necessary to determine whether the second object can match the first object. Furthermore, it is also necessary to determine which part of the second object and the first object can match. Therefore, the length of the differential chain code array corresponding to the second object is generally less than the length of the differential chain code array of the first object. For ease of explanation, in this embodiment, the longer differential chain code array is referred to as the long differential chain code array, and the shorter differential chain code array is referred to as the short differential chain code array.
[0081] Step 350: Use the subsequence array as a sliding window to traverse the long difference chain code array one by one to obtain multiple subcost arrays.
[0082] The subsequence array obtained in step 340 is used to match the long differential chain code array. During matching, the subsequence array is used as a sliding window, sliding one unit length at a time, such as... Figure 7 As shown, the long differential chain code array is traversed one by one to obtain the sub-cost array corresponding to each sub-sequence array. The length of the sub-cost array is the same as the length of the long differential chain code array. The formula for calculating the cost value of each index of the sub-cost array is as follows: in, Let j represent the current position of the sliding window, i be the index of the differential chain code in the subsequence array, and n be the length of the subsequence array. The differential chain codes in the long differential chain code array; For example, such as Figure 7 As shown, when j is 1, the sliding window is at the initial position and has not slid. For c1, When j is 2, for c2, the sliding window has slid by 1 unit. And so on.
[0083] Step 360: Smooth each sub-cost array.
[0084] like Figure 8 As shown, if there are no noise points, the sub-cost array should be all 0. However, because of a noise point, a segment of the entire cost array is not 0. Therefore, it is necessary to reduce the impact of noise on the cost array. The method adopted in this embodiment is to smooth each sub-cost array. Specifically, the method for smoothing the sub-cost array is as follows: Starting from the beginning of the sub-cost array, take the minimum value of d consecutive cost values and replace the cost value at the middle position of the d consecutive cost values, until all cost values of the sub-cost array have been traversed, and a new sub-cost array is generated. Where d is an odd number greater than 1 and d is less than n; After the sliding process, the noise impact is significantly reduced.
[0085] Step 370: Merge all sub-cost arrays to form the total cost array.
[0086] The cost values in the total cost array The calculation formula is: + in, For the x-th sub-cost array, Let x be the length of the x-th subsequence array, m be the total number of subsequence arrays, and the value in the square brackets in the calculation formula be the index of the cost value in the corresponding subcost array.
[0087] Step 380: Determine the possible matching parts based on the total cost array.
[0088] Based on the total cost array, the corresponding cost distribution map can be drawn; for example... Figure 10 The value distribution map shown is a graph with segments and a pattern of increasing and decreasing values. The possible matching parts on the first object can be intuitively obtained from the cost distribution map. This step retains the positions with smaller costs and takes the center position of the line segment as the starting position of the possible match; specifically, this step can be implemented as follows: Step 1: Select the indices of all cost values in the total cost array whose cost value is less than the predetermined cost threshold; Step 2: Based on the selected index, determine the starting positions of several parts on the first object corresponding to the long differential chain code array that may match the second object corresponding to the short differential chain code array.
[0089] Step 390: Match the second object with each of the possible matching parts one by one to determine the optimal matching part on the first object.
[0090] Specifically, the ordered contour point set of the second object is paired with each of the possible matching parts to form corresponding point pairs; The transformation matrix is calculated using the singular value decomposition method to transform the corresponding point pairs, and the average distance between the corresponding point pairs after the transformation is calculated. The optimal matching part on the first object is determined based on the average distance between corresponding point pairs after transformation. Since the contour matching method in this embodiment adopts a temporal fuzzy matching strategy, the obtained results may have positions that are similar to the local contour shape, or there may be incorrect matching positions. In order to eliminate incorrect matching, this embodiment constructs a set of corresponding point pairs with the local point set and each possible matching position, calculates the transformation matrix using the singular value decomposition method, evaluates the quality of matching by statistically analyzing the average distance of the corresponding point pairs after transformation, and finally retains the matching parts with smaller distances, thereby determining the optimal matching parts on the first object.
[0091] This embodiment proposes a computer program product in which the computer program / instructions are executed by the processor, and the contour matching method based on differential chain code provided in this embodiment is executed. This method has a fast matching speed, is not limited to matching closed contours, and greatly reduces the impact of noise on the matching results.
[0092] Those skilled in the art will understand that all or part of the steps of the above embodiments can be implemented by hardware, or by a program instructing related hardware. The program can be stored in a computer-readable storage medium, such as a read-only memory, a disk, or an optical disk. Based on this understanding, the technical solution of the present invention, 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. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, a server, or a network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of the present invention. The aforementioned storage medium includes various media capable of storing program code, such as a USB flash drive, a portable hard drive, a read-only memory (ROM), a random access memory (RAM), a magnetic disk, or an optical disk.
[0093] The above-described embodiments are only used to illustrate the technical solutions of the present invention, and are not intended to limit it. Although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features. Such modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of the present invention.
Claims
1. A contour matching method based on differential chain code, characterized in that, include: Calculate the differential chain code array of an ordered set of contour points in an image; wherein the calculated differential chain code array includes a long differential chain code array corresponding to a first object and a short differential chain code array corresponding to a second object; The short differential chain code array is segmented sequentially to obtain a multi-segment subsequence array; Using subsequence arrays as sliding windows, the long difference chain code array is traversed one by one to obtain multiple subcost arrays with the same length as the long difference chain code array; All sub-cost arrays are merged to form a total cost array; wherein, each cost value in the total cost array is... The calculation formula is: + In the formula, For the x-th sub-cost array, is the length of the x-th subsequence array, m is the total number of subsequence arrays, and the value in square brackets is the index of the cost value in the subcost array; Based on the total cost array, determine the part of the first object that matches the second object.
2. The contour matching method based on differential chain code according to claim 1, characterized in that, The calculation of the differential chain code array for the ordered contour point set is specifically as follows: Calculate the differential chain code of each contour point in the ordered contour point set sequentially; The calculation method for the differential chain code of each contour point specifically includes: Establish a pre-defined correspondence between angles and differential chain codes; Make each contour point to be calculated form a vector with each of its two adjacent contour points, and obtain the angle between the two vectors. Based on the included angle and the corresponding relationship, the differential chain code of the contour point to be calculated is determined.
3. The contour matching method based on differential chain code according to claim 1, characterized in that, Before calculating the differential chain code array of the ordered contour point set, the method further includes: The contour is smoothed to obtain an initial smooth contour; For the initial smooth contour point set, sampling is performed in an orderly manner along its contour line at predetermined intervals to obtain the ordered contour point set.
4. The contour matching method based on differential chain code according to claim 1, characterized in that, The process involves using a sub-sequence array as a sliding window to traverse the long difference chain code array, obtaining multiple sub-cost arrays with the same length as the long difference chain code array. The calculation formula for each cost value in each sub-cost array is as follows: in, Let j represent the current position of the sliding window, i be the index of the differential chain code in the subsequence array, and n be the length of the subsequence array. It is the differential chain code in the long differential chain code array.
5. The contour matching method based on differential chain code according to claim 4, characterized in that, Before fusing all sub-cost arrays to form the total cost array, the process also includes: Smooth each sub-cost array; The method for smoothing the sub-cost array is as follows: Starting from the beginning of the sub-cost array, take the minimum value of d consecutive cost values and replace the cost value at the middle position of the d consecutive cost values, until all cost values of the sub-cost array have been traversed, and a new sub-cost array is generated. Where d is an odd number greater than 1 and less than n.
6. The contour matching method based on differential chain code according to claim 1, characterized in that, The step of determining the matching part on the first object with the second object based on the total cost array specifically includes: Select the indices of all cost values in the total cost array whose cost value is less than a predetermined cost threshold; Based on the selected index, determine the starting positions of several parts on the first object corresponding to the long differential chain code array that may match the second object corresponding to the short differential chain code array.
7. The contour matching method based on differential chain code according to claim 6, characterized in that, After determining the starting positions of several parts on the first object corresponding to the long differential chain code array that may match the second object corresponding to the short differential chain code array based on the selected index, the method further includes: The ordered contour point set of the second object is used to form corresponding point pairs with each of the possible matching parts; The transformation matrix is calculated using the singular value decomposition method to transform the corresponding point pairs, and the average distance between the corresponding point pairs after the transformation is calculated. The optimal matching location on the first object is determined based on the average distance between corresponding point pairs after transformation.
8. The contour matching method based on differential chain code according to claim 5, characterized in that, d is 9.
9. A computer program product comprising a computer program / instructions, characterized in that, When the computer program / instruction is executed by the processor, it implements the contour matching method based on differential chain code as described in any one of claims 1-8.
Citation Information
Patent Citations
Local shape matching method based on outline random sampling
CN104463866A
Pointer type instrument panel reading identification method for transformer substation inspection robot
CN112232209A
