Make an algorithm more robust for identifying contours on images

what I meant to say is… for a discussion it helps if I don’t have to run your code to see what’s going on. what would help me is to see intermediate results, i.e. you might wanna post some intermediate results from the failure case.