MATLAB: How to calculate the angle by which a binary image has been rotated

MATLAB

I want to find the angle by which a binary image has been rotated. I have an image pattern of the type ones and zeros like this:
0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 1 0 0 0 0 0 1
0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 1 0 0 0 0 0 1
0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 1 0 0 0 0 0 1

Best Answer

We do not have a function that directly computes the angle by which an image is rotated. However, we do have other functions available which might help us calculate the same:
I1 = imread(your original image);
% some calculations which result in binary image
I2 = <your binary image>; % Assuming there is a single object in the image
[L, num]= bwlabel(I2);
stats = regionprops(L, Orientation) ;
The above set of commands can be repeated when the image is rotated. The difference in angles give us the degree by which the image is rotated. Also, note that the above technique depends on the nature of the image.
You might also want to try the following:
stats = regionprops(double(I2), Orientation) ; % where I2 is your binary image
More information on Orientation can be found by typing :
doc regionprops
at the MATLAB command prompt.
You might also be interested in looking at the “CPSELECT” function. The documentation can be found by typing:
doc cpselect