radon變換用於車牌圖像傾斜矯正[水平傾斜和垂直傾斜]


  Radon變換定義:下圖顯示了在指定的旋轉角度的單一投影。間距為1個像素的平行光穿過圖像,則radon變換計算穿過圖像長度上的積分,即

     式中    
 
   旋轉角度為θ的平行束投影
 

    f(x,y) 在垂直方向的線積分是f(X,Y)投影到X軸;在水平方向的積分是f(X,Y)投影到Y軸。可以沿任意角度θ計算投影,下圖說明了Radon變換沿角度θ的幾何形狀。

   
   其實可以通俗地理解為將圖像上每一個點向一個旋轉的新坐標系y'作投影,在得到的投影合集中找到最大投影就能知道圖像的最大化為偏角,使用旋轉公式就能將圖像矯正過來。
  車牌識別中遇到兩種傾斜,垂直和水平傾斜。兩種傾斜都是因為相機安裝位置和監控過車角度沒有對好導致。
  垂直傾斜二值圖:

  

  水平傾斜二值圖:

  

  

  垂直傾斜為菱形扭曲,水平傾斜車牌字符仍保留原來的比例特征。理論上通過從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)

   垂直傾斜矯正結果:

  

  水平傾斜旋轉后結果:

  

  垂直傾斜還需要將每一個字符縱向移動,保證水平。

  發現從radon變換結果R中統計最大角度有時有問題,還需再改進。另外還沒有使用C實現radon變換。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM