-
Notifications
You must be signed in to change notification settings - Fork 0
/
nms.m
75 lines (66 loc) · 2.21 KB
/
nms.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
function y=nms(im,theta)
[m,n]=size(theta);
y=zeros(m,n);
im=padarray(im,[1 1],'symmetric');
t=round(theta/(pi/4));
for i=2:m+1
for j=2:n+1
if((t(i-1,j-1)==2)||(t(i-1,j-1)==-2))
if(im(i,j)~=max(im(i,j),max(im(i,j-1),im(i,j+1))))
y(i-1,j-1)=0;
else
y(i-1,j-1)=im(i,j);
end
end
if(t(i-1,j-1)==-1)
if(((i~=2)&&(i~=m+1)&&(j~=2)&&(j~=n+1))||(((i==2)&&(j==2))||((i==m+1)&&(j==n+1)))||((i==m+1)&&(j==2))||((i==2)&&(j==n+1)))
if(im(i,j)~=max(im(i,j),max(im(i-1,j+1),im(i+1,j-1))))
y(i-1,j-1)=0;
else
y(i-1,j-1)=im(i,j);
end
elseif((i==m+1)||(j==2))
if(im(i,j)~=max(im(i,j),im(i-1,j+1)))
y(i-1,j-1)=0;
else
y(i-1,j-1)=im(i,j);
end
else
if(im(i,j)~=max(im(i,j),im(i+1,j-1)))
y(i-1,j-1)=0;
else
y(i-1,j-1)=im(i,j);
end
end
end
if(t(i-1,j-1)==1)
if(((i~=2)&&(i~=m+1)&&(j~=2)&&(j~=n+1))||(((i==2)&&(j==2))||((i==m+1)&&(j==n+1)))||((i==m+1)&&(j==2))||((i==2)&&(j==n+1)))
if(im(i,j)~=max(im(i,j),max(im(i-1,j-1),im(i+1,j+1))))
y(i-1,j-1)=0;
else
y(i-1,j-1)=im(i,j);
end
elseif((i==2)||(j==2))
if(im(i,j)~=max(im(i,j),im(i+1,j+1)))
y(i-1,j-1)=0;
else
y(i-1,j-1)=im(i,j);
end
else
if(im(i,j)~=max(im(i,j),im(i-1,j-1)))
y(i-1,j-1)=0;
else
y(i-1,j-1)=im(i,j);
end
end
end
if(t(i-1,j-1)==0)
if(im(i,j)~=max(im(i,j),max(im(i+1,j),im(i-1,j))))
y(i-1,j-1)=0;
else
y(i-1,j-1)=im(i,j);
end
end
end
end
end