function normVec = avgNormals(i, j, m, n)

global dX
global dY
global T
global HUGE

% include neighbor in the average if neighbor is accepted 
% at least one neighbor must be accepted
normVec = [0 0];
if (i < m) & (T(i+1, j, 2) == HUGE) & (T(i+1, j, 1) ~= HUGE)
    normVec = [dY(i+1, j) dX(i+1, j)];
end
if (j < n) & (T(i, j+1, 2) == HUGE) & (T(i, j+1, 1) ~= HUGE)
    normVec = normVec + [dY(i, j+1) dX(i, j+1)];
end
if (i > 1) & (T(i-1, j, 2) == HUGE) & (T(i-1, j, 1) ~= HUGE)
    normVec = normVec + [dY(i-1, j) dX(i-1, j)];
end
if (j > 1) & (T(i, j-1, 2) == HUGE) & (T(i, j-1, 1) ~= HUGE)
    normVec = normVec + [dY(i, j-1) dX(i, j-1)];
end

