function [Iout]=ut_edge(varargin)
%ut_edge Marr-Hilderth and Canny edge detectors
%
% Iout = UT_EDGE(Iin) finds the possible edges in image Iin using an
% implementation of the Canny edge detector. The derivatives are
% calculated from a 2-D Gaussian function implemented with UT_GAUSS.
% The localization is done by finding the zero-crossings of the second
% directional derivatives (instead of directional maximum suppression
% such as implemented by EDGE from the image processing toolbox). The
% sigma (standard deviation) of the Gaussian filtering is set to 2.
% Iout is a 2-dimensional array with the same size as Iin. The no-edge
% pixels are indicated in Iout as zeroes. Edge pixels carries the edge
% strength as grey level. The edge strength is scaled between 0 and 1.
%
% Iout = UT_EDGE(Iin,...,OPTION,OPTIONVAL,...) finds the possible edges
% with some options switched on, and with parameter(s) set to OPTIONVAL.
% The following options are available:
%
% 'marrhildreth' or 'm': Perform Marr-Hildreth operation, i.e. Laplacian
% of Gaussian, rather than Canny operation.
% 'canny' or 'c': Perform Canny operation (default).
% 'sigma' or 's': The width (standard deviation) of the Gaussian
% filtering is set to OPTIONVAL (default: 2)
% 'threshold' or 't': Return a binary (logical) edge map instead of edge
% strengths. The edges are detected by
% thresholding it at OPTIONVAL. If OPTIONVAL is
% omitted, the default of the threshold is 0.1.
% 'hysteresis' or 'h': Return a binary (logical) edge map instead of edge
% strengths. The edge are detected by hysteresis
% thresholding. Two thresholds are applied. The
% edges detected with the higher thresholds form
% the seed that is propagated in the edge
% segments obtained by thresholding with the
% lower threshold. OPTIONVAL is a two-element
% vector. The first element specifies the
% fraction of pixels that will be assigned to
% candidate edges (detected with the lower
% threshold). The second element is the fraction
% of pixels that will be assigned to seed edges
% (detected with the higher threshold). If
% OPTIONVAL is omitted, the default of [0.1 0.03]
% is assumed. If OPTIONVAL is a scalar, then the
% default assignment to the second element is
% 0.3*OPTIONVAL.
%
% Copyright: F. van der Heijden, F.vanderHeijden@utwente.nl
% Laboratory for Measurements and Instrumentation
% University of Twente, the Netherlands
% Version 1.3, date: 21-02-2018
%
% See also UT_GAUSS, EDGE.
[Iin,sigma,operator,threshold_method,thres_parm]=ParseInputs(varargin{:});
grad=(ut_gauss(Iin,sigma,1,0).^2+ut_gauss(Iin,sigma,0,1).^2).^0.5;
grad=grad/max(grad(:));
if strcmp(operator,'marrhildreth')
lap=ut_gauss(Iin,sigma,2,0)+ut_gauss(Iin,sigma,0,2);
zerocross=ut_levelx(lap,0.0);
Iout=grad.*zerocross;
end
if strcmp(operator,'canny')
SDGD=ut_gauss(Iin,sigma,1,0).^2.*ut_gauss(Iin,sigma,2,0)+ ...
2*ut_gauss(Iin,sigma,1,0).*ut_gauss(Iin,sigma,0,1).*ut_gauss(Iin,sigma,1,1)+...
ut_gauss(Iin,sigma,0,1).^2.*ut_gauss(Iin,sigma,0,2);
zerocross=ut_levelx(SDGD,0.0);
Iout=grad.*zerocross;
end
if strcmp(threshold_method,'threshold')
Iout = logical(Iout>thres_parm(1));
end
if strcmp(threshold_method,'hysteresis')
Iout_sorted = sort(Iout(:));
thres_parm(1) = Iout_sorted(max(floor((1-thres_parm(1))*numel(Iout)),1));
thres_parm(2) = Iout_sorted(max(floor((1-thres_parm(2))*numel(Iout)),1));
Iout_mask = Iout>thres_parm(1);
Iout_marker = Iout>thres_parm(2);
Iout=imreconstruct(Iout_marker,Iout_mask);
end
%----------------------------------------------------------------------
% Subfunction ParseInputs
%----------------------------------------------------------------------
function [Iin,Sigma,operator,threshold_method,thres_parm] = ParseInputs(varargin)
narginchk(1,30);
Iin = double(varargin{1});
if ndims(Iin)~=2
error('Iin must be a 2-dimensional array');
end
%defaults
Sigma=2;
operator = 'canny';
threshold_method = 'none';
thres_parm = [0.1, 0.03];
options = {'canny','c','marrhildreth','m','threshold','t','hysteresis','h','sigma','s'};
if nargin>1
for k=2:length(varargin)
if ischar(varargin{k})
string = lower(varargin{k});
j = strmatch(string,options,'exact');
if isempty(j)
error(['Invalid input string: ''' varargin{k} '''.']);
end
switch string
case {'canny','c','marrhildreth','m'}
if strcmp(string,'m'), string = 'marrhildreth'; end;
if strcmp(string,'c'), string = 'canny'; end;
operator = string;
case {'sigma','s'}
if nargin>k & isnumeric(varargin{k+1})
Sigma = varargin{k+1};
k=k+1;
end
case {'threshold','t'}
threshold_method = 'threshold';
thres_parm = [0.1 0.03];
if nargin>k & isnumeric(varargin{k+1})
thres_parm(1) = varargin{k+1};
k=k+1;
end
case {'hysteresis','h'}
threshold_method = 'hysteresis';
thres_parm = [0.1 0.03];
if nargin>k & isnumeric(varargin{k+1})
thres_parm = varargin{k+1};
if length(thres_parm)==1
thres_parm(2) = 0.3*thres_parm(1);
end
k=k+1;
end
end
end
end
end
if Sigma<0
error('Sigma must be positive');
end
if strcmp(threshold_method , 'hysteresis')
if thres_parm(1)<0 | thres_parm(1)>1 | thres_parm(2)<0 | thres_parm(2)>1
error('hysteresis: threshold parameters out of range');
end
if thres_parm(2)>thres_parm(1)
error('hysteresis: the second threshold must be less than the first');
end
end
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
matlab-(含教程)基于双目视觉的人脸三维建模matlab仿真 (189个子文件)
subject4_Middle_1.jpg 77KB
subject1_Middle_1.jpg 77KB
subject4_Middle_837.jpg 75KB
subject1_Middle_727.jpg 75KB
subject4_Middle_419.jpg 75KB
subject1_Middle_364.jpg 75KB
subject4_Middle_1673.jpg 75KB
subject4_Middle_1255.jpg 74KB
subject1_Middle_1453.jpg 74KB
subject1_Middle_1090.jpg 74KB
subject1_Middle_1816.jpg 74KB
subject1_Right_1.jpg 64KB
subject4_Right_1.jpg 64KB
subject4_Left_1.jpg 63KB
subject2_Middle_1.jpg 62KB
subject4_Right_837.jpg 62KB
subject1_Right_729.jpg 62KB
subject1_Right_365.jpg 62KB
subject4_Left_837.jpg 61KB
subject1_Right_1093.jpg 61KB
subject4_Right_1673.jpg 61KB
subject1_Right_1457.jpg 61KB
subject4_Right_419.jpg 61KB
subject4_Right_1255.jpg 61KB
subject1_Left_1.jpg 61KB
subject4_Left_1673.jpg 61KB
subject4_Left_419.jpg 61KB
subject4_Left_1255.jpg 60KB
subject2_Middle_835.jpg 60KB
subject2_Middle_418.jpg 60KB
subject2_Middle_1252.jpg 60KB
subject2_Middle_1669.jpg 60KB
subject1_Left_729.jpg 58KB
subject1_Left_365.jpg 58KB
subject1_Left_1457.jpg 58KB
subject1_Left_1093.jpg 58KB
subject2_Right_1.jpg 56KB
Calibratie 1_R_2585.jpg 56KB
subject2_Left_1.jpg 55KB
Calibratie 1_R_545.jpg 55KB
subject2_Right_1252.jpg 54KB
subject2_Right_418.jpg 54KB
subject2_Right_835.jpg 54KB
subject2_Right_1669.jpg 54KB
Calibratie 1_R_681.jpg 53KB
Calibratie 1_R_1769.jpg 53KB
subject2_Left_835.jpg 53KB
subject2_Left_418.jpg 52KB
Calibratie 1_M_2585.jpg 52KB
subject2_Left_1252.jpg 52KB
subject2_Left_1669.jpg 52KB
Calibratie 1_R_1497.jpg 52KB
Calibratie 1_R_409.jpg 52KB
Calibratie 1_R_817.jpg 52KB
Calibratie 1_R_1905.jpg 51KB
Calibratie 1_R_1.jpg 50KB
Calibratie 1_R_1633.jpg 50KB
Calibratie 1_M_545.jpg 49KB
Calibratie 1_M_681.jpg 48KB
Calibratie 1_R_137.jpg 48KB
Calibratie 1_M_1905.jpg 48KB
Calibratie 1_M_817.jpg 47KB
Calibratie 1_R_1361.jpg 46KB
Calibratie 1_R_273.jpg 45KB
Calibratie 1_R_1225.jpg 45KB
Calibratie 1_M_1769.jpg 45KB
Calibratie 1_R_2041.jpg 45KB
Calibratie 1_R_1089.jpg 45KB
Calibratie 1_R_2449.jpg 45KB
Calibratie 1_M_409.jpg 45KB
Calibratie 1_M_1497.jpg 44KB
Calibratie 2_M_1597.jpg 44KB
Calibratie 2_M_1730.jpg 44KB
Calibratie 1_M_1.jpg 43KB
Calibratie 2_M_2395.jpg 43KB
Calibratie 2_M_1331.jpg 43KB
Calibratie 2_M_1863.jpg 43KB
Calibratie 2_M_1.jpg 43KB
Calibratie 2_M_2262.jpg 43KB
Calibratie 2_M_1464.jpg 42KB
Calibratie 2_M_2528.jpg 42KB
Calibratie 1_M_1633.jpg 42KB
Calibratie 2_M_2129.jpg 42KB
Calibratie 2_M_932.jpg 42KB
Calibratie 2_M_1996.jpg 42KB
Calibratie 2_R_2395.jpg 42KB
Calibratie 1_M_2041.jpg 42KB
Calibratie 2_R_1597.jpg 42KB
Calibratie 2_R_1863.jpg 42KB
Calibratie 1_M_2313.jpg 42KB
Calibratie 2_M_666.jpg 42KB
Calibratie 2_R_1464.jpg 42KB
Calibratie 2_R_2528.jpg 42KB
Calibratie 1_R_953.jpg 42KB
Calibratie 2_R_666.jpg 42KB
Calibratie 1_M_2449.jpg 42KB
Calibratie 2_R_1730.jpg 41KB
Calibratie 1_M_1361.jpg 41KB
Calibratie 1_M_137.jpg 41KB
Calibratie 2_R_1996.jpg 41KB
共 189 条
- 1
- 2
资源评论
- weixin_415014912021-11-30用户下载后在一定时间内未进行评价,系统默认好评。
mYlEaVeiSmVp
- 粉丝: 1936
- 资源: 19万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功