Rotate a Matrix by Finding an Axis
Show older comments
Hey, sorry to bother but I 'm having issues in a project. Long story short, I must find an axis on the 2D binary matrix (which is done by finding the maximum distance between two of the black points in the matrix) and then rotate said image to make it as straight as possible. I cannot use imrotate though I guess that part can be done with a rotation matrix and so, is pretty easy (still don't know how it works but I can look into that).
If anyone can help me at finding the axis please, it'd be most aprecciated. However, I do understand it is quite the unusual task.
Anyway, thank you and have yourself a jolly new year's eve.
Accepted Answer
More Answers (1)
Walter Roberson
on 31 Dec 2018
0 votes
find an axis on the 2D binary matrix (which is done by finding the maximum distance between two of the black points in the matrix) and then rotate said image to make it as straight as possible.
Those are not inherently compatible objectives.
Consider for example,
A
+
B+++++++++++++++++++++++++++++++++++++++++++++++++
Now the maximum distance between two of the black points is between A and B, so you would identify AB or BA as your axes. You would then rotate so that AB was the horizontal or vertical axes, which would require that the long line was at an angle. That disagrees with your requirement to "make it as straight as possible".
Once you have identified the angle of your axes, using atan2(dy, dx) then you can use makehgtform to construct a transform matrix, which you can then use to rotate your points. That will tell you the new location for the points... but the new locations are unlikely to be integral, so you need to figure out how you want to handle that to create a new image.
3 Comments
Pedro Sousa
on 2 Jan 2019
Pedro Sousa
on 2 Jan 2019
Walter Roberson
on 2 Jan 2019
Are you looking for connected distance or euclidean distance ?
Categories
Find more on Lengths and Angles in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!