Gaussian filters和2D convolution

mark


2D convolution




function [mag,ax,ay, or] = Canny(im, sigma) % Magic numbers GaussianDieOff = .0001; % Design the filters - a gaussian and its derivative pw = 1:30; % possible widths ssq = sigma^2; width = find(exp(-(pw.*pw)/(2*ssq))>GaussianDieOff,1,'last'); if isempty(width) width = 1; % the user entered a really small sigma end gau=fspecial('gaussian',2*width+1,1); % Find the directional derivative of 2D Gaussian (along X-axis) % Since the result is symmetric along X, we can get the derivative along % Y-axis simply by transposing the result for X direction. [x,y]=meshgrid(-width:width,-width:width); dgau2D=-x.*exp(-(x.*x+y.*y)/(2*ssq))/(pi*ssq); % Convolve the filters with the image in each direction % The canny edge detector first requires convolution with % 2D gaussian, and then with the derivitave of a gaussian. % Since gaussian filter is separable, for smoothing, we can use % two 1D convolutions in order to achieve the effect of convolving % with 2D Gaussian. We convolve along rows and then columns. %smooth the image out aSmooth=imfilter(im,gau,'conv','replicate'); % run the filter across rows aSmooth=imfilter(aSmooth,gau','conv','replicate'); % and then across columns %apply directional derivatives ax = imfilter(aSmooth, dgau2D, 'conv','replicate'); ay = imfilter(aSmooth, dgau2D', 'conv','replicate'); mag = sqrt((ax.*ax) + (ay.*ay)); magmax = max(mag(:)); if magmax>0 mag = mag / magmax; % normalize end or = atan2(-ay, ax); % Angles -pi to + pi. neg = or<0; % Map angles to 0-pi. or = or.*~neg + (or+pi).*neg; or = or*180/pi; % Convert to degrees. end
最新发布
05-22
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值