www.pudn.com > levelsetImage.rar > edgestop.m
function g = edgestop( im, n, sigma ) % EDGESTOP Create the edge-stopping function % G = EDGESTOP( IM, SIZE, SIGMA ) creates the edge-stopping % function of 'im'. The image is first smoothed with a gaussian % kernal of size 'n' and parameter 'sigma' % first convolve the image with a gaussian filter to blur it gauss_filter = fspecial( 'gaussian', n, sigma ); filtered_im = imfilter( im, gauss_filter ); % next create the gradient image by summing the horizontal % and vertical gradient images [ x_grad, y_grad ] = gradient( filtered_im ); grad_im = sqrt( ( x_grad.^2 ) + ( y_grad.^2 ) ); % scale the gradient image max_grad = max( max( grad_im ) ); min_grad = min( min( grad_im ) ); grad_im = 10 .* ( grad_im - min_grad ) ./ ( max_grad - min_grad ); % Create the edge-stopping function, can also use: %g = exp( -abs( grad_im ) ); g = 1 ./ ( 1 + abs( grad_im ) );