📄 finalcanny.m
字号:
%SEGMENTATION STEP
%NON MAXIMAL SUPPRESSION AND HYSTERESIS
%Input - Gaussian smoothed image
% - Edge image
% - High threshold
% - Low threshold
%Output- Thinned image
function [imnew1]=finalcanny(imnew1,edge,high,low)
[m,n]=size(edge);
for i=1:m,
for j=1:n,
% adjascent pixel calculation
if edge(i,j)==0
if j>1
lt=imnew1(i,j-1);
else
lt=edge(i,j);
% lt=0;
end
if j<n
rt=imnew1(i,j+1);
else
rt=edge(i,j);
% rt=0;
end
elseif edge(i,j)==45
if i<m & j>1
lt=imnew1(i+1,j-1);
else
lt=edge(i,j);
% lt=0;
end
if i>1 &j<n
rt=imnew1(i-1,j+1);
else
rt=edge(i,j);
% rt=0;
end
elseif edge(i,j)==90
if i>1
lt=imnew1(i-1,j);
else
lt=edge(i,j);
% lt=0;
end
if i<m
rt=imnew1(i+1,j);
else
rt=edge(i,j);
% rt=0;
end
else
if i>1 & j>1
lt=imnew1(i-1,j-1);
else
lt=edge(i,j);
% lt=0;
end
if i<m & j<n
rt=imnew1(i+1,j+1);
else
rt=edge(i,j);
% rt=0;
end
end
%hysteresis calculation
if(imnew1(i,j) <= lt | imnew1(i,j) <= rt)
imnew1(i,j)=0;
else
% high =30;
% low =15 ;
high =high;
low =low ;
if imnew1(i,j) >= high
imnew1(i,j) = 255; % edge
elseif imnew1(i,j) < low
imnew1(i,j) = 0;
else
% magnitude is between high & low determine the 8 pixels
p1=0;p2=0;p3=0;p4=0;p5=0;p6=0;p7=0;p8=0;
if i>1 & j>1
p1=imnew1(i-1,j-1);
end
if i>1
p2=imnew1(i-1,j);
end
if i>1 & j<n
p3=imnew1(i-1,j+1);
end
if j>1
p4=imnew1(i,j-1);
end
if j<n
p5=imnew1(i,j+1);
end
if i<m & j>1
p6=imnew1(i+1,j-1);
end
if i<m
p7=imnew1(i+1,j);
end
if i<m & j<n
p8=imnew1(i+1,j+1);
end
if p1>high | p2>high | p3>high | p4>high | p5>high | p6>high | p7>high | p8>high
imnew1(i,j)=255;
else
imnew1(i,j)=0;
end
end
end
end
end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -