forked from javimazzaf/choroidSegmentation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunc_LinePoints.m
executable file
·114 lines (111 loc) · 3.02 KB
/
func_LinePoints.m
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
function [X,Y] = func_LinePoints(X0, Y0, X1, Y1,cols)
% Connect two pixels in an image with the desired graylevel
%
% Command line
% ------------
% result = func_DrawLine(Img, X1, Y1, X2, Y2)
% input: Img : the original image.
% (X1, Y1), (X2, Y2) : points to connect.
% nG : the gray level of the line.
% output: result
%
% Note
% ----
% Img can be anything
% (X1, Y1), (X2, Y2) should be NOT be OUT of the Img
%
% The computation cost of this program is around half as Cubas's [1]
% [1] As for Cubas's code, please refer
% http://www.mathworks.com/matlabcentral/fileexchange/loadFile.do?obiectId=4177
%
% Example
% -------
% result = func_DrawLine(zeros(5, 10), 2, 1, 5, 10, 1)
% result =
% 0 0 0 0 0 0 0 0 0 0
% 1 1 1 0 0 0 0 0 0 0
% 0 0 0 1 1 1 0 0 0 0
% 0 0 0 0 0 0 1 1 1 0
% 0 0 0 0 0 0 0 0 0 1
%
%
% iing Tian Oct. 31 2000
% scuteeitian@hotmail.com
% This program is written in Oct.2000 during my postgraduate in
% GuangZhou, P. R. China.
% Version 1.0
X=nan(1,300);
Y=nan(1,300);
i=1;
if abs(X1 - X0) <= abs(Y1 - Y0)
if Y1 < Y0
k = X1; X1 = X0; X0 = k;
k = Y1; Y1 = Y0; Y0 = k;
end
X(1)=X0;
Y(1)=Y0;
if (X1 >= X0) & (Y1 >= Y0)
dy = Y1-Y0; dx = X1-X0;
p = 2*dx; n = 2*dy - 2*dx; tn = dy;
while (Y(i) < Y1)
if tn >= 0
tn = tn - p;
X(i+1) = X(i);
else
tn = tn + n; X(i+1) = X(i) + 1;
end
Y(i+1) = Y(i) + 1;
i=i+1;
end
else
dy = Y1 - Y0; dx = X1 - X0;
p = -2*dx; n = 2*dy + 2*dx; tn = dy;
while (Y(i) <= Y1)
if tn >= 0
tn = tn - p;
X(i+1) = X(i);
else
tn = tn + n; X(i+1) = X(i) - 1;
end
Y(i+1) = Y(i) + 1;
i=i+1;
end
end
else
if X1 < X0
k = X1; X1 = X0; X0 = k;
k = Y1; Y1 = Y0; Y0 = k;
end
X(1)=X0;
Y(1)=Y0;
if (X1 >= X0) & (Y1 >= Y0)
dy = Y1 - Y0; dx = X1 - X0;
p = 2*dy; n = 2*dx-2*dy; tn = dx;
while (X(i) < X1)
if tn >= 0
tn = tn - p;
Y(i+1) = Y(i);
else
tn = tn + n; Y(i+1) = Y(i) + 1;
end
X(i+1) = X(i) + 1;
i=i+1;
end
else
dy = Y1 - Y0; dx = X1 - X0;
p = -2*dy; n = 2*dy + 2*dx; tn = dx;
while (X(i) < X1)
if tn >= 0
tn = tn - p;
Y(i+1) = Y(i);
else
tn = tn + n; Y(i+1) = Y(i) - 1;
end
X(i+1) = X(i) + 1;
i=i+1;
end
end
end
Y=Y(Y>0 & Y<cols+1);
X=X(Y>0 & Y<cols+1);
b=1;