forked from nepacheco/Continuum-Image-Analyzer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAnalyzeNotch.m
More file actions
66 lines (60 loc) · 2.24 KB
/
AnalyzeNotch.m
File metadata and controls
66 lines (60 loc) · 2.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
function theta = AnalayzeNotch(notchImage,varargin)
%ANALAYZENOTCH Has the user select 4 points to determine the angle the two
%cut sections are in relation to one another.
%
% 'Axis' - Optional Argument which is the axis to display the image one
% 'Style' - Name-Argument {'line','points'} which denotes if you want to
% analyze a notch using lines or points.
%****** INPUT PARSING *********************
% default values
style = 'line';
styleOptions = {'line','points'};
p = inputParser();
addRequired(p,'Image');
addOptional(p,'axis',0);
addParameter(p,'Style',@(x) any(validatestring(x,styleOptions)));
parse(p,path,varargin{:});
ax = p.Results.axis;
if ax == 0
ax = gca;
end
style = p.Results.Style;
%*********************************************
theta = 0;
line_vec = zeros(2,2);
I = imshow(notchImage,'Parent',ax);
title("Select the points to measure the notch");
for i = 1:2
while(1)
switch style
case 'line'
title(sprintf("Draw line %d",i));
line = drawline('Color','magenta','Parent',ax,'LineWidth',0.5);
pos = line.Position;
case 'points'
title(sprintf("Select Points for line %d",i));
point1 = drawpoint('Color','magenta','Parent',ax,'MarkerSize',3);
point2 = drawpoint('Color','red','Parent',ax,'MarkerSize',3);
pos = [point1.Position(1) point1.Position(2);
point2.Position(1) point2.Position(2)];
line = drawline('Position',pos,'Color','magenta','LineWidth',1.5);
delete(point1); delete(point2);
end
line_vec(:,i) = [(pos(2,1) - pos(1,1));(pos(1,2) - pos(2,2))];
line_vec(:,i) = line_vec(:,i)./norm(line_vec(:,i));
choice = listdlg('PromptString',{'Are you happy with your line'},...
'ListString',{'Yes','No'});
if choice==1
break;
end
delete(line)
end
end
pause(0.1);
% Measures angular displacement in the clockwise direction
angle1 = atan2d(line_vec(2,1),line_vec(1,1));
angle2 = atan2d(line_vec(2,2),line_vec(1,2));
theta = mod(-(angle2 - angle1),360);
% value between 0 and 180
% theta = acos(dot(line_vec(:,1),line_vec(:,2))/(norm(line_vec(:,1))*norm(line_vec(:,2))););
end