function mask = lnkshow7(p,a,thresh)
%
% lnkshow - generate link mask
% On input:
%     p: band properties matrix
%     a: labeled image
%     thresh: threshold for angle difference
% On output:
%     mask: overlay mask of link edges
% Call:
%     mask = lnkshow7(p,a);
%

[numsegs,dummy] = size(p);
[m,n] = size(a);
mask = zeros(m,n);
CROW = 1; CCOL = 2;

for s1 = 1:numsegs
  s1row = p(s1,CROW); s1col = p(s1,CCOL);
  for i1 = 4:6
    s2 = p(s1,i1);
    if s1 ~= s2
      s2row = p(s2,CROW); s2col = p(s2,CCOL);
	  theta = atan2(s2row-s1row,s2col-s1col);
	  rmin = min(s1row,s2row);
	  rmax = max(s1row,s2row);
	  cmin = min(s1col,s2col);
	  cmax = max(s1col,s2col);
	  for r = rmin:rmax
	    for c = cmin:cmax
		  theta2 = atan2(r-s1row,c-s1col);
		  if abs(theta2-theta)<thresh
		    mask(r,c) = 255;
		  end
		end
	  end
    end;
  end;
end;
