I am trying to determine the orientation of a square region in a bitmap image relative to the X-axis. I have written the following code to illustrate the limitation of the 'Orientation' property of the REGIONPROPS command:
s = imread('square0.bmp'); %file is attached
imshow(s); %start with a square parallel to x-axis
s15 = imrotate(s, 15); %rotate the image by 15 degrees
figure(2);imshow(s15);g = rgb2gray(s15); %convert to greyscale
l = bwlabel(g); %label the regions
p = regionprops(l, 'Orientation', 'MajorAxisLength', 'MinorAxisLength')%find the orientation of the region
srot = imrotate(s15, -(p.Orientation));%attempt to rotate the region back to a horizontal position
figure(3);imshow(srot);
The image is rotated 15 degrees. I then attampt to rotate the square
back to an orientation parallel to the x-axis using the opposite of the
angle calculated by REGIONPROPS. However, the final orientation is not
parallel to the x-axis. The angle of orientationof the rotated figure is 54 degrees. This is clearly not 15 degrees as I expected.
Best Answer