How to straighten a tilted square shape in an image?
问题 How can I straighten a tilted square shape in an image? I do not know the angle with which it is tilted and the code must calculate it and then rotate it automatically. For example, I have the following image: which should be rotated to give the following output image: 回答1: A simple way using only the top and bottom corners. Note that this approach relies on the upper and lower most corners: i = imread('sq.jpg'); i_bw = im2bw(i)==0; % Modify the strel as required se = strel('square', 10); i