How to get the orientation value of a rotated square?
Disclaimer:  I am not a MATLAB user, so I had to search for this and have no way to test it.

You should be able to find two opposite corner points by using the "Extrema" property from "regionprops".  The tangent of an angle is a slope, so calculate the slope and take the inverse tangent.  Do note that the line may be vertical, i.e. undefined slope, and you have to deal with that case.  If you choose the left-top and right-bottom, you should get a more horizontal line and not have to worry about it.

You also have to keep radians and degrees straight.



As math:

$$ \Delta y = y_{LT} - y_{RB} $$
$$ \Delta x = x_{LT} - x_{RB} $$

$$ m = \frac{\Delta y}{\Delta x} $$

$$ \theta = tan_{deg}^{-1} (m) $$

$$ d = \theta - 45 $$

By finding the leftmost and rightmost $x$'s, there shouldn't be a problem with the slope calculation.  The line between the two extreme points should be a diagonal of the square.  A diagonal should be at 45 degrees, so $d$ is how much you need to rotate the figure to get it there.