Reputation: 57
As you can see in image, I have image that contain many lines. how can I get the longest line using matlab, then remove the other lines?
Upvotes: 1
Views: 3689
Reputation: 3547
First, as mentioned by Lokesh A. R., the line you are wanting in your image is not the longest since it is not continuous.
If you really do want that line to be found, then take a look at dilation, which will expand the lines, cause small breaks in the line to connect, then reduce the line back to its same thickness. However, this risks connecting lines that you don't want to connect, and is probably not reliable unless the lines in the image are far enough apart.
If you really do want just the longest line, then I would suggest an algorithm (that you would have to code)
This is a basic algorithm for detecting objects in an image and it may be possible that matlab can do this step. Take a look at mathworks page on object detection and see if it can "detect" the lines in your image and give you stats about them (like the number of pixels in each)
Upvotes: 2
Reputation: 2106
Here, read this: http://www.mathworks.com/help/images/ref/houghlines.html
Should basically answer your question. HoughLines is one of the more common method for detecting lines.
Upvotes: 0