a=imread('input.tif');
bw=im2bw(a);
skeleton=bwmorph(bw, 'skel', Inf);
lb=bwlabel(skeleton);
k=regionprops(lb,'BoundingBox');
g=cat(1, k.BoundingBox);
[mx, idx]=max(g(:,3).*g(:,4));
frame=lb==idx;
angles2=[85:0.01:95];
[rho,theta]=radon(frame, angles2);
[pos_x, pos_y]=find(rho==max(rho(:)));
angle=angles2(pos_y)
c=imrotate(a,90-angle);
imwrite(c, 'out_rotated2.tif');