I've written about 20 pages of hints, tips and techniques. Most are cookbooks of how to do various complex tasks. I've tried not to replicate the excellent works by Anthony and Fred, but inevitably there is some overlap.

The commands and scripts are Windows BAT, but should be (mostly) understandable by users of other languages.

One other technique would be sweeping left to right and top down. The first white pixel you hit would be top left. Do the sweeps from different directions to find the other corners (eg to find the bottom right you would do a sweep right to left and bottom to top.
This would work fine for most orientations of the rectangle except when it was rotated a bit counterclockwise. But this could be detected by testing if the x-value of the bottom right corner was left of the x-value of the top left corner. If this is the case then you would have to swap the left and right corners for each other. - I think this would be the least expensive technique.