how to fix damaged lines in a binary image?

1 view (last 30 days)
bill
bill on 11 Oct 2012
My binary image has 4 objects that they should be horizontal lines in the original image. I detected the boundaries of the objects (damaged lines) with bwboundaries and the middle point of the objects with regionprops so i could find the thickness of the original lines but i don't know how to proceed. Was a bad idea to find the center points of the lines with regionprops? is there a better way?
Here you can see the binary image: http://imageshack.us/a/img825/1173/45157442.png
By "fixing" the lines i mean i need to restore them. They should be horizontal in the original image.
  3 Comments
Matt J
Matt J on 12 Oct 2012
What was your idea for 'restoring' them? How does finding the center point and thickness lead you to a way to straighten the lines? Do you just want to erase the bent ones from the image and redraw them straight? If so, how would you choose the position and length of the restored line?
bill
bill on 18 Oct 2012
Sorry for not responding all these days. By finding the center point i know the distance between the left and right end of the line. That means that i will know the length of the line that i have to fix. So i have to redraw a straighten line between this distance (like you said). In order to find the thickness of the line i thought that by finding the center point i will also know the up and bottom end of the line which is a wrong hypothesis as i can see from the result because the center point is in the middle of the object and not in the middle of the "white area" in this point. So the question must be: how to find the thickness of these lines in order to straighten them.
This is how i think it should look like: http://imageshack.us/a/img213/3861/64904614.png

Sign in to comment.

Answers (2)

Image Analyst
Image Analyst on 11 Oct 2012
Edited: Image Analyst on 11 Oct 2012
What do you mean by "fix the damaged lines"? Do you mean to extend them to connect gaps? If so, look up edge linking: http://www.csse.uwa.edu.au/~pk/Research/MatlabFns/#edgelink Otherwise you can try a morphological closing with imclose().
When you say "supposed to be lines" do you mean that you want the blobs to be a single pixel wide, instead of many pixels wide? If so, use
skeletonImage = bwmorph(binaryImage, 'skel', inf);
Please clarify the ambiguous/unclear wording.

Matt J
Matt J on 11 Oct 2012
Edited: Matt J on 11 Oct 2012
I don't see how finding the center point helps you get the thickness of the lines.
Depending on how exact you need to be, it looks like the thicknesses could be obtained pretty closely by
R=regionprops(...,'Perimeter','Area')
thickness(i) = R(i).Area/(R(i).Perimeter/2); %thickness of i-th line

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!