Drawing a line down the middle of an object?

7 views (last 30 days)
Alex Mason
Alex Mason on 18 Aug 2011
I have this image:
ignore the little specks, I have already got a method of removing them and leaving just the big block of white.
Is it possible to then trace a rough line down the middle of that object? and then replace that object with the line? It doesnt have to follow any kind of curvature, just a THIN straight line roughly following the angle and length. Also it could be helpful if the line was assigned a random colour.
I know regionprops will get me the centroid and there is an orientation property which seems to be the angle, but I cant be sure. Region props gave about 77 for orientation which looks about right. Is extent going to be the right thing to use with regionprops?

Answers (1)

BF83
BF83 on 18 Aug 2011
Hi,
you could first calculate the centroid of your white object and then use princomp to get the object's eigenvector related to the greatest eigenvalue. This vector along with the centroid should allow you to plot your line.

Community Treasure Hunt

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

Start Hunting!