No BSD License  

Highlights from
GeoML

image thumbnail

GeoML

by

 

28 Aug 2008 (Updated )

A general morphable template tool for image segmentation.

ATE_EdgeDistance(varargin)
function varargout = ATE_EdgeDistance(varargin)
% ATE_EDGEDISTANCE  Computes the energy using the distance from edges.
%
%  This function computes the energy using the distance map from the edges
% from edges found in the image using an edge detector.
%
%  INITIALIZATION:
% 
%  Params
%  ------
% IN:
%  img      = The image.
%  fedge    = The edge function.
% OUT:
%  dist     = The distance map.
%
%  ENERGY COMPUTATION:
%
%  Params
%  ------
% IN:
%  img      = The image.
% OUT:
%  E        = The distance map.

% At least one argument is required:
if nargin<1; error('At least one argument is required!'); end

% Check the type of call:
if numel(varargin{1})==1 && varargin{1}==0
    % Call the init function:
    varargout{:} = InitEnvironment(varargin{2:end});
else
    % Call the evaluate function:
    varargout{:} = ComputeEnergy(varargin{:});
end

% ------------------------ LOCAL FUNCTIONS ------------------------

% The init function:
function dist = InitEnvironment(img,fedge)

% Check params:
if nargin<1; error('An image is requred for the initialization!'); end
if nargin<2; fedge=@(img)(edge(gaussianFilter(img),'canny')); end

% Get a gray double image:
img = imtype(img,'gF');

% Computing the edges:
edg = fedge(img);

% Computing the distance map:
dist = bwdist(edg);

% -----------------------------------------------------------------

% The evaluation function:
function E = ComputeEnergy(pts,dist)

% The energy id the sum of the distances:
E = sum(impixels(dist,pts))/size(pts,2);

Contact us