Algorithm of Contour Detection Improvement (2)

To combine the objects, first, we should detect whether the intersection line is flat. As I have said, it may fail in some cases. But in many cases, it is enough. And it can reduce the running time. So there comes the question: how do we difine a flatness of a line?


To solve this question, I define a method to calculate the faltness of a line. We all know that the line in the computer is just combined by pixels in the screen. So every point in the line will be neighbour to another points. So, for every pont in  the line, I will check its neighbour points. If the neighbour points are level to this, then I treat it flat and assign 0 to this point. But if we have a point that is vertical to this, Then I treat it bad case and assign it 10. So, at last, every point has a mark. I will calculate the average point tosee if it is flat. There are some examples followed.


Algorithm of Contour Detection Improvement (2)_第1张图片


We can see the right two pictures are all flat lines and their mark is below than 1. But the left lines are not so good and their marks are more than one. So, this method can detect level line. And After we detect the line, we want to combine the right case.


At first, we must know that what case we want to do and what case we do not want. So see the picture.


Algorithm of Contour Detection Improvement (2)_第2张图片


What we want to do is combine such cases. We want to combine the case whose intersection line is level and boder is continus. See the picture above, the blue line is level and the green line is continus. This is the case we want to do. And rememner, we will only do the case whose two sides of boder lines are all level. If one side boder is continus and another is not, we will not get this because it may lead error.


So, another question comes. How could we say that the boder is continus? In this question, I use straight line to fit the boder line. We can see that there are two boder lines starting from the end point. So, we have two lines. And every line we have two k value(y = k * x). So, we can test the difference of k value and make a threshold. If we have a difference which is less than the k, we can combine them.


Ok, the algorithm is just like this. And I'm sure that we can improve it. Below is a result.


Algorithm of Contour Detection Improvement (2)_第3张图片


Algorithm of Contour Detection Improvement (2)_第4张图片


Thank you!


The code is here. http://download.csdn.net/detail/lcbwlx/6923377

你可能感兴趣的:(tmp)