1D and 2D Gaussian Derivatives

http://campar.in.tum.de/Chair/HaukeHeibelGaussianDerivatives

在这里插入图片描述
在这里插入图片描述

The Two-Dimensional Case
Base Function (0th order)
在这里插入图片描述

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

Computes discrete 1D gaussian functions

function [ gaussian ] = gaussian( x, sigma, order, normalize )
        if isempty(normalize)
            normalize = false;
        end
        
        gaussian_base = exp(-(x.*x)/(2*sigma^2));
        
        % we will do the same as ITK. this is just done to be able to
        % compare gaussian results with those coming from ITK.
        if (normalize)
            gaussian_base = sigma*gaussian_base;
        end
            
        if order == 0            
            gaussian = 1/(sigma*sqrt(2*pi)) .* gaussian_base;
        elseif order == 1
            gaussian = -x./(sigma^2*sqrt(2*pi)) .* gaussian_base;
        elseif order == 2
            gaussian = - gaussian_base ./ (sigma^3*sqrt(2*pi)) + x.*x.*gaussian_base / (sigma^5*sqrt(2*pi));
        end
end

Computes discrete 2D gaussian functions

function [ gaussian2d ] = gaussian2d( x, y, sigma, order_x, order_y, normalize )
	if (nargin<6)
        normalize = false;
    end        
        
    gaussian2d_base = exp( -(x.*x + y.*y) / (2*sigma^2) );
    
    % we will do the same as ITK. this is just done to be able to
    % compare gaussian results with those coming from ITK.
	if (normalize)
    	gaussian2d_base = sigma^2*gaussian2d_base;
	end    
    
    if (order_x == 0 && order_y ==0)
        scale = 1 / (2*pi*sigma^2);
        gaussian2d = scale .* gaussian2d_base;
    elseif (order_x == 1 && order_y == 0)
        scale = - x / (sigma^4*2*pi);
        gaussian2d = scale .* gaussian2d_base;
    elseif (order_x == 0 && order_y == 1)
        scale = - y / (sigma^4*2*pi);
        gaussian2d = scale .* gaussian2d_base;    
    elseif (order_x == 2 && order_y == 0)
        t1 = - gaussian2d_base / (sigma^4*2*pi);
        t2 = x .* x .* gaussian2d_base / (sigma^6*2*pi);
        gaussian2d = t1 + t2;
    elseif (order_x == 0 && order_y == 2)
        t1 = - gaussian2d_base / (sigma^4*2*pi);
        t2 = y .* y .* gaussian2d_base / (sigma^6*2*pi);
        gaussian2d = t1 + t2;
    elseif (order_x == 1 && order_y == 1)
       gaussian2d = x .* y .* gaussian2d_base / (2*pi*sigma^6);
    end
end
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、付费专栏及课程。

余额充值