Rotate a Matrix by Finding an Axis
이전 댓글 표시
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.
채택된 답변
추가 답변 (1개)
Walter Roberson
2018년 12월 31일
0 개 추천
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
Pedro Sousa
2019년 1월 2일
Pedro Sousa
2019년 1월 2일
Walter Roberson
2019년 1월 2일
Are you looking for connected distance or euclidean distance ?
카테고리
도움말 센터 및 File Exchange에서 Image Arithmetic에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
