Summary of the invention
To the defective that exists in the prior art, technical matters to be solved by this invention provides a kind of fine rule detection method and system that the fine rule topological structure influences and efficient is high that do not receive.
For solving the problems of the technologies described above, the technical scheme that the present invention adopts is following:
Fine rule detection method in a kind of image may further comprise the steps:
(1) image is carried out rim detection, write down detected edge;
(2) generate the Edge Distance graph of a relation; Said Edge Distance graph of a relation is used for representing distance and the direction of each pixel of said image to edge nearest with it;
(3) according to the fine rule breadth extreme threshold value N that sets
MaxIn said Edge Distance graph of a relation, extract fine rule.
Aforesaid fine rule detection method, edge described in the step (1) adopts the Coordinate Chain table record at pixel edge in centre joint coordinate chained list or the image; Wherein, said centre joint coordinate chained list is the chained list that the coordinate in all relative pixel centre positions of both sides of edges connects in regular turn.
Aforesaid fine rule detection method, in the Edge Distance graph of a relation, the distance that will arrive its nearest edge is greater than N described in the step (2)
MaxThe distance relation value of/2 pixel is set to invalid value.
Aforesaid fine rule detection method, described in the step (2) in the Edge Distance graph of a relation, for closed edge not, the initial direction both sides opposite in sign along the edge; For closed edge, be positioned at the opposite in sign in the closed edge inboard and the outside.
Aforesaid fine rule detection method, the generative process of Edge Distance graph of a relation is following described in the step (2):
At first initialization Edge Distance graph of a relation all is arranged to invalid value with each represented in Edge Distance graph of a relation pixel to the distance at edge nearest with it;
Scan the centre joint coordinate chained list at each bar edge then; In the computed image with the ultimate range of current coordinate at N
MaxPixel in/2 scopes is to the distance of current coordinate, and the distance modification of the point that this pixel is corresponding is the distance to current coordinate among the distance relation figure on the edge of, and confirms the direction of this point; If this pixel on the edge of among the distance relation figure corresponding point be modified distance, the size of current distance and former distance relatively then is if current distance less than former distance, is then replaced former distance with current distance.
Aforesaid fine rule detection method, the process of extracting fine rule described in the step (3) is following:
(a) locate fine line region on the edge of among the distance relation figure: with in the Edge Distance graph of a relation near invalid value one side and with the distance at edge at N
MaxThe distance of the point in/2 scopes is made as invalid value;
(b) with in the image with the Edge Distance graph of a relation in the corresponding pixel of point in the fine line region merge.
Aforesaid fine rule detection method, after obtaining fine rule, said method also comprises the step of removing the undesirable fine rule of length breadth ratio, the breadth extreme of the length/fine rule of said length breadth ratio=fine rule.
Said methods of length calculation is: the breadth extreme of the area/fine rule of fine rule.
Wherein, the area of fine rule is the pixel number that fine line region comprised; The breadth extreme of said fine rule is peaked 2 times of this fine line region middle distance in the Edge Distance graph of a relation.
Fine rule detection system in a kind of image comprises being used for image is carried out rim detection, writes down the pick-up unit at detected edge;
Be used to generate the generating apparatus of Edge Distance graph of a relation; Said Edge Distance graph of a relation is used for representing distance and the direction of each pixel of said image to edge nearest with it;
Be used for according to the fine rule breadth extreme threshold value N that sets
MaxIn said Edge Distance graph of a relation, extract the extraction element of fine rule.
Aforesaid fine rule detection system, wherein, extraction element comprises the positioning unit that is used for the location of distance relation figure on the edge of fine line region; Be used for the merge cells that the pixel that the point in the fine line region in image and the Edge Distance graph of a relation is corresponding merges.
Aforesaid fine rule detection system also comprises the removal device that is used for after obtaining fine rule, removing the undesirable fine rule of length breadth ratio.
The method of the invention and system; Through generating the Edge Distance graph of a relation; Detect the mode that satisfies the fine rule of setting breadth extreme on the edge of among the distance relation figure; Can detect in the image all less than the fine rule of setting breadth extreme, not receive the influence of fine rule topological structure, can the detection width gradual change etc. the fine rule of special shape.Simultaneously, compared with prior art, when having avoided template big, the problem that operation efficiency is low.
Embodiment
Describe the present invention below in conjunction with embodiment and accompanying drawing.
Fig. 1 shows in this embodiment fine rule detection system structure in the image.As shown in Figure 1, this system comprises pick-up unit 11, the generating apparatus 12 that is connected with pick-up unit 11, the extraction element 13 that is connected with generating apparatus 12, and the removal device 14 that is connected with extraction element 13.Wherein, extraction element 13 comprises positioning unit 131 and merge cells 132.
Pick-up unit 11 is used for image is carried out rim detection, and writes down detected edge.
Generating apparatus 12 is used to generate the Edge Distance graph of a relation; Said Edge Distance graph of a relation is used for representing distance and the direction of each pixel of said image to edge nearest with it.
Extraction element 13 is used for according to the fine rule breadth extreme threshold value N that sets
MaxIn said Edge Distance graph of a relation, extract fine rule.Positioning unit 131 is used on the edge of, and distance relation figure locatees fine line region.Merge cells 132 is used for the pixel that the point in the fine line region in image and the Edge Distance graph of a relation is corresponding and merges.
Removal device 14 is used for after obtaining fine rule, removing the undesirable fine rule of length breadth ratio.
Fig. 2 shows the method flow that adopts the fine rule in the system shown in Figure 1 detected image.As shown in Figure 2, this method may further comprise the steps:
(1) 11 pairs of images of pick-up unit carry out rim detection, and write down detected edge.
Edge detection method can adopt existing method, like the Canny operator.
In this embodiment, detected edge is adopted centre joint Coordinate Chain table record.With the upper left angle point of image is that true origin is set up rectangular coordinate system, and level is to the right an x axle positive dirction, is y axle positive dirction straight down.The coordinate of each pixel in this coordinate system is given a definition image, and the intermediate position coordinates of two neighbor pixels, i.e. centre joint coordinate.The coordinate in all relative pixel centre positions of both sides of edges is connected into chained list in regular turn, write down the edge with this chained list.As shown in Figure 3, for edge 31, connect into chained list according to the order of sequence with the coordinate in relative pixel centre position, 31 both sides, edge, write down this edge 31.
Can also adopt other mode records to detected edge, like Coordinate Chain table record with pixel edge in the image.
(2) generating apparatus 12 generates the Edge Distance graph of a relation.
The size of Edge Distance graph of a relation is identical with the image size; Each point in the Edge Distance graph of a relation is corresponding one by one with each pixel in the image, and the pixel that each point is used for writing down the image corresponding with this point arrives minor increment and the direction with this nearest edge of pixel.Said direction is meant that pixel is positioned at the position at edge, distinguishes with sign in distance relation figure.For closed edge not, the initial direction both sides opposite in sign along the edge; For closed edge, be positioned at the opposite in sign in the closed edge inboard and the outside.Certainly, the direction of pixel can adopt other methods to set up, as long as can distinguish and the position at edge relation.
The concrete generative process of Edge Distance graph of a relation is following:
At first initialization Edge Distance graph of a relation all is arranged to invalid value with the distance of every bit, as 0,255 etc.
Scan the centre joint coordinate chained list at each bar edge then, in the computed image with the ultimate range of current coordinate at N
MaxPixel in/2 scopes is to the distance of current coordinate, and the distance modification of the point that this pixel is corresponding is the distance to current coordinate among the distance relation figure on the edge of, and confirms the direction of this point.If this pixel on the edge of among the distance relation figure corresponding point be modified distance (being non-initial invalid value), the size of current distance and former distance relatively then is if current distance less than former distance, is then replaced former distance with current distance.
In this embodiment, N
MaxGet 6, promptly the width of fine rule is no more than 6 pixel width.Shown in Fig. 4 A, at first scan the centre joint coordinate chained list at edge 41, obtain first centre joint coordinate, as current coordinate.In the computed image with the pixel of ultimate range in 3 pixel width ranges of current coordinate distance to current coordinate; Promptly calculate with current coordinate be pixel in 3 * 3 territories at center to the distance of current coordinate, be the distance of this pixel coordinate and current coordinate with the distance modification of point corresponding in the Edge Distance graph of a relation with this pixel.If this pixel is 41 left sides on the edge of, then distance is a negative value; If 41 right side on the edge of, then distance be on the occasion of.Continue scanning centre joint coordinate chained list, obtain second centre joint coordinate,, repeat said process, up to the centre joint coordinate chained list that has scanned edge 41 as current coordinate.Handle next bar edge again,, generate final Edge Distance graph of a relation up to handling all edges.
Shown in Fig. 4 B, when handling edge 42, for the pixel of the 7th row, its distance with respect to edge 42 (being current distance) is 2.Since this pixel on the edge of among the distance relation figure distance of corresponding point be modified (being non-invalid value), therefore relatively current distance and this are put the size of former distance.If current distance is put former distance less than this, then with this former distance of current distance replacement.This situation explanation edge 2 is the nearest edges of this row pixel.Because this row pixel is positioned at the left side at edge 42, therefore on the edge of among the distance relation figure direction of corresponding point for negative.
As shown in Figure 5, for closed edge, be provided with the inner pixel in edge to the range direction at edge for just, the outside, edge is for just.
Shown in Fig. 6 A and 6B, at N
MaxThe pixel in/2 scopes and the distance of edge angle point have following two kinds of computing method:
A kind of method is the corner method.Shown in Fig. 6 A, at N
MaxIn/2 scopes, the oblique line of pixel and angle point distance is equal to level or vertical distance.
Another kind method is the fillet method.Shown in Fig. 6 B, at N
MaxIn/2 scopes, with the oblique line of pixel and angle point apart from distance as this pixel.Computing formula is:
Wherein, x
1And y
1Be respectively the horizontal ordinate of pixel, x
2And y
2Be respectively the horizontal ordinate of angle point.
(3) extraction element 13 is according to the fine rule breadth extreme threshold value N that sets
MaxIn said Edge Distance graph of a relation, extract fine rule.Specifically comprise the steps:
(a) positioning unit 131 location fine line region.
On the edge of among the distance relation figure, erode near invalid value one side and with the distance on border at N
MaxThe distance of the point in/2 scopes, be about near invalid value one side and with the distance on border at N
MaxThe distance of the point in/2 scopes is made as invalid value.Remaining zone is a fine line region.Because fine line region can only appear between two edges and closed edge that do not seal, thus with the frontier distance of invalid value and Edge Distance graph of a relation at N
MaxPoint in/2 scopes can not be fine line region.In closed edge,, do not belong to fine line region equally if invalid value explains that then the width of closed edge does not satisfy the maximum fine rule width range of setting.
Edge Distance graph of a relation shown in Fig. 7 A (invalid value is 0), the effect after excessive erosion is shown in Fig. 7 B.The Edge Distance graph of a relation that comprises closed edge shown in Figure 5, the effect after excessive erosion is as shown in Figure 8, because there is not effective value in closed edge inside, the zone of therefore this closed edge being described and being surrounded does not belong to fine line region.
(b) merge cells 132 with in the image with the Edge Distance graph of a relation in the corresponding pixel of point in the fine line region merge.
After confirming fine line region, need different fine rules be distinguished.Can the point in the fine line region be carried out identical label, utilize label to realize distinguishing mutually with other fine rules.As shown in Figure 9 to the effect after the Edge Distance graph of a relation after the excessive erosion carries out label shown in Fig. 7 B, label is that 1 point corresponding pixel in image is the pixel in the fine line region.
After obtaining fine rule, removal device 14 is removed the undesirable fine rule of length breadth ratio.The breadth extreme of the length/fine rule of said length breadth ratio=fine rule.Said methods of length calculation is: the breadth extreme of the area/fine rule of the length=fine rule of fine rule; The area of fine rule can confirm that the breadth extreme of fine rule is peaked 2 times of this fine line region middle distance in the Edge Distance graph of a relation through the pixel number that fine line region comprised.If the value of length breadth ratio, explains then that this fine rule width is bigger less than pre-set threshold, do not think that it is a fine rule.
Obviously, those skilled in the art can carry out various changes and modification to the present invention and not break away from the spirit and scope of the present invention.Like this, belong within the scope of claim of the present invention and equivalent technology thereof if of the present invention these are revised with modification, then the present invention also is intended to comprise these changes and modification interior.