This is a hard question and I've done some thinking without much success. My main goal is to rotate an arbitrary pixel object to minimize it's bounding box' width. (or to maximize the height, that should be the same assuming circumference is constant)
Because such goal is not in the scope of SO question, I have determined a simpler goal that will lead to the solution: Find a geometric center of the pixel object.
Why? Because if I have this center, I will able to find points furthest from it and then rotate the object so that those points are vertically aligned.
I originally thought this would be as simple as calculating the center of the bounding box. Quick test in Inkscape proved that wrong: center of bounding box is not rotation invariant:
So, how can I find the real geometric center to calculate object extremes and rotate it? Here are some illustrations of what I'm trying to achieve - mind that I'm working with PIXELS not vector data: