I would not work with corners. But I'm sure that the greatest distance will always be between two pixels on the edge of the set, so I would follow the pattern: from any pixel in the set, go in any direction until you reach the edge of the set. Then move (offset) clockwise along the edge. Do this with any pixel as a starting point, and you can find the greatest distance. This is still pretty greedy, but I thought it might give you an alternative starting point for improvement.
Edit: what occurred to me: when you have the starting pixel s and the ending pixel e . In the first iteration using s corresponding e will be adjacent (next clockwise along the edge). When repeating along the edge, a case may arise that there is no straight line through the set between s and e . In this case, the line will hit another part of the set point (pixel p ). You can continue the iteration of the edge in this pixel ( e = p )
Edit2: If you press p , you will find out that the distance between s and e cannot be greater, so in the next iteration s you can skip all this part of the edge (between s and p ) and start again with p .
Edit3: Use the above method to find the first p . Take this p as the next s and continue. Repeat until you reach your first p again. The maximum distance will be between two of them p , unless the edge of the set is convex, in which case you will not find p .
Disclaimer: this is untested and it’s just ideas from the head, no drawings were made to justify my statements, and everything may be wrong (i.e. think about it for yourself before implementing it; D)
Meene source share