function [pixelOut,ctrlOut] = EdgeDetectandOverlay(pixelIn,ctrlIn)
% EdgeDetectandOverlay 
% Detect edges in an input stream, and overlay the edge data onto the 
% original stream. 
% pixelIn and ctrlIn are a scalar pixel and its associated pixelcontrol
% structure, respectively.
% You can generate HDL code from this function.

  persistent align
  if isempty(align)
    align = visionhdl.PixelStreamAligner;
  end    
  
  persistent find_edges
  if isempty(find_edges)
    find_edges = visionhdl.EdgeDetector;
  end
  
  [edgeOut,edgeCtrl] = find_edges(pixelIn,ctrlIn);
  [origOut,alignedEdgeOut,ctrlOut] = align(pixelIn,ctrlIn,edgeOut,edgeCtrl);
  if (alignedEdgeOut)
      pixelOut = uint8(0); % Set edge pixels to black
  else
      pixelOut = origOut;
  end
end