Fully implements edge detection. Minor edits on some corner cases still
need to be addressed.