0

I am using the following code in MATLAB to find the rectangle containing a car's license plate:

    clc
clear
close all

%Open Image
I = imread('plate_1.jpg');
figure, imshow(I);

%Gray Image
Ib = rgb2gray(I);
figure,
subplot(1,2,1), imshow(Ib);

%Enhancement
Ih = histeq(Ib);
subplot(1,2,2), imshow(Ih);

figure,
subplot(1,2,1), imhist(Ib);
subplot(1,2,2), imhist(Ih);

%Edge Detection
Ie = edge(Ih, 'sobel');
figure, 
subplot(1,2,1), imshow(Ie);

%Dilation
Id = imdilate(Ie, strel('diamond', 1));
subplot(1,2,2), imshow(Id);


%Fill
If = imfill(Id, 'holes');
figure, imshow(If);

%Find Plate
[lab, n] = bwlabel(If);

regions = regionprops(lab, 'All');
regionsCount = size(regions, 1) ;

for i = 1:regionsCount
    region = regions(i);
    RectangleOfChoice = region.BoundingBox;
    PlateExtent = region.Extent;

    PlateStartX = fix(RectangleOfChoice(1));
    PlateStartY = fix(RectangleOfChoice(2));
    PlateWidth  = fix(RectangleOfChoice(3));
    PlateHeight = fix(RectangleOfChoice(4));

    if PlateWidth >= PlateHeight*3 && PlateExtent >= 0.7
        im2 = imcrop(I, RectangleOfChoice);
        figure, imshow(im2);
    end
end

Plates all have white backgrounds. Currently,I use the rectangles' ratio of width to height to select candidate regions for output. This gives the plate rectangle in addition to several other irrelevant ones in the case of a white car. What method can I use to get only one output: the license plate? Also, I don't find a plate at all when I run the code on a black car. Maybe that's because the car's color is the same as the plate edge. Are there any alternatives to edge detection to avoid this problem?

Mehdi Haghgoo
  • 3,144
  • 7
  • 46
  • 91
  • The car colour being black may be a problem. As a premature answer, why don't you change the line `edge(Ih, 'sobel')` and change the argument `sobel` to any of the following: `prewitt`, `log`,`canny` or `roberts`. If not, you may need to somehow enhance image in some way so edges are more easily detected, that's if edges are the problem – woosah Dec 25 '13 at 23:27
  • For the many rectangles, maybe you can separate the plate from other non-rellevant resutls by checking the variance/some other histogram feature, that characterizes the plate (because of the black letters inside) – Adiel Dec 26 '13 at 01:50
  • @Woosah I use prewitt,log,canny an roberts. They don't work neither.This is the white car I use [link](http://8pic.ir/images/88146564605446812704.jpg) and this is the black one: [link](http://8pic.ir/images/69002361337612567596.jpg). – Mehdi Haghgoo Dec 26 '13 at 07:50

1 Answers1

2

Try this !!!

I = imread('http://8pic.ir/images/88146564605446812704.jpg');
im=rgb2gray(I);
sigma=1;
f=zeros(128,128);
f(32:96,32:96)=255;
[g3, t3]=edge(im, 'canny', [0.04 0.10], sigma);
se=strel('rectangle', [1 1]);
BWimage=imerode(g3,se);
gg = imclearborder(BWimage,8);
bw = bwareaopen(gg,200);
gg1 = imclearborder(bw,26);
imshow(gg1);

%Dilation
Id = imdilate(gg1, strel('diamond', 1));
imshow(Id);

%Fill
If = imfill(Id, 'holes');
imshow(If);

%Find Plate
[lab, n] = bwlabel(If);

regions = regionprops(lab, 'All');
regionsCount = size(regions, 1) ;

for i = 1:regionsCount
    region = regions(i);
    RectangleOfChoice = region.BoundingBox;
    PlateExtent = region.Extent;

    PlateStartX = fix(RectangleOfChoice(1));
    PlateStartY = fix(RectangleOfChoice(2));
    PlateWidth  = fix(RectangleOfChoice(3));
    PlateHeight = fix(RectangleOfChoice(4));

   if PlateWidth >= PlateHeight*1 && PlateExtent >= 0.7
        im2 = imcrop(I, RectangleOfChoice);
        %figure, imshow(I);
        figure, imshow(im2);
    end
end
Dramon
  • 36
  • 2