Edge and outline extraction code