-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathline_detect_horizontal.m
46 lines (42 loc) · 1.04 KB
/
line_detect_horizontal.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
function [ new ] =line_detect_horizontal( old_image , filter)
%filter = [0 0 1 ; 0 0 0 ; -1 0 0];
filter=double(filter);
p=1;
old_image = double(padarray(old_image,[p,p]));
[h w l] =size(old_image);
result = zeros(h,w,l);
new = zeros(h,w,l);
if l==1
for i=2:h-1
for j=2:w-1
s= old_image(i-1:i+1,j-1:j+1);
sum1=sum(sum(s.*filter));
result(i,j)=sum1;
if result(i,j)>255
result(i,j)=255;
elseif result(i,j)<0
result(i,j)=0;
end
end
end
else
for k=1:3
for i=2:h-1
for j=2:w-1
s= old_image(i-1:i+1,j-1:j+1,k);
sum1=sum(sum(s.*filter));
result(i,j,k)=sum1;
if result(i,j,k)>255
result(i,j,k)=255;
elseif result(i,j,k)<0
result(i,j,k)=0;
end
end
end
end
end
result = uint8(result);
old_image=uint8(old_image);
new=result+old_image;
%imshow(new);
end