• 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变换。

  • 相关阅读:
    Network (poj1144)
    C. Hongcow Builds A Nation
    ZYB loves Xor I(hud5269)
    D. Chloe and pleasant prizes
    Game(hdu5218)
    约瑟夫环的递推方法
    Misaki's Kiss again(hdu5175)
    Exploration(hdu5222)
    B. Arpa's weak amphitheater and Mehrdad's valuable Hoses
    C. Arpa's loud Owf and Mehrdad's evil plan
  • 原文地址:https://www.cnblogs.com/virqin/p/2514083.html
Copyright © 2020-2023  润新知