radon校正
Radon(拉东)算法是一种通过定方向投影叠加,找到最大投影值时角度,从而确定图像倾斜角度的算法。具体过程如图所示
拉东变换
matlab实现
clear all
clc
close all
[inputfilename,dirname] = uigetfile('*.*');
inputfilename = [dirname, inputfilename];
im = imread(inputfilename); % For example: 'input.jpg'
grayImage = rgb2gray(im);
%%%%%
%%%%% Edge detection and edge linking....
binaryImage = edge(grayImage,'canny'); % 'Canny' edge detector
binaryImage = bwmorph(binaryImage,'thicken'); % A morphological operation for edge linking
%%%%%
%%%%% Radon transform projections along 180 degrees, from -90 to +89....
% R: Radon transform of the intensity image 'grayImage' for -90:89 degrees.
% In fact, each column of R shows the image profile along corresponding angle.
% xp: a vector containing the radial coordinates corresponding to each row of 'R'.
% Negative angles correspond to clockwise directions, while positive angles
% correspond to counterclockwise directions around the center point (up-left corner).
% R1: A 1x180 vector in which, each element is equal the maximum value of Radon transform along each angle.
% This value reflects the maximum number of pixels along each direction.
% r_max: A 1x180 vector, which includes corresponding radii of 'R1'.
theta = -90:89;
[R,xp] = radon(binaryImage,theta);
imagesc(theta,xp, R); colormap(jet);
xlabel('theta (degrees)');ylabel('x''');
title('theta方向对应的Radon变换R随着x''的变化图');
colorbar
%%%%%
[R1,r_max] = max(R);
theta_max = 90;
while(theta_max > 50 || theta_max<-50)
[R2,theta_max] = max(R1); % R2: Maximum Radon transform value over all angles.
% theta_max: Corresponding angle
R1(theta_max) = 0; % Remove element 'R2' from vector 'R1', so that other maximum values can be found.
theta_max = theta_max - 91;
end
correctedImage = imrotate(im,-theta_max); % Rotation correction
correctedImage(correctedImage == 0) = 255; % Converts black resgions to white regions
subplot(1,2,1), subimage(im)
subplot(1,2,2), subimage(correctedImage)
或
function [bw,qingxiejiao]=radontran(bwbone,bw)%radon倾斜校正
theta=1:90;
[R,xp]=radon( bwbone,theta);
[I0,J]=find(R>=max(max(R)));%找倾斜角
qingxiejiao=90-J;
bw=imrotate(bw,qingxiejiao,'bilinear','crop');
clc;
clear all;
close all;
[fn pn fi]=uigetfile('*.*','choose a picture');
Img=imread([pn fn]);
imshow(Img);title('Original image');
I = rgb2gray(Img);
I=improve_hist(I);
bw=edge(I,'canny');
theta=1:179;
[R,xp]=radon(bw,theta);
[I0,J]=find(R>=max(R(:)));%J记录了倾斜角
qingxiejiao=90-J;
I1=imrotate(Img,qingxiejiao,'bilinear','crop');
subplot(1,2,1),imshow(Img);title('Original image');
subplot(1,2,2),imshow(I1);title('correct image');
其中