Vehicle Number Plate Detection and Character Recognition using MATLAB

Before understanding the concept behind image reading and recognition, you should understand “Fourier Transform” and basic matrix operations in Matlab.

1) Let’s consider we have captured below the picture of the vehicle, in which number plate and its font is clear with the surrounding contrast.

Vehicle number plate detection using MATLAB
Vehicle number plate detection using MATLAB

2) To locate the car license plate and identify the characters, we use the Matlab platform to provide some image processing functions to Fourier transform the character template and the image to be processed as the core idea. The basic method is as follows:

  1. Read the image to be processed and convert it to a binary image. After converting, using the threshold of 0.2 near the license plate characters most clearly, the least points (as shown below)
    I = imread('car.jpg');
    I2 = rgb2gray(I);
    I4 = im2bw(I2, 0.2);
  2. Remove the area where the image is too small to be sure of the license plate.
    bw = bwareaopen(I4, 500);
  3. To locate the license plate, inflate the white area, corrode to unrelated small objects, including the license plate characters.
    se = strel('disk',15);
    bw = imclose(bw,se);

  4. At this point the number plate where the white connectivity domain is clearly visible, but outside the black area, there is a larger white connectivity domain and the license plate where the domain surrounded by. It is necessary to fill it.
    bw = imfill(bw,[1 1]);
  5. Now, let’s find the connectivity domain boundary. While retaining this graphic for later to mark it on it.
    [B,L] = bwboundaries(bw,4);
    imshow(label2rgb(L, @jet, [.5 .5 .5]))
    hold on
  6. Finding the one that is most likely to be the number plate in all connected domains. The standard of judgment is that the aspect ratio of the license plate is about 4.5: 1, and its area is related to the circumference:(4.5 × L × L) / (2 × (4.5 + 1) × L) 2 ≈ 1/27 ,Which is characterized by,

    metric = 27 * area / perimeter ^ 2

    as the matching degree of the connected domain, the closer it is to 1, the more likely that the corresponding connected domain is 4.5: 1.

    MATLAB Program

    stats = regionprops(L,'Area','Centroid');
    for k = 1:length(B)
      boundary = B{k};
      delta_sq = diff(boundary).^2;   
      perimeter = sum(sqrt(sum(delta_sq,2)));
      area = stats(k).Area;
      metric = 27*area/perimeter^2;
      metric_string = sprintf('%2.2f',metric);
    if metric >= 0.9 && metric <= 1.1
        centroid = stats(k).Centroid;
        plot(centroid(1),centroid(2),'ko');
        goalboundary = boundary;
        s = min(goalboundary, [], 1);
        e = max(goalboundary, [], 1);
       goal = imcrop(I4,[s(2) s(1) e(2)-s(2) e(1)-s(1)]);
    end
      text(boundary(1,2)-35,boundary(1,1)+13,...
      metric_string,'Color','g',...
    'FontSize',14,'FontWeight','bold');
    end
    for k = 1:length(B)
     boundary = B{k};
     plot(boundary(:,2),boundary(:,1),'w','LineWidth',2)
    end

    The rectangular matching degree is 0.99, which is the most probable area. Below is the license plate area in the binary image determined by it:

  7. The license plate image is highlighted and expanded to a square of 256 × 256 (left as shown below) so that the matrix rotation operation is performed in the following “Fourier transform”.
    goal = ~goal;
    goal(256,256) = 0;
    figure;
    imshow(goal);
  8. Read a character template from the file (with “P” as an example, the template image is taken directly from the above binary image). Calculate the Fourier descriptor for the image and calculate the descriptor with a predefined decision function. In the transformed image, the level of brightness indicates the degree to which the corresponding region matches the template (as shown in the figure below).
    w = imread('P.bmp');
    w = ~w;
    C= real(ifft2(fft2(goal).*fft2(rot90(w,2),256,256)));
  9. By checking the maximum value of C, the test determines a suitable threshold (where 240 is appropriate), showing the point where the brightness is greater than the threshold, that is, the highest degree of matching to the template (see below).
    thresh = 240;
    figure;
    imshow(C > thresh);

    In contrast to the left and right graphs, it can be shown that the character “P” is recognized and positioned. The same way that you can identify and locate other characters.

3) This method is generally easier to understand, Matlab function hides the Fourier transform and other complex calculations. Disadvantages: In the positioning of the license plate, the program specifically according to the characteristics of the given image design, there is no universality. In character recognition, only characters that are substantially consistent with a given template are recognized. License plate size, angle, light, integrity, clarity changes, it can not be identified. At the same time for “8” and “B” similar characters, recognition is often confused.

Download

Click here to download MATLAB program and related files.

If you like this article, please share it with your friends and like or facebook page for future updates. Subscribe to our newsletter to get notifications about our updates via email. If you have any queries, feel free to ask in the comments section below. Have a nice day!

Addition of Two Images Using MATLAB Image Processing

In this tutorial, you will learn how to add two images. Yes, it is possible in MATLAB. You can add i.e. superimpose two images. Following are the steps to add two images using MATLAB image processing:

The only requirement for superimposition (or addition) of two images is that the two matrices that you have defined for two images should have the same size (as we know MATLAB totally works with matrices and the addition of two matrices is possible only when they are of the same size).

Let us consider two images

  1. H: New photorock 1.jpg
  2. H: New photoImagesPhoto1561.jpg

H:New photorock 1.jpg
H:New photorock 1.jpg

H:New photoImagesPhoto1561.jpg
H:New photoImagesPhoto1561.jpg

(These are two images that I have chosen, but for your case, it may be different. For copying the image path visit my previous post)

MATLAB Program for Addition of Two Images:

%Addition of two images
%Created by : myclassbook.org (mayuresh)
%Created on : 21 May 2013

A=imread('H:New photorock 1.jpg');          %define A as a first image
B=imread('H:New photoImagesPhoto1561.jpg'); %define B as a second image
C=imresize(A,[400 400]);                    % image resize of A as 400*400 matrix
D=imresize(B,[400 400]);                    % image resize of B as 400*400 matrix  
E=imadd(C,D);                               % image addtion of C and D
imshow(E)                                   % display of image E

Addition of Two Images
Addition of Two Images

Output

Addition of Two Images
Addition of Two Images

If you like this article, please share it with your friends and like or facebook page for future updates. Subscribe to our newsletter to get notifications about our updates via email. If you have any queries, feel free to ask in the comments section below. Have a nice day!

Color to Grayscale Conversion: MATLAB Image Processing Tutorial

Hi friends, this is my first tutorial on Matlab image processing.The purpose of this tutorial is to gain familiarity with MATLAB’s Image Processing Toolbox. Let us start the basic of the image processing with a very simple example i.e. converting a color image of any format (ex. jpeg, jpg, bmp, etc) into a grayscale image.

MATLAB Program for Color to Grayscale Conversion

Step 1:

Initially, you have to define a matrix A with a path of the image that you have to convert. For this purpose, if you can’t copy a path of the image file, just install this small software (http://www.novell.com/coolsolutions/tools/downloads/pathc400.zip) after installing this software simply right click on the image you will see an option for copy long URL. OK after copying the image path.

Step 2:

Define matrix B with the image format. In this case jpg. You can change the format you have.

Step 3:

C=rgb2gray(B).   Here rgb stands for RedGreenBlue i.e. color image gray stands for converting it into grayscale.

%tutorial M-file
%created by: myclassbook.org
%created on: 20 may 2013

% Load a color .jpg image and convert it into grayscale

A=’H:New photoImagesPhoto1619.jpg’; %designate matrix A as the specified file
B=imread(A,’jpg’)                            %matrix B loaded with jpg file specified by A
figure (1),imshow(B);                     %show image B in figure window 1
C=rgb2gray(B)                                 %convert color image to grayscale image
figure (2),imshow(C);                    %show image C in figure window 2

MATLAB Image Processing
MATLAB Image Processing

MATLAB Image Processing
MATLAB Image Processing

MATLAB Image Processing
MATLAB Image Processing

If you like this article, please share it with your friends and like or facebook page for future updates. Subscribe to our newsletter to get notifications about our updates via email. If you have any queries, feel free to ask in the comments section below. Have a nice day!