How does Matlab detect falling edges?
Transition out of state if the value of the input data signal falls below a threshold of 2.5. The falling edge is detected when the value of the expression signal-2.5 becomes zero or negative.
How do I improve edge detection in Matlab?
Try changing the parameters or use different edge detection methods like Sobel, Canny, etc. Keep trying until you get something closer. Don't just assume you have to start with that bad image on top. Adjust parameters then there will be less to fix up to get to the bottom image.