Tracking edges / white pixel instead the whole image

caffeinecranked's icon

Hey there I was wondering if anyone could help me on this matter..
So basically I have an image let's a box of a rectangle in the middle, then I apply an edge detection for let's say Canny or Sobel and the result would be the white line of rectangle and the rest would be black.. So I will scan the image from top to bottom and left to right..
If I reached the first position of white pixel - let's say here (4,0) - top left vertex ..then I will check the neighbouring pixels for the next available white pixel...the result would either I go downward or continue to the right - so let's say the algorithm goes to the right and it continues until (10,0) which in this case be the top right vertex then it checks the next available pixel and then no more left to the right and now it will continue to go downward and so on..
How do I go about and do this?

thank you

caffeinecranked's icon

So instead scanning the whole image it will track down the white pixel and moves along it until there's no more left.