% TDF Finding topographical distance function
% 
% C = TDF(MINIMA,IM,COLORIM) Find the topographical distance function
% around the markers in MINIMA, for the image IM and according to the
% four-color labeling in COLORIM
%
function [c] = tdf(im,colorim)


disp('Calculating topographical distance functions');
for i = 1 : 4
    colorhere = colorim == i;
    
    %
    % Find all regions in colorim that have the same color and get the
    % minima for these
    %
    
    if isempty(find(colorhere,1))
        c(:,:,i) = ones(size(im));
        continue;
    end;
        
    msg = ['Computing TDF for color ' int2str(i)];
    disp(msg);
    

    % calculate topographical distance and add the min value of the
    % markers
    c(:,:,i) = ift(im,colorhere); 
    
end;
