Summary of the invention
The object of the invention is have that calculated amount is large, execution speed is slow to solve when the element of conventional template matching algorithm to the band anglec of rotation detects, cause element to locate the problem slow with detection speed, and propose a kind of MELF element based on template matches location and detection method.
Based on MELF element location and the detection method of template matches, described MELF element location is realized by following steps with detection method:
Step one, employing optical photographic system obtain the original MELF part drawing picture of MELF element;
Step 2, select fixed threshold to carry out Threshold segmentation to the original MELF part drawing picture that step one obtains, obtain the pretreated image of binaryzation, and calculate the number of non-zero pixels point in the pretreated image of binaryzation;
Whether the number of the non-zero pixels point that step 3, determining step two obtain reaches the corresponding multiple of original MELF element total number of image pixels, if not, then terminates MELF element testing process, returns corresponding error code; If so, continue to perform step 4;
Step 4, set up according to the length of MELF element of input and width information the template image that the anglec of rotation is 0 °, to the anglec of rotation be the template image of 0 ° with 1 degree for step-length rotates, obtain comprising all template images of the anglec of rotation between [-30 °, 30 °] that the anglec of rotation is the template image of 0 °;
Step 5, employing image gaussian pyramid computing method, original MELF part drawing picture step one obtained is contracted to 1/4th as the MELF part drawing picture after reducing, and the template image that step 4 obtains is contracted to 1/4th as the template image after reducing; Wherein, the template image after reducing comprises the anglec of rotation after reducing is the template image of 0 ° and the template image of the anglec of rotation between [-30 °, 30 °] after reducing;
Step 6, respectively to step 5 obtain reduce after MELF part drawing picture and the original MELF part drawing picture that obtains of step one carry out Canny rim detection and obtain edge image, respectively not operation is carried out to the edge image obtained afterwards, to calculate in the edge image after not operation non-zero pixels point afterwards respectively to the distance of nearest zero pixel, as the distance transformed image of MELF part drawing picture after reducing and the distance transformed image of original MELF part drawing picture;
Step 7, search for image to be matched with the template image that step 4 obtains, the region that image to be matched is covered by template image, as subregion image, adopts template matches computing formula:
the similarity of antithetical phrase area image and template image and otherness carry out template matches calculating, obtain optimum matching template and the best match position of optimum matching template in original MELF part drawing picture; Wherein, T (m, n) represents the gray-scale value of template image T at (m, n) place; s
(i, j)(m, n) represents and subregion image s
(i, j)the gray-scale value at (m, n) place of middle correspondence;
Step 8, Canny rim detection is adopted to obtain being with the MELF edge image of noise spot to the original MELF part drawing picture that step one obtains, the matching result of the optimum matching template utilizing step 7 to obtain and the best match position of optimum matching template in original MELF part drawing picture, correlativity according to image border point extracts crucial marginal point from the MELF edge image of band noise spot, to determine the overall profile of MELF element in original MELF image, complete the position fixing process of MELF element;
Step 9, all crucial marginal point utilizing step 8 to obtain form minimum enclosed rectangle, the position of MELF element in original MELF part drawing picture is represented with minimum enclosed rectangle, the centre coordinate of minimum enclosed rectangle represents that the centre coordinate of MELF element, the anglec of rotation of minimum enclosed rectangle represent the anglec of rotation of MELF element; When the centre coordinate of minimum enclosed rectangle and the anglec of rotation constant, form the rectangle after outwards increasing amount of bias after the length of minimum enclosed rectangle and width being amplified 1.1 times; Again when centre coordinate and the anglec of rotation of minimum enclosed rectangle, the rectangle inwardly increased after amount of bias will be formed after the length of minimum enclosed rectangle and reduced width 0.9 times;
Rectangle after step 10, the outside increase amount of bias that obtains according to step 9 or inwardly increase the number of non-zero pixels in the rectangle after amount of bias, whether correctly judge to detect the MELF position of components obtained, if incorrect, then terminate the testing process of MELF element, return corresponding error code, if correct, then perform step 11;
Step 11, according to the length of the size decision element of minimum enclosed rectangle and width whether in range of tolerable variance, if, then terminate the location of MELF element and testing process and export the testing result of MELF element, centre coordinate and the anglec of rotation, if not, then terminate the testing process of MELF element, return corresponding error code.
Beneficial effect of the present invention is:
It is uneven that the inventive method solves the imaging surface gray scale collected when accepting forward illumination that the cylindrical shape characteristic due to MELF element causes, and is unfavorable for that successive image segmentation realizes the problem of element location.Edge image is obtained by Canny rim detection, edge image carries out not operation afterwards, in edge image afterwards after calculating not operation, non-zero pixels point is to the distance of nearest zero pixel, obtain the distance transformed image of the MELF part drawing picture after reducing and the distance transformed image of original MELF part drawing picture, utilize the distance transformed image of MELF element and adopt template matching method, obtaining the optimum matching template image of final exact matching and its best match position in original MELF image; The crucial marginal point of the correlation extraction of image border is utilized in the MELF edge image of band noise spot, represent that the overall profile of MELF element carries out the technical scheme of template matches with the minimum enclosed rectangle comprising all crucial marginal points, avoid element edge variable effect testing process, accuracy of detection is remained on about 97%; Adopt the template image of the template image of the anglec of rotation between [-30 °, 30 °] afterwards, detect the element to be matched with the anglec of rotation; Utilize gaussian pyramid computing method to original MELF part drawing picture and the anglec of rotation at [-30 °, 30 °] between the template image of template image carry out the compression of view data, template image image after obtaining the MELF part drawing picture after reducing and reducing, the number of searching position in template matches computation process and the calculated amount of each coupling can be reduced, there is the benefit improving template matches counting yield, compared with calculating with existing template matches, process is compared, and template matches calculated amount is reduced about 50% and will calculate minimizing about 60% consuming time;
The robustness of the inventive method is good, when template size changes, still can mate, and whether detects the match is successful, and the location of MELF element and the accuracy of detection are increased to 95-98%.
Embodiment
Embodiment one:
A kind of location of the MELF element based on template matches of present embodiment and detection method, as shown in Figure 1, described MELF element location is realized by following steps with detection method:
Step one, employing optical photographic system obtain the original MELF part drawing picture of MELF element;
Step 2, select fixed threshold to carry out Threshold segmentation to the original MELF part drawing picture that step one obtains, obtain the pretreated image of binaryzation, and calculate the number of non-zero pixels point in the pretreated image of binaryzation;
Whether the number of the non-zero pixels point that step 3, determining step two obtain reaches the corresponding multiple of original MELF element total number of image pixels, if not, then terminates MELF element testing process, returns corresponding error code; If so, continue to perform step 4;
Step 4, set up according to the length of MELF element of input and width information the template image that the anglec of rotation is 0 °, to the anglec of rotation be the template image of 0 ° with 1 degree for step-length rotates, obtain comprising all template images of the anglec of rotation between [-30 °, 30 °] that the anglec of rotation is the template image of 0 °;
Step 5, employing image gaussian pyramid computing method, original MELF part drawing picture step one obtained is contracted to 1/4th as the MELF part drawing picture after reducing, and the template image that step 4 obtains is contracted to 1/4th as the template image after reducing; Wherein, the template image after reducing comprises the anglec of rotation after reducing is the template image of 0 ° and the template image of the anglec of rotation between [-30 °, 30 °] after reducing; This Image Data Compression of carrying out original MELF part drawing picture and the angled template image of band, can reduce the number of searching position in step 7 template matches computation process and the calculated amount of each coupling, have the benefit improving template matches counting yield.
Step 6, respectively to step 5 obtain reduce after MELF part drawing picture and the original MELF part drawing picture that obtains of step one carry out Canny rim detection and obtain edge image, respectively not operation is carried out to the edge image obtained afterwards, to calculate in the edge image after not operation non-zero pixels point afterwards respectively to the distance of nearest zero pixel, as the distance transformed image of MELF part drawing picture after reducing and the distance transformed image of original MELF part drawing picture;
Step 7, search for image to be matched with the template image that step 4 obtains, the region that image to be matched is covered by template image, as subregion image, adopts template matches computing formula:
the pixel of antithetical phrase area image and the corresponding each point gray scale difference of template image square and the similarity of the subregion image that represents and template image and otherness carry out template matches calculating, acquisition optimum matching template and the best match position of optimum matching template in original MELF part drawing picture; Wherein, T (m, n) represents the gray-scale value of template image T at (m, n) place; s
(i, j)(m, n) represents and subregion image s
(i, j)the gray-scale value at (m, n) place of middle correspondence;
Step 8, Canny rim detection is adopted to obtain being with the MELF edge image of noise spot to the original MELF part drawing picture that step one obtains, the matching result of the optimum matching template utilizing step 7 to obtain and the best match position of optimum matching template in original MELF part drawing picture, correlativity according to image border point extracts crucial marginal point from the MELF edge image of band noise spot, to determine the overall profile of MELF element in original MELF image, complete the position fixing process of MELF element;
Step 9, all crucial marginal point utilizing step 8 to obtain form minimum enclosed rectangle, the position of MELF element in original MELF part drawing picture is represented with minimum enclosed rectangle, the centre coordinate of minimum enclosed rectangle represents that the centre coordinate of MELF element, the anglec of rotation of minimum enclosed rectangle represent the anglec of rotation of MELF element; When the centre coordinate of minimum enclosed rectangle and the anglec of rotation constant, form the rectangle after outwards increasing amount of bias after the length of minimum enclosed rectangle and width being amplified 1.1 times; Again when centre coordinate and the anglec of rotation of minimum enclosed rectangle, the rectangle inwardly increased after amount of bias will be formed after the length of minimum enclosed rectangle and reduced width 0.9 times;
Rectangle after step 10, the outside increase amount of bias that obtains according to step 9 or inwardly increase the number of non-zero pixels in the rectangle after amount of bias, whether correctly judge to detect the MELF position of components obtained, if incorrect, then terminate the testing process of MELF element, return corresponding error code, if correct, then perform step 11;
Step 11, according to the length of the size decision element of minimum enclosed rectangle and width whether in range of tolerable variance, if, then terminate the location of MELF element and testing process and export the testing result of MELF element, centre coordinate and the anglec of rotation, if not, then terminate the testing process of MELF element, return corresponding error code.
Embodiment two:
With embodiment one unlike, MELF element based on the template matches location of present embodiment and detection method, set up according to the length of the MELF element of input and width information the template image that the anglec of rotation is 0 ° described in step 4, to the anglec of rotation be the template image of 0 ° with 1 degree for step-length rotates, obtain the anglec of rotation at [-30 °, 30 °] between the process of all template images be
Step 4 one, obtain according to the length of input MELF element and width information the Template Information that the anglec of rotation is 0 °, set up the template image that the anglec of rotation is 0 °; Wherein, the length corresponding rotation angle of MELF element is the width of 0 ° of template image, and the width corresponding rotation angle of MELF element is the height of 0 ° of template image;
Step 4 two, to the anglec of rotation be the template image of 0 ° with 1 degree for step-length rotates, and by w'=h|sin θ |+w|cos θ |, h'=w|sin θ |+h|cos θ | calculate the anglec of rotation at [-30 °, 30 °] between Template Information, set up the template image of the anglec of rotation between [-30 °, 30 °]; Wherein, θ represents the anglec of rotation, and w, h represent that the anglec of rotation is width and the height of the template image of 0 ° respectively, and w', h' are width and the height of postrotational template image, for the template matches of step 7.
Embodiment three:
With embodiment one or two unlike the location of the MELF element based on template matches of, present embodiment and detection method, described in step 5, the concrete computation process of image gaussian pyramid computing method is,
Step May Day, the pyramid diagram picture that will obtain is established to comprise i+1 tomographic image, in pyramid diagram picture, each tomographic image is all obtained by same original MELF part drawing picture, the level of pyramid diagram picture adopts order numbering from the bottom to top, and level more hi-vision is less, the highest the i-th+1 layer highest level representing pyramid diagram picture, G
irepresent the pyramid diagram picture of level i; Then by G
iwith Gaussian kernel
Carry out convolutional calculation, then even number lines all in result of calculation and even column are removed, complete G
i+1sampling computation process;
Step 5 two, establish original image G
0represent original MELF part drawing picture or the template image of input, according to G described in step May Day
i+1sampling computation process, to input original image G
0carry out iterative computation, until the image obtained is original image G
01/4th, namely obtain the MELF part drawing picture after reducing or the template image after reducing.
Embodiment four:
With embodiment three unlike, MELF element based on the template matches location of present embodiment and detection method, subregion image in image to be matched described in step 7 and the matching between template image are by degree of correlation function R (i, j) measure, the computing formula of degree of correlation function R (i, j):
In formula, R (i, j) represent template image move to image s to be matched (
i , j) place time template image and the degree of correlation of subregion image.
Embodiment five:
With embodiment one, two or four unlike the location of the MELF element based on template matches of, present embodiment and detection method, the process that the similarity of antithetical phrase area image and template image described in step 7 and otherness carry out template matches calculating is,
Step July 1st, choose the anglec of rotation after reducing be 0 ° template image with reduce after the distance transformed image of MELF part drawing picture carry out template matches calculating, search obtains Minimum relevance weight R (i, j) value, and using the best match position of position corresponding for Minimum relevance weight R (i, j) value as first rough matching;
Step 7 two, the best match position of first rough matching that step to be obtained the July 1st are as the left upper apex of rectangle, intercept in the distance transformed image of the MELF part drawing picture after reducing one with reduce after the anglec of rotation be the rectangle of the template image formed objects of 0 °, corresponding amount of bias is expanded again, as the region of interest ROI of next step detected image respectively to surrounding;
Step 7 three, step 7 two obtain region of interest ROI in, by the anglec of rotation after all reducing at [-30 °, 30 °] between template image carry out template matches calculating, search obtains all matching template image sequences number of second time rough matching relevance degree correspondence in 0.9-1.1 Minimum relevance weight R (i, j) value doubly and the matched position of correspondence;
Step 7 four, Minimum relevance weight R (i in the Candidate Set that all matching template images step 7 three obtained are formed, j) template image that value is corresponding is as optimum matching template image, coordinate transform is used to obtain the position of matched position correspondence in the distance transformed image of original MELF part drawing picture of optimum matching template image, as the left upper apex of rectangle, intercept in the distance transformed image of original MELF part drawing picture one with the rectangle of best match sequence number corresponding original template image formed objects, corresponding amount of bias is expanded again respectively to surrounding, as the region of interest ROI of next step detected image,
The best match sequence number of the optimum matching template image that step the Seventh Five-Year Plan, employing step 7 four obtain, and the template image that each three sequence numbers in best match sequence front and back are corresponding, the region of interest ROI obtained with step 7 four and carry out template matches calculating, obtain the sequence number of optimum matching template image and the best match position of exact matching of exact matching, obtained the position that the best match position of exact matching is corresponding in original MELF part drawing picture by coordinate transform.
Embodiment six:
With embodiment five unlike, MELF element based on the template matches location of present embodiment and detection method, from the MELF edge image of band noise spot, crucial marginal point is extracted, to determine that the process of the overall profile of MELF element in original MELF image is described in step 8:
Step Aug. 1st, using the correspondence position of the best match position of exact matching in original MELF image as the left upper apex of rectangle, intercept in the distance transformed image of original MELF part drawing picture one with the rectangular image of the optimum matching template image formed objects of exact matching;
Step 8 two, the optimum matching template image of exact matching is done normalized, and the gray-scale value of the optimum matching template image of exact matching is transformed between [0,1]; The rectangular image that template image after normalization and step Aug. 1st intercept is carried out taking advantage of operation, finds and take advantage of the rear image maximum gradation value of operation;
Step 8 three, not operation is carried out to the optimum matching template image of exact matching, then calculate non-zero pixels to the distance of nearest zero pixel and as template distance transformed image;
Step 8 four, using the position corresponding in the MELF edge image of band noise spot of the best match position of exact matching as the left upper apex of rectangle, intercept in the MELF edge image of band noise spot one with the rectangular image of the optimum matching template image formed objects of exact matching, and normalized is adopted to it, gray-scale value is transformed between [0,1];
Rectangular image after step 8 five, the template distance transformed image calculated step 8 three and step 8 four normalization takes advantage of operation, with the image maximum gradation value obtained in step 8 two for threshold value carries out anti-thresholding process to taking advantage of the image after operation, carry out and operation with the rectangular image of non-normalized in step 8 four afterwards, be the crucial marginal point of element with the point set in image after operation.
Embodiment seven:
With embodiment one, two, four or six unlike, MELF element based on the template matches location of present embodiment and detection method, judge described in step 10 that the process whether correctly detecting the MELF position of components that obtains is, in the number of non-zero pixels in the rectangle after outwards increasing amount of bias and the rectangle after inwardly increasing amount of bias, have at least one to reach 0.9 times of the non-zero pixels point number that step 2 obtains, judge to detect the position of components obtained correct, otherwise it is incorrect to judge that detection obtains position of components.
Embodiment 1:
Based on MELF element location and the detection method of template matches, described MELF element location is realized by following steps with detection method:
Step one, employing optical photographic system obtain the original MELF part drawing picture of MELF element as shown in Figure 2;
Step 2, select fixed threshold to carry out Threshold segmentation to the original MELF part drawing picture that step one obtains, obtain the pretreated image of binaryzation, and calculate the number of non-zero pixels point in the pretreated image of binaryzation;
Whether the number of the non-zero pixels point that step 3, determining step two obtain reaches the corresponding multiple of original MELF element total number of image pixels, if not, then terminates MELF element testing process, returns corresponding error code; If so, continue to perform step 4;
Step 4, be the template image of 0 ° according to the length of MELF element of input and the width information anglec of rotation set up as shown in Figure 5, to the anglec of rotation be the template image of 0 ° with 1 degree for step-length rotates, obtain comprising all template images of the anglec of rotation between [-30 °, 30 °] that the anglec of rotation is the template image of 0 °;
Step 5, employing image gaussian pyramid computing method, original MELF part drawing picture step one obtained is contracted to 1/4th as the MELF part drawing picture after reducing, and the template image that step 4 obtains is contracted to 1/4th template images after reducing as shown in Figure 7; Wherein, the template image after reducing comprises the anglec of rotation after reducing is the template image of 0 ° and the template image of the anglec of rotation between [-30 °, 30 °] after reducing;
Step 6, respectively to step 5 obtain reduce after MELF part drawing picture and the original MELF part drawing picture that obtains of step one carry out the edge image that Canny rim detection obtains as shown in Figure 3, respectively not operation is carried out to the edge image obtained afterwards, to calculate in the edge image after not operation non-zero pixels point afterwards respectively to the distance of nearest zero pixel, as the distance transformed image of the MELF part drawing picture after reducing as shown in Figure 6, and the distance transformed image of original MELF part drawing picture as shown in Figure 4;
Step 7, search for image to be matched with the template image that step 4 obtains, the region that image to be matched is covered by template image, as subregion image, adopts template matches computing formula:
the pixel of antithetical phrase area image and the corresponding each point gray scale difference of template image square and the similarity of the subregion image that represents and template image and otherness carry out template matches calculating, acquisition optimum matching template and the best match position of optimum matching template in original MELF part drawing picture; Wherein, T (m, n) represents the gray-scale value of template image T at (m, n) place; s
(i, j)(m, n) represents and subregion image s
(i, j)the gray-scale value at (m, n) place of middle correspondence;
Step 7, choose the anglec of rotation after reducing be 0 ° template image with reduce after the distance transformed image of MELF part drawing picture carry out template matches calculating, search obtains Minimum relevance weight R (i, j) value, and by Minimum relevance weight R (i, j) position that value is corresponding as the best match position of first rough matching, as shown in Figure 8; Using the left upper apex of the best match position of first rough matching as rectangle, intercept in the distance transformed image of the MELF part drawing picture after reducing one with reduce after the anglec of rotation be the rectangle of the template image formed objects of 0 °, corresponding amount of bias is expanded again respectively to surrounding, as shown in Figure 9, as the region of interest ROI of next step detected image; In the region of interest ROI obtained, by the anglec of rotation after all reducing at [-30 °, 30 °] between template image carry out template matches calculating, search obtains second time rough matching relevance degree at 0.9-1.1 Minimum relevance weight R (i doubly, the matched position of j) corresponding in value all matching template image sequences number and correspondence, as shown in Figure 10; Using template image corresponding for Minimum relevance weight R (i, j) value in the Candidate Set of all matching template images formation of acquisition as optimum matching template image, as shown in figure 11; Coordinate transform is used to obtain the position of matched position correspondence in the distance transformed image of original MELF part drawing picture of optimum matching template image, as the left upper apex of rectangle, intercept in the distance transformed image of original MELF part drawing picture one with the rectangle of best match sequence number corresponding original template image formed objects, expand corresponding amount of bias respectively to surrounding again, obtain region of interest ROI as shown in figure 12; Adopt the best match sequence number of the optimum matching template image obtained, and the template image that each three sequence numbers in best match sequence front and back are corresponding, the region of interest ROI intercepted with the best match position of second time rough matching and carry out template matches calculating, obtain the sequence number of optimum matching template image (as shown in figure 13) and the best match position of exact matching of exact matching, the position that the best match position of exact matching is corresponding in original MELF part drawing picture is obtained, as shown in figure 14 by coordinate transform.
Step 8, Canny rim detection is adopted to obtain being with the MELF edge image of noise spot to the original MELF part drawing picture that step one obtains, the matching result of the optimum matching template utilizing step 7 to obtain and the best match position of optimum matching template in original MELF part drawing picture, correlativity according to image border point extracts crucial marginal point from the MELF edge image of band noise spot, to determine the overall profile of MELF element in original MELF image, as shown in figure 15;
Step 9, all crucial marginal point utilizing step 8 to obtain form minimum enclosed rectangle, the position of MELF element in original MELF part drawing picture is represented with minimum enclosed rectangle, the centre coordinate of minimum enclosed rectangle represents that the centre coordinate of MELF element, the anglec of rotation of minimum enclosed rectangle represent the anglec of rotation of MELF element; When the centre coordinate of minimum enclosed rectangle and the anglec of rotation constant, form the rectangle after outwards increasing amount of bias after the length of minimum enclosed rectangle and width being amplified 1.1 times; Again when centre coordinate and the anglec of rotation of minimum enclosed rectangle, the rectangle inwardly increased after amount of bias will be formed after the length of minimum enclosed rectangle and reduced width 0.9 times;
Rectangle after step 10, the outside increase amount of bias that obtains according to step 9 or inwardly increase the number of non-zero pixels in the rectangle after amount of bias, judges that it is correct for detecting the MELF position of components obtained, continues to perform step 11;
Step 11, the length judging the size decision element of minimum enclosed rectangle and width, in range of tolerable variance, terminate the location of MELF element and testing process and export the testing result of MELF element, centre coordinate and the anglec of rotation.