满意答案
clear all
close all
bw=imread('你的你的你的你的.jpg');
bw=rgb2gray(bw);
figure,imshow(bw);title('灰度图像');
%================倾斜校正======================
qingxiejiao=rando_bianhuan(bw)
bw=imrotate(bw,qingxiejiao,'bilinear','crop');figure,imshow(bw);title('倾斜校正');
%取值为负值向右旋转
%%调用函数
function qingxiejiao=rando_bianhuan(I)
I=edge(I);%figure,imshow(I);
% I = zeros(100,100);
% I(25:75, 25:75) = 1;
theta = 1:180;
[R,xp] = radon(I,theta);
%figure,imagesc(theta,xp,R);colormap(hot);%title('R_{\theta} (X\prime)')%%imshow(theta,xp,R,[],'n')
[I,J] = find(R>=max(max(R)));%J记录了倾斜角
qingxiejiao=90-J;
%直线位置
% xlabel('\theta (degrees)');ylabel('X\prime');
% % colormap(hot)% colorbar IMAGE(C) displays matrix C as an image.
% title('R_{\theta} (X\prime)');
% colorbar;
01分享举报