improved edge detection algorithm