A list,

Domestic license plate recognition steps based on MATLAB: original image recognition, column filtering, row filtering, segmentation results, gray, horizontal tilt correction, filtering binarization, character segmentation.

Ii. Source code

% clear 
addpath(genpath(pwd)); % Add all files under subfolders %% load images start=6212;
% state=num+1;
% start=6540;
state=1;

% for num = state:294
    close all
num = 1; % read the num image % from the folder20
% 

    fname=['Sample library \IMG_',num2str(start+num),'.jpg']; % has three license plate folders:'PlateImages/%d.jpg'or'PlateImages/Image1/%d.jpg''PlateImages/Image2/%d.jpg'
filename = fullfile(pwd, fname);
Img = imread(filename);
%{
figure(5);
subplot(2.2.1); imshow(Img); title('original'); I1=rgb2gray(Img); subplot(2.2.2); imshow(I1); title('Grayscale');
subplot(2.2.3); imhist(I1); title('Gray histogram'); I2=edge(I1,'roberts'.0.15.'both');
subplot(2.2.4); imshow(I2); title(Roberts operator edge detection)
se=[1;1;1];
I3=imerode(I2,se);
figure(6);
subplot(2.2.1); imshow(I3); title('Corroded image'); se=strel('rectangle'[25.25]); I4=imclose(I3,se); subplot(2.2.2); imshow(I4); title('Smooth image contour'); I5=bwareaopen(I4,2000);
subplot(2.2.3); imshow(I5); title('Remove small objects from objects'); %} GetDB; %% Locate license plate: find the position of license plate in the original image % input parameter Img: read the original true color image information % output parameter plate: After positioning processing, from the original true color image (compression processing) intercepted to the license plate position of the true color image information; %% tilt correction: horizontal tilt correction and vertical tilt correction are processed by Radon transform and affine function respectively for the tilt correction of recognition numbers. % Input parameters: true color license plate image information captured for positioning % Output parameters:  plate = radon_repair(plate); %% license plate filter % license plate filter: eliminate (pixel value set0) Boundary image information of license plate image % Input parameter: plate True color license plate image information captured for positioning % Output parameter: D is the image of the original license plate image after filtering (i.e., excluding the upper and lower boundaries (and eliminating polygon regions)), p is the image of the original license plate image after counterclockwise rotation [D, P] = Plate_Process(plate,fname); % % % segmentation license plate license plate segmentation: cut (delete) the boundary of the license plate image information input parameters: % d to the original license plate image filtering (i.e., excluding outside the upper and lower boundary (and polygonal region excluding)) after pictures, p for the true color of the original license plate image after image plate counter-clockwise % output parameters: according to the image d0Edge, the cut out input picture: input picture D was cut out and output picture E, input picture P was cut out and output picture P [E, P] = Segmation(D, P); Function [result, plate] = Plate_Process(plate, fname, flag) %if nargin < 3
        flag = 1;
    end
    % n = ndims(A) returns the number of dimensions in the array A.
    if ndims(plate) == 3
        % I = rgb2gray(RGB) converts the truecolor image RGB to the grayscale intensity image I.
        % rgb2gray converts RGB images to grayscale by eliminating the hue and saturation information whileretaining the luminance. plate1 = rgb2gray(plate); % Convert the original picture information of the license plate tograyscale intensity image(Grayscale image? For convenience, the following are all referred to as grayscale images)
    else
        plate1 = plate; end Im = plate1; % Im is grayscale image plate =double(plate); % B = mean2(A) computes the mean of the values in A. % b = std2(A) computes the standard deviation of the values in A. % The [mean standard deviation] matrix of the current image is obtained, which is used to calculate with the [mean standard deviation] matrix of the database, and then the database parameter information m = [mean2(plate(:,:,1)) mean2(plate(:,:,2)) mean2(plate(:,:,3)) std2(plate(:,:,1)) std2(plate(:,:,2)) std2(plate(:,:,3))]; % f = fullfile(filepart1,... ,filepartN) builds a full file specification, f, from the foldersand file names specified.
    % f = fullfile('myfolder'.'mysubfolder'.'myfile.m') ===> f = myfolder\mysubfolder\myfile.m
    load('model.mat');
    
    ms = cat(1, M.m);   % 数据库中的[均值 标准差]矩阵
    
    % B = repmat(A,m,n) creates a large matrix B consisting of an m-by-n tiling of copies of A.
    % The size of B is [size(A,1)*m, (size(A,2)*n]. The statement repmat(A,n) creates an n-by-n tiling.
    m = repmat(m, size(ms, 1), 1); % Extend the [mean standard deviation] matrix of the current image, For the matrix calculation % B = sum(A,dim) sums along the dimension of A specified by scalar dim. The dim input is an integer  value from1 to N, 
    % where N is the number of dimensions in A. Set dim to 1 to compute the sum of each column, 2To sum rows, etc. % dis = sum(m-ms).^2.2); % The variance of the current image [mean standard deviation] matrix and the database [mean standard deviation] matrix [~, id] = min(dis); % find the one with the smallest variance, that is, find the database parameter that is best suited for processing the current imageif fname(6) = ='s'ro = M(id).ro; % Angle parameter of image rotation, in degreeselse
        ro=0; end th = M(id).th; % Threshold for converting grayscale image to binary image. If the value in grayscale image is greater than this threshold, it is converted to1Otherwise, convert to0pts = M(id).pts; % Defines the vertex of the picture % B = imrotate(A, Angle, Method) rotates image A by Angle degrees in A counterclockwise direction around its % center point,using the interpolation method specified by method.
    Im = imrotate(Im, ro, 'bilinear'); % Rotate the grayscale image Im in a counterclockwise direction and select bilinear interpolation. Plate = imrotate(plate, ro,'bilinear'); % Rotate the original image of the license plate by ro degrees counterclockwise, Bilinear interpolation % BW = IM2bw (I, level) converts the grayscale image I to a binary image. % The output image BW replaces all pixels in the input image With luminance greater than level with the value1 (white)
    % and replaces all other pixels with the value 0 (black). Specify level in the range [0.1]. This range is relative to
    % the signal levels possible for the image's class. Therefore, a level value of 0.5 is midway between black andwhite, regardless of class. bw = im2bw(Im, th); % convert grayscale image Im to binary image, conversion threshold is th % h = fspecial('average', hsize) returns an averaging filter h of size hsize.
    % The argument hsize can be a vector specifying the number of rows and columns in h, or it can be a scalar, in which case h is a square matrix.
    h = fspecial('average'.2); % defines a multidimensional mean filter h with a dimension of2 x 2
    
    % B = imfilter(A,h) filters the multidimensional array A with the multidimensional filter h.
    % The array A can be logical or a nonsparse numeric array of any class and dimension. The result B has the same size and class as A.
    % ___= imfilter(___,options,...) performs multidimensional filtering according to the specified options.
    % 'replicate' ===> Input array values outside the bounds of the array are assumed to equal the nearest array border value.
    bw1 = imfilter(bw, h, 'replicate'); % Use multidimensional mean filter H to filter binary image BW. The filtering option is REPLICATE % mask = Mask_Process(BW1). % The function of this method is to remove the upper and lower stray lines of the bW1 image, that is, to remove the information at the upper and lower boundaries of the binary image Bw1 using a specific algorithm (the pixel values of these rows are all set to0Mask here can be understood as: if the image pixel is between the boundary of the hybrid line and the upper boundary of the license plate or between the boundary of the hybrid line and the lower boundary of the license plate, the value of this pixel is0Otherwise, if the image pixel is between the blur line boundary and the blur line boundary, the value of this pixel is1% bw2 = bw1 .* mask; * operation can be understood as: and operation, so bw2 is the result of removing interference in binary image bw1 with mask matrix bw2 = bw1; % In addition to eliminating clutter lines by Mask_Process() function, if there is defined license plate boundary information, the license plate boundary information can be further used for image processing %if~ isEmpty (PTS) % If the PTS is not empty(that is, there are external boundary vertex definitions), Execute % % BW = Roipoly (I, C, R) returns the region of interest(ROI) specified by the polygon(polygon) described by Vectors Cand r,
%         % which specify the column andRow indices of each vertex, respectively. CandR must be the same size. % % according to binary image bw2, and polygon vertices PTS (:,1), pts(:, 2), the binary image mask is obtained, and the values of the area surrounded by vertices are1% % All values of other fields are0, the purpose of this is to remove the interference of the license plate boundary.1), pts(:, 2)); % bw1 = bw1.* mask; % bw1 = bw1.* mask; % bw2 = bw2.* mask; % bw2 = bw2. % bw2 is the binary image % end after removing interference using Mask_Process() algorithm and polygonCopy the code

3. Operation results











Fourth, note

Version: 2014 a