How to find angle for a curve in an image??

7 views (last 30 days)
I want to find angle alpha that is showed in image name angle.png. This figure show the angle between the extruded part and base. I want to calculate angle for all extruded part with base boundary in an image which attached with this question (Original_image.jpg).

Answers (1)

Bjorn Gustavsson
Bjorn Gustavsson on 17 Oct 2022
Since it is a bit unclear exactly how you're going about to select which points belong where you'll get a very general answer. Create a function angle_arrays.m:
function angle = angle_arrays(a,b)
% ANGLE_ARRAYS - angle between arrays
%
% Calling:
% angle = angle_arrays(a,b)
%
% copied from one major comp-sys-matlab-newsletter contributor.
angle = atan2(norm(cross(a,b)),dot(a,b));
Then you should be able to use ginput to manually select points at the base of the branching-point and at each arm, starting at the base:
[x3,y3] = ginput(3);
% then calculate the angle:
angle = angle_arrays([diff(x3(1:2)),diff(y3(1:2)),0],[diff(x3([1 3])),diff(y3([1 3])),0]);
Then you can put that snippet into a loop and save away the coordinates and angles as you see fit.
HTH
  2 Comments
Surendra Ratnu
Surendra Ratnu on 17 Oct 2022
Thanks for your answer. I applied this function but i could not get desire result. and i have 100 images so it's hard to manually select points on the boundary. Can you give some suggestion regarding this. I attched a image and mat file of boundary in which i showed enlarge view of some extruded part. Green points on the red boundary are the exact point where i want to measure the angle.
Bjorn Gustavsson
Bjorn Gustavsson on 17 Oct 2022
For that case you might be able to make linear fits to the coordinates of the identified red points "before" and "after" your green points. For that I'd use polyfit and then calculate the tangent-vectors for those 2 line-fits and then calculate the angle between those two using the above technique.

Sign in to comment.

Products


Release

R2022b

Community Treasure Hunt

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

Start Hunting!