I am working on a set of images, and as an intermediate step, I need to determine the longest edge in a 2-dimensional image. The original image has been subjected to canny edge detection. What could be the best way to do this... I tried going through the entire image marking every edge with different pixel values to differentiate them and keeping the maximum length stored. This seems to be failing due to some reason. I have to implement this in C++, is there a better way to do this?