Contour matching method based on differential chain code and computer program product
By combining differential chain code and singular value decomposition, a fast and robust contour matching method is realized, which solves the problems of slow contour matching speed and limited applicability in existing technologies and can effectively match non-closed contours.
Patent Information
- Application Number
- CN202410881714.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-02
- Publication Date
- 2024-11-19
AI Technical Summary
Existing contour matching methods are slow and have limited applicability, making it difficult to effectively match non-closed contours.
A contour matching method based on differential chain codes is adopted. By calculating the differential chain code array of an ordered contour point set, the short differential chain code array is processed in segments, and the long differential chain code array is traversed using a sliding window. Combined with the singular value decomposition method, the matching parts are determined.
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 CN118982691A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of image processing technology, and in particular to a contour matching method based on differential chain codes and a computer program product. Background Art
[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 point extraction, scale invariant curve parameterization methods, and matching methods based on local curvature similarity of contours. However, these methods can only achieve closed contour matching, or the algorithms are complex and relatively slow.
[0003] In view of the above problems, how to improve the speed of contour matching and expand the scope of application of the contour matching method has become an urgent problem to be solved by technical personnel in this field. Summary of the invention
[0004] The object of the present invention is to provide a contour matching method and a computer program product based on differential chain codes to solve or at least partially solve the technical problems mentioned in the above background technology.
[0005] To achieve this object, the present invention adopts the following technical solutions:
[0006] In a first aspect, the present invention provides a contour matching method based on differential chain code, comprising:
[0007] Calculating a differential chain code array of the ordered contour point set; wherein the calculated differential chain code array includes a long differential chain code array corresponding to the first object and a short differential chain code array corresponding to the second object;
[0008] The short differential chain code array is segmented in sequence to obtain a multi-segment subsequence array;
[0009] Use the subsequence arrays as sliding windows one by one, traverse the long differential chain code array, and obtain multiple sub-cost arrays with the same length as the long differential chain code array;
[0010] Merge all sub-cost arrays to form a total cost array;
[0011] A portion of the first object that matches the second object is determined according to the total cost array.
[0012] Optionally, the differential chain code array for calculating the ordered contour point set is specifically:
[0013] Calculate the differential chain code of each contour point of the ordered contour point set one by one in sequence;
[0014] The calculation method of the differential chain code of each contour point specifically includes:
[0015] Establish the corresponding relationship between angle and differential chain code in advance;
[0016] Make the contour point to be calculated and the two adjacent contour points form a vector respectively, and obtain the angle between the two vectors;
[0017] According to the included angle and the corresponding relationship, the differential chain code of the contour point to be calculated is determined.
[0018] Optionally, before calculating the differential chain code array of the ordered contour point set, the method further includes:
[0019] Smoothing the contour to obtain an initial smooth contour;
[0020] The initially smoothed contour point set is sampled in an orderly manner along its contour line at a predetermined interval to obtain the ordered contour point set.
[0021] Optionally, the subsequence arrays are used as sliding windows one by one to traverse the long differential chain code array to obtain multiple sub-cost arrays with the same length as the long differential chain code array. The calculation formula for each cost value in the sub-cost array is:
[0022]
[0023] Among them, C j is the cost value, j represents the current position of the sliding window, i is the index of the differential chain code in the subsequence array, n is the length of the subsequence array, and b i is the differential chain code of the subsequence array, a i-1+j is the differential chain code in the long differential chain code array.
[0024] Optionally, before fusing all sub-cost arrays to form a total cost array, the method further includes:
[0025] Smoothing each sub-cost array;
[0026] The method for smoothing the sub-cost array is specifically as follows:
[0027] Starting from the starting position of the sub-cost array, the minimum value of the consecutive d cost values is taken, and the cost value at the middle position among the consecutive d cost values is replaced, until all the cost values of the sub-cost array are traversed to generate a new sub-cost array;
[0028] Here, d is an odd number greater than 1, and d is less than n.
[0029] Optionally, each cost value c in the total cost array k The calculation formula is:
[0030] ck =s1[k]+s2[k+l1]+s3[k+l1+l2]+...+s m [k+l1+l2+...+l m-1 ]
[0031] Among them, s x is the x-th sub-cost array, l x is the length of the x-th subsequence array, m is the total number of subsequence array segments, and the value in the brackets is the index of the cost value in the sub-cost array.
[0032] Optionally, determining the part on the first object that matches the second object according to the total cost array specifically includes:
[0033] Selecting the indexes of all cost values in the total cost array whose cost values are smaller than a predetermined cost threshold;
[0034] According to the selected index, 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 are determined.
[0035] 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 according to the selected index, the method further includes:
[0036] The ordered contour point set of the second object and each possible matching part form corresponding point pairs respectively;
[0037] The transformation matrix is calculated by using a singular value decomposition method to transform the corresponding point pairs, and the average distance of the corresponding point pairs after the transformation is counted;
[0038] An optimal matching part on the first object is determined according to an average distance of the corresponding point pairs after the transformation.
[0039] Optionally, d is 9.
[0040] In a second aspect, the present invention further provides a computer program product, including a computer program / instruction, characterized in that when the computer program / instruction is executed by a processor, the above-mentioned contour matching method based on differential chain code is implemented.
[0041] Compared with the prior art, the present invention has the following beneficial effects:
[0042] The present invention proposes a contour matching method based on differential chain codes, which transforms the contour matching problem into a differential chain code matching problem. The matching speed is faster than that of the existing contour matching method, and is no longer limited to matching only closed contours, which further improves the robustness of the algorithm. BRIEF DESCRIPTION OF THE DRAWINGS
[0043] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0044] Figure 1 A flow chart of a contour matching method based on differential chain codes provided in an embodiment of the present invention.
[0045] Figure 2a A schematic diagram of a contour before smoothing provided by an embodiment of the present invention.
[0046] Figure 2b A schematic diagram of a contour after smoothing provided by an embodiment of the present invention.
[0047] Figure 3 A schematic diagram of an ordered contour point set sampled by a contour provided by an embodiment of the present invention.
[0048] Figure 4 A schematic diagram of a statistical rule for the angle of vectors in a set of ordered contour points provided by an embodiment of the present invention.
[0049] Figure 5 A schematic diagram of the correspondence between a differential chain code and an angle provided in an embodiment of the present invention.
[0050] Figure 6 A vector graph of an ordered contour point set with noise is provided in an embodiment of the present invention.
[0051] Figure 7 A schematic diagram of a method for traversing a sub-cost array provided in an embodiment of the present invention.
[0052] Figure 8 A schematic diagram of a cost value calculation process provided by an embodiment of the present invention.
[0053] Fig. 9 A schematic diagram of a total cost value statistics method provided by an embodiment of the present invention.
[0054] Fig.10 A cost value distribution diagram of a total cost array provided by an embodiment of the present invention.
[0055] Fig.11a A schematic diagram of a local contour matching scenario of an open-loop contour provided by an embodiment of the present invention.
[0056] Fig.11b for Fig.11a The matching result display diagram.
[0057] Fig.12 A flow chart of another contour matching method based on differential chain codes provided in an embodiment of the present invention.
[0058] Fig.13 A flow chart of another contour matching method based on differential chain codes provided in an embodiment of the present invention. DETAILED DESCRIPTION
[0059] In order to make the purpose, features and advantages of the present invention more obvious and easy to understand, the technical solutions in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the embodiments described below are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0060] Embodiment 1:
[0061] Please refer to Figure 1 , Figure 1 A flow chart of a contour matching method based on differential chain code provided in an embodiment of the present invention, the method specifically includes:
[0062] Step 110: Smooth the contour to obtain an initial smooth contour.
[0063] Please refer to Figure 2a and Figure 2b , Figure 2a A schematic diagram of a contour before smoothing provided by an embodiment of the present invention, Figure 2b A schematic diagram of a contour after smoothing provided by an embodiment of the present invention;
[0064] The noise of the contour has an important impact on the uniformity of the subsequent sampling point set and is the main reason that affects the matching results. Therefore, it is necessary to smooth the contour before sampling;
[0065] In this embodiment, the mean of the neighboring point set is selected for smoothing; Figure 2a and Figure 2b These are the contours before and after smoothing. By comparing the two figures above, it can be seen that the noise situation of the smoothed contour has been significantly improved.
[0066] Step 120 : For the initial smoothed contour point set, orderly sampling is performed along its contour line at a predetermined interval to obtain an orderly contour point set.
[0067] Please refer to Figure 3 , Figure 3A schematic diagram of an ordered contour point set sampled by a contour provided by an embodiment of the present invention;
[0068] 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 that the contour lines are uniformly sampled at a predetermined interval. The sampling effect is as follows: Figure 3 As shown; here, the predetermined spacing is a preset fixed value, which can be adaptively selected according to different application scenarios.
[0069] Step 130: Calculate the differential chain code array of the ordered contour point set.
[0070] This embodiment uses differential chain codes to express the contour point set, but the differential chain code calculation method in this step is slightly different from the traditional method;
[0071] For details, please refer to Figure 4 and Figure 5 , Figure 4 A schematic diagram of a statistical rule of vector angles of ordered contour point concentrations provided by an embodiment of the present invention, Figure 5 A schematic diagram of the corresponding relationship between a differential chain code and an angle provided in an embodiment of the present invention;
[0072] like Figure 4 As shown in the figure, it is assumed that contour point p1, contour point p2 and contour point p3 are three consecutive points in the ordered contour point set, and contour point p1, contour point p2 and contour point p3 constitute and two vectors;
[0073] Relative to The deflection angle, that is, the angle θ between the two vectors, is Figure 5 The corresponding relationship shown is converted into a differential chain code for expressing the contour point p2;
[0074] Among them, for the closed-loop contour, each point of the closed-loop contour corresponds to a differential chain code; and for the open-loop contour, except for the first and last endpoints, other points have corresponding differential chain codes. Therefore, for the open-loop contour, the first and last endpoints can be filled with preset fixed values. In this step, for the case of the open-loop contour, the differential chain codes of the first and last endpoints are expressed by 0.
[0075] Step 140: segment the short differential chain code array in sequence to obtain a multi-segment subsequence array.
[0076] The orderliness of differential chain codes can lead to noise sensitivity issues, such as Figure 6 As shown, Figure 6 A vector graph of an ordered contour point set with noise provided by an embodiment of the present invention;
[0077] Figure 6 In the example, after the noise point p3 of point set P matches with q3 of point set Q, the subsequent matching point pairs will be staggered, that is, the error caused by the noise is transitive, and the longer the differential chain code, the more misaligned points there are, and the greater the error.
[0078] In order to suppress error propagation, the method sequentially segments the short differential chain code, and reduces the impact of the transitivity by reducing the length of the array; it should be noted that the length in this embodiment is different from the size length in the traditional sense, and the length 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;
[0079] For ease of understanding, the matching target object 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, and further, it is necessary to determine which part of the second object can match the first object.
[0080] Therefore, the length of the differential chain code array corresponding to the second object is generally smaller than the length of the differential chain code array of the first object. For the sake of convenience, in this embodiment, the longer differential chain code array is called a long differential chain code array, and the shorter differential chain code array is called a short differential chain code array.
[0081] Step 150: Use the subsequence arrays as sliding windows one by one to traverse the long differential chain code array to obtain multiple sub-cost arrays.
[0082] Please refer to Figure 7 , Figure 7 A schematic diagram of a method for traversing a sub-cost array provided in an embodiment of the present invention, Figure 8 A schematic diagram of a cost value calculation process provided by an embodiment of the present invention;
[0083] The subsequence array obtained in step 140 is used to match the long differential chain code array respectively. When 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 subsequence array. The length of the sub-cost array here is the same as the length of the long differential chain code array. The calculation formula for the cost value of each index of the sub-cost array is as follows:
[0084]
[0085] Among them, C j is the cost value, j represents the current position of the sliding window, i is the index of the differential chain code in the subsequence array, n is the length of the subsequence array, and b iis the differential chain code of the subsequence array, a i-1+j is the differential chain code in the long differential chain code array;
[0086] For example, Figure 7 As shown, when j is 1, the sliding window is at the starting position and does not slide. For c1, When j is 2, for c2, the sliding window slides 1 length unit. And so on.
[0087] Step 160: Smoothing each sub-cost array.
[0088] like Figure 8 As shown, Figure 8 A schematic diagram of a cost value calculation process provided by an embodiment of the present invention;
[0089] like Figure 8 As shown, if there is no noise point, the sub-cost array should be all 0, but because of a noise point, a section of the entire cost array is not 0, so 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;
[0090] Specifically, the method for smoothing the sub-cost array is as follows:
[0091] Starting from the starting position of the sub-cost array, the minimum value of the consecutive d cost values is taken, and the cost value at the middle position among the consecutive d cost values is replaced, until all the cost values of the sub-cost array are traversed to generate a new sub-cost array;
[0092] Wherein, d is an odd number greater than 1, and d is less than n;
[0093] For example, Figure 8 In the example, d is 3 and n is 5;
[0094] Figure 8 In the example, the original sub-cost array is: (0, 1, 3, 4, 4, 4, 3, 1, 0, ..., 0);
[0095] The first cost value of the new sub-cost array after smoothing 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 the minimum value 0 among "0, 1, 3" filled to the middle position of "0, 1, 3" of the original sub-cost array, that is, "1", so the second cost value of the new sub-cost array is also 0; the third cost value is the minimum value 1 among "1, 3, 4" filled to the middle position of "1, 3, 4" of the original sub-cost array, that is, "3", 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);
[0096] After sliding treatment, the noise impact is significantly reduced.
[0097] Step 170: merge all sub-cost arrays to form a total cost array.
[0098] Each cost value c in the total cost array k The calculation formula is:
[0099] c k =s1[k]+s2[k+l1]+s3[k+l1+l2]+...+s m [k+l1+l2+...+l m-1 ]
[0100] Among them, s x is the x-th sub-cost array, l x is the length of the x-th subsequence array, m is the total number of subsequence array segments, and the value in the brackets in the calculation formula is the index of the cost value in the corresponding sub-cost array;
[0101] For example, please refer to Fig. 9 , Fig. 9 A schematic diagram of a statistical method for a total cost value provided in an embodiment of the present invention is an application example of the above calculation formula.
[0102] Step 180: Determine possible matching locations based on the total cost array.
[0103] According to the total cost array, the corresponding cost value distribution diagram can be drawn; please refer to Fig.10 , Fig.10 A cost value distribution diagram of a total cost array provided by an embodiment of the present invention. Since denoising is used in the ascending step, the cost value distribution diagram finally obtained is as follows: Fig.10 As shown in the figure, it is a graph that is distributed in sections and has a regular pattern of increasing and decreasing;
[0104] From the cost value distribution diagram, the possible matching parts on the first object can be intuitively obtained. In this step, the position with a smaller cost value is retained, and the center position of the line segment is taken as the starting position of the possible matching. Specifically, this step can be implemented as follows:
[0105] Step 1: Select the indexes of all cost values in the total cost array whose cost values are smaller than a predetermined cost threshold;
[0106] Step 2: According to 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.
[0107] Step 190: Match the second object with the possible matching components one by one to determine the best matching part on the first object.
[0108] Please refer to Fig.11a and Fig.11b , Fig.11a A schematic diagram of a local contour matching scenario of an open-loop contour provided by an embodiment of the present invention, Fig.11b for Fig.11a The matching result display diagram;
[0109] like Fig.11a and Fig.11b As shown in the figure, the segmented fuzzy matching method is used to process the local contour sampling point set into 6 segments, each with 30 points, and d is set to 9. Fig.11a The local contour in the upper right corner (the second object) finally matches the part of the first object at the dotted box;
[0110] Specifically, the ordered contour point set of the second object and each possible matching part are respectively used to form corresponding point pairs;
[0111] The transformation matrix is calculated by using a singular value decomposition method to transform the corresponding point pairs, and the average distance of the corresponding point pairs after the transformation is counted;
[0112] Determining the best matching part on the first object according to the average distance of the corresponding point pairs after the transformation;
[0113] In the above implementation, the singular value decomposition method is a conventional algorithm for calculating the transformation matrix, so it is not described in detail in this embodiment;
[0114] Since the contour matching method in this embodiment adopts a fuzzy matching strategy, the results obtained may have positions that are similar to the local contour shape, and may also have positions that are incorrectly matched. In order to eliminate incorrect matches, this embodiment forms a group of corresponding point pairs with the local point set and each possible matching position, and uses the singular value decomposition method to calculate the transformation matrix. The quality of the match is evaluated by statistically analyzing the average distance of the corresponding point pairs after the transformation, and finally retains the matching part with a smaller distance, thereby determining it as the optimal matching part on the first object.
[0115] The present embodiment proposes a contour matching method based on differential chain codes, which converts the contour matching problem into a differential chain code matching problem. The matching speed is fast and is not limited to matching closed contours. Since differential chain codes are ordered, they are sensitive to noise. The method adopts a segmented contour matching method, divides the contour into multiple segments for sequential matching, and adds several steps to suppress noise and eliminate erroneous matches, which greatly reduces the impact of noise on the matching results and improves the robustness of the algorithm.
[0116] Embodiment 2:
[0117] An embodiment of the present invention also provides a computer-readable storage medium, in which at least one instruction is stored. The instruction is loaded and executed by a processor to implement a contour matching method based on differential chain codes.
[0118] like Fig.12 As shown, Fig.12 Another flow chart of a contour matching method based on differential chain code provided by an embodiment of the present invention; the contour matching method based on differential chain code specifically includes:
[0119] Step 210: Smooth the contour to obtain an initial smooth contour.
[0120] The noise of the contour has an important impact on the uniformity of the subsequent sampling point set and is the main reason that affects the matching results. Therefore, before sampling, it is necessary to smooth the contour, and the noise of the smoothed contour is significantly improved.
[0121] Step 220 : For the initial smoothed contour point set, orderly sampling is performed along its contour line at a predetermined interval to obtain an ordered contour point set.
[0122] 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 that the contour lines are uniformly sampled at a predetermined interval. Here, the predetermined interval is a pre-set fixed value, which can be adaptively selected according to different application scenarios.
[0123] Step 230: Calculate the differential chain code array of the ordered contour point set.
[0124] This embodiment uses differential chain codes to express the contour point set, but the differential chain code calculation method in this step is slightly different from the traditional method;
[0125] like Figure 4 As shown in the figure, it is assumed that contour point p1, contour point p2 and contour point p3 are three consecutive points in the ordered contour point set, and contour point p1, contour point p2 and contour point p3 constitute and two vectors;
[0126] Relative to The deflection angle, that is, the angle θ between the two vectors, is Figure 5 The corresponding relationship shown is converted into a differential chain code for expressing the contour point p2;
[0127] Among them, for the closed-loop contour, each point of the closed-loop contour corresponds to a differential chain code; and for the open-loop contour, except for the first and last endpoints, other points have corresponding differential chain codes. Therefore, for the open-loop contour, the first and last endpoints can be filled with preset fixed values. In this step, for the case of the open-loop contour, the differential chain codes of the first and last endpoints are expressed by 0.
[0128] Step 240: segment the short differential chain code array in sequence to obtain a multi-segment subsequence array.
[0129] The orderliness of differential chain codes can lead to noise sensitivity issues. Figure 6 In the example, after the noise point p3 of point set P matches with q3 of point set Q, the subsequent matching point pairs will be staggered, that is, the error caused by the noise is transitive, and the longer the differential chain code, the more misaligned points there are, and the greater the error.
[0130] In order to suppress error propagation, the method sequentially segments the short differential chain code, and reduces the impact of the transitivity by reducing the length of the array; it should be noted that the length in this embodiment is different from the size length in the traditional sense, and the length 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;
[0131] For ease of understanding, the matching target object 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, and further, it is necessary to determine which part of the second object can match the first object.
[0132] Therefore, the length of the differential chain code array corresponding to the second object is generally smaller than the length of the differential chain code array of the first object. For the sake of convenience, in this embodiment, the longer differential chain code array is called a long differential chain code array, and the shorter differential chain code array is called a short differential chain code array.
[0133] Step 250: Use the subsequence arrays as sliding windows one by one to traverse the long differential chain code array to obtain multiple sub-cost arrays.
[0134] The subsequence array obtained in step 240 is used to match the long differential chain code array respectively. When 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 subsequence array. The length of the sub-cost array here is the same as the length of the long differential chain code array. The calculation formula for the cost value of each index of the sub-cost array is as follows:
[0135]
[0136] Among them, C i is the cost value, j represents the current position of the sliding window, i is the index of the differential chain code in the subsequence array, n is the length of the subsequence array, and b i is the differential chain code of the subsequence array, a i-1+j is the differential chain code in the long differential chain code array;
[0137] For example, Figure 7 As shown, when j is 1, the sliding window is at the starting position and does not slide. For c1, When j is 2, for c2, the sliding window slides 1 length unit. And so on.
[0138] Step 260: Smoothing each sub-cost array.
[0139] like Figure 8 As shown, if there is no noise point, the sub-cost array should be all 0, but because of a noise point, a section of the entire cost array is not 0, so 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;
[0140] Specifically, the method for smoothing the sub-cost array is as follows:
[0141] Starting from the starting position of the sub-cost array, the minimum value of the consecutive d cost values is taken, and the cost value at the middle position among the consecutive d cost values is replaced, until all the cost values of the sub-cost array are traversed to generate a new sub-cost array;
[0142] Wherein, d is an odd number greater than 1, and d is less than n;
[0143] After sliding treatment, the noise impact is significantly reduced.
[0144] Step 270: merge all sub-cost arrays to form a total cost array.
[0145] Each cost value c in the total cost array k The calculation formula is:
[0146] c k =s1[k]+s2[k+l1]+s3[k+l1+l2]+...+s m [k+l1+l2+...+l m-1 ]
[0147] Among them, s x is the x-th sub-cost array, l x is the length of the x-th subsequence array, m is the total number of subsequence array segments, and the value in the brackets in the calculation formula is the index of the cost value in the corresponding sub-cost array.
[0148] Step 280: Determine possible matching locations based on the total cost array.
[0149] According to the total cost array, the corresponding cost value distribution diagram can be drawn; Fig.10 As shown in the figure, the cost value distribution diagram is a diagram that is distributed in sections and has a regular pattern of increasing and decreasing;
[0150] From the cost value distribution diagram, the possible matching parts on the first object can be intuitively obtained. In this step, the position with a smaller cost value is retained, and the center position of the line segment is taken as the starting position of the possible matching. Specifically, this step can be implemented as follows:
[0151] Step 1: Select the indexes of all cost values in the total cost array whose cost values are smaller than a predetermined cost threshold;
[0152] Step 2: According to 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.
[0153] Step 290: Match the second object with the possible matching components one by one to determine the best matching part on the first object.
[0154] Specifically, the ordered contour point set of the second object and each possible matching part are respectively used to form corresponding point pairs;
[0155] The transformation matrix is calculated by using a singular value decomposition method to transform the corresponding point pairs, and the average distance of the corresponding point pairs after the transformation is counted;
[0156] Determining the best matching part on the first object according to the average distance of the corresponding point pairs after the transformation;
[0157] Since the contour matching method in this embodiment adopts a fuzzy matching strategy, the results obtained may have positions that are similar to the local contour shape, and may also have positions that are incorrectly matched. In order to eliminate incorrect matches, this embodiment forms a group of corresponding point pairs with the local point set and each possible matching position, and uses the singular value decomposition method to calculate the transformation matrix. The quality of the match is evaluated by statistically analyzing the average distance of the corresponding point pairs after the transformation, and finally retains the matching part with a smaller distance, thereby determining it as the optimal matching part on the first object.
[0158] This embodiment proposes a computer-readable storage medium, in which instructions stored are loaded and executed by a processor to implement the contour matching method based on differential chain codes 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 matching results.
[0159] Embodiment three:
[0160] An embodiment of the present 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 a differential chain code.
[0161] like Fig.13 As shown, Fig.13 A flow chart 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:
[0162] Step 310: Smooth the contour to obtain an initial smooth contour.
[0163] The noise of the contour has an important impact on the uniformity of the subsequent sampling point set and is the main reason that affects the matching results. Therefore, before sampling, it is necessary to smooth the contour, and the noise of the smoothed contour is significantly improved.
[0164] Step 320: For the initial smoothed contour point set, orderly sampling is performed along its contour line at a predetermined interval to obtain an ordered contour point set.
[0165] 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 that the contour lines are uniformly sampled at a predetermined interval. Here, the predetermined interval is a pre-set fixed value, which can be adaptively selected according to different application scenarios.
[0166] Step 330: Calculate the differential chain code array of the ordered contour point set.
[0167] This embodiment uses differential chain codes to express the contour point set, but the differential chain code calculation method in this step is slightly different from the traditional method;
[0168] like Figure 4 As shown in the figure, it is assumed that contour point p1, contour point p2 and contour point p3 are three consecutive points in the ordered contour point set, and contour point p1, contour point p2 and contour point p3 constitute and two vectors;
[0169] Relative to The deflection angle, that is, the angle θ between the two vectors, is Figure 5 The corresponding relationship shown is converted into a differential chain code for expressing the contour point p2;
[0170] Among them, for the closed-loop contour, each point of the closed-loop contour corresponds to a differential chain code; and for the open-loop contour, except for the first and last endpoints, other points have corresponding differential chain codes. Therefore, for the open-loop contour, the first and last endpoints can be filled with preset fixed values. In this step, for the case of the open-loop contour, the differential chain codes of the first and last endpoints are expressed by 0.
[0171] Step 340: segment the short differential chain code array in sequence to obtain a multi-segment subsequence array.
[0172] The orderliness of differential chain codes can lead to noise sensitivity issues. Figure 6 In the example, after the noise point p3 of point set P matches with q3 of point set Q, the subsequent matching point pairs will be staggered, that is, the error caused by the noise is transitive, and the longer the differential chain code, the more misaligned points there are, and the greater the error.
[0173] In order to suppress error propagation, the method sequentially segments the short differential chain code, and reduces the impact of the transitivity by reducing the length of the array; it should be noted that the length in this embodiment is different from the size length in the traditional sense, and the length 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;
[0174] For ease of understanding, the matching target object 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, and further, it is necessary to determine which part of the second object can match the first object.
[0175] Therefore, the length of the differential chain code array corresponding to the second object is generally smaller than the length of the differential chain code array of the first object. For the sake of convenience, in this embodiment, the longer differential chain code array is called a long differential chain code array, and the shorter differential chain code array is called a short differential chain code array.
[0176] Step 350: Use the subsequence arrays as sliding windows one by one to traverse the long differential chain code array to obtain multiple sub-cost arrays.
[0177] The subsequence array obtained in step 340 is used to match the long differential chain code array respectively. When 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 subsequence array. The length of the sub-cost array here is the same as the length of the long differential chain code array. The calculation formula for the cost value of each index of the sub-cost array is as follows:
[0178]
[0179] Among them, C j is the cost value, j represents the current position of the sliding window, i is the index of the differential chain code in the subsequence array, n is the length of the subsequence array, and b i is the differential chain code of the subsequence array, a i-1+j is the differential chain code in the long differential chain code array;
[0180] For example, Figure 7 As shown, when j is 1, the sliding window is at the starting position and does not slide. For c1, When j is 2, for c2, the sliding window slides 1 length unit. And so on.
[0181] Step 360: Smooth each sub-cost array.
[0182] like Figure 8 As shown, if there is no noise point, the sub-cost array should be all 0, but because of a noise point, a section of the entire cost array is not 0, so 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;
[0183] Specifically, the method for smoothing the sub-cost array is as follows:
[0184] Starting from the starting position of the sub-cost array, the minimum value of the consecutive d cost values is taken, and the cost value at the middle position among the consecutive d cost values is replaced, until all the cost values of the sub-cost array are traversed to generate a new sub-cost array;
[0185] Wherein, d is an odd number greater than 1, and d is less than n;
[0186] After sliding treatment, the noise impact is significantly reduced.
[0187] Step 370: merge all sub-cost arrays to form a total cost array.
[0188] Each cost value c in the total cost array k The calculation formula is:
[0189] c k =s1[k]+s2[k+l1]+s3[k+l1+l2]+...+s m [k+l1+l2+...+l m-1 ]
[0190] Among them, s x is the x-th sub-cost array, l x is the length of the x-th subsequence array, m is the total number of subsequence array segments, and the value in the brackets in the calculation formula is the index of the cost value in the corresponding sub-cost array.
[0191] Step 380: Determine possible matching locations based on the total cost array.
[0192] According to the total cost array, the corresponding cost value distribution diagram can be drawn; Fig.10 As shown in the figure, the cost value distribution diagram is a diagram that is distributed in sections and has a regular pattern of increasing and decreasing;
[0193] From the cost value distribution diagram, the possible matching parts on the first object can be intuitively obtained. In this step, the position with a smaller cost value is retained, and the center position of the line segment is taken as the starting position of the possible matching. Specifically, this step can be implemented as follows:
[0194] Step 1: Select the indexes of all cost values in the total cost array whose cost values are smaller than a predetermined cost threshold;
[0195] Step 2: According to 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.
[0196] Step 390: Match the second object with the possible matching components one by one to determine the best matching part on the first object.
[0197] Specifically, the ordered contour point set of the second object and each possible matching part are respectively used to form corresponding point pairs;
[0198] The transformation matrix is calculated by using a singular value decomposition method to transform the corresponding point pairs, and the average distance of the corresponding point pairs after the transformation is counted;
[0199] Determining the best matching part on the first object according to the average distance of the corresponding point pairs after the transformation;
[0200] Since the contour matching method in this embodiment adopts a fuzzy matching strategy, the results obtained may have positions that are similar to the local contour shape, and may also have positions that are incorrectly matched. In order to eliminate incorrect matches, this embodiment forms a group of corresponding point pairs with the local point set and each possible matching position, and uses the singular value decomposition method to calculate the transformation matrix. The quality of the match is evaluated by statistically analyzing the average distance of the corresponding point pairs after the transformation, and finally retains the matching part with a smaller distance, thereby determining it as the optimal matching part on the first object.
[0201] A computer program product is proposed in this embodiment. When the computer program / instructions in the computer program product are executed by a processor, the contour matching method based on differential chain codes 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.
[0202] Those skilled in the art can understand that all or part of the steps of the above embodiments can be completed by hardware, or by a program to instruct the relevant hardware to complete, and the program can be stored in a computer-readable storage medium, and the storage medium mentioned above can be a read-only memory, a disk or an optical disk, etc. Based on such an understanding, the technical solution of the present invention is essentially 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, and the computer software product is stored in a storage medium, including a number of instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present invention. 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, etc. Various media that can store program codes.
[0203] As described above, the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit the same. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that the technical solutions described in the aforementioned embodiments may still be modified, or some of the technical features thereof may be replaced by equivalents. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions 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, It is characterized in that include: Calculating a differential chain code array of the ordered contour point set; wherein the calculated differential chain code array includes a long differential chain code array corresponding to the first object and a short differential chain code array corresponding to the second object; The short differential chain code array is segmented in sequence to obtain a multi-segment subsequence array; Use the subsequence arrays as sliding windows one by one, traverse the long differential chain code array, and obtain multiple sub-cost arrays with the same length as the long differential chain code array; Merge all sub-cost arrays to form a total cost array; A portion of the first object that matches the second object is determined according to the total cost array.
2. According to claim 1, a contour matching method based on differential chain code, It is characterized in that The differential chain code array for calculating the ordered contour point set is specifically: Calculate the differential chain code of each contour point of the ordered contour point set one by one in sequence; The calculation method of the differential chain code of each contour point specifically includes: Establish the corresponding relationship between angle and differential chain code in advance; Make the contour point to be calculated and the two adjacent contour points form a vector respectively, and obtain the angle between the two vectors; According to the included angle and the corresponding relationship, the differential chain code of the contour point to be calculated is determined.
3. According to claim 1, a contour matching method based on differential chain code, It is characterized in that Before calculating the differential chain code array of the ordered contour point set, the method further includes: Smoothing the contour to obtain an initial smooth contour; The initially smoothed contour point set is sampled in an orderly manner along its contour line at a predetermined interval to obtain the ordered contour point set.
4. According to claim 1, a contour matching method based on differential chain code, It is characterized in that The subsequence array is used as a sliding window one by one to traverse the long differential chain code array to obtain multiple sub-cost arrays with the same length as the long differential chain code array. The calculation formula for each cost value in the sub-cost array is: Among them, C j is the cost value, j represents the current position of the sliding window, i is the index of the differential chain code in the subsequence array, n is the length of the subsequence array, and b i is the differential chain code of the subsequence array, a i-1+j is the differential chain code in the long differential chain code array.
5. According to claim 4, a contour matching method based on differential chain code, It is characterized in that Before fusing all sub-cost arrays to form a total cost array, the method further includes: Smoothing each sub-cost array; The method for smoothing the sub-cost array is specifically as follows: Starting from the starting position of the sub-cost array, the minimum value of the consecutive d cost values is taken, and the cost value at the middle position among the consecutive d cost values is replaced, until all the cost values of the sub-cost array are traversed to generate a new sub-cost array; Here, d is an odd number greater than 1, and d is less than n.
6. A contour matching method based on differential chain code according to claim 1 or 5, It is characterized in that Each cost value c in the total cost array k The calculation formula is: Each cost value c in the total cost array k The calculation formula is: c k =s 1 [k]+s 2 [k+l 1 ]+s 3 [k+l 1 +l 2 ]+...+s m [k+l 1 +l 2 +...+l m-1 ] Among them, s x is the x-th sub-cost array, l x is the length of the x-th subsequence array, m is the total number of subsequence array segments, and the value in the brackets is the index of the cost value in the sub-cost array.
7. A contour matching method based on differential chain code according to claim 6, It is characterized in that The determining, according to the total cost array, a portion on the first object that matches the second object specifically includes: Selecting the indexes of all cost values in the total cost array whose cost values are smaller than a predetermined cost threshold; According to the selected index, 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 are determined.
8. A contour matching method based on differential chain code according to claim 7, It is 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 according to the selected index, the method further includes: The ordered contour point set of the second object and each possible matching part form corresponding point pairs respectively; The transformation matrix is calculated by using a singular value decomposition method to transform the corresponding point pairs, and the average distance of the corresponding point pairs after the transformation is counted; An optimal matching part on the first object is determined according to an average distance of the corresponding point pairs after the transformation.
9. The contour matching method based on differential chain code according to claim 5, It is characterized in that d is 9.
10. A computer program product comprising a computer program / instructions, It is characterized in that When the computer program / instructions are executed by a processor, the contour matching method based on differential chain codes described in any one of claims 1 to 9 is implemented.
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
Fracture adhesion printing number identification method
CN115331235A
Fast text / graphics resolution improvement with chain-code table look-up
US20030132943A1
System and method for image analysis using a chaincode
US20040008890A1
