Created
May 28, 2014 21:26
-
-
Save mabdrabo/3990ff2ea497e199ce1f to your computer and use it in GitHub Desktop.
Number plate recognition
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
clc, clear, close all | |
for i=1:6 | |
x = imread(strcat(num2str(i), '.jpg')); | |
% x= imread('2.jpg'); % read image | |
image = rgb2gray(x); | |
%g=medfilt2(image,[2 2]); % Median filtering to remove noise. | |
H = padarray(2,[2 2]) - fspecial('gaussian' ,[5 5],2); % create unsharp mask | |
sharpened = imfilter(image,H); % create a sharpened version of the image using that mask | |
BW2 = edge(sharpened,'prewitt'); | |
se=strel('disk',1); % Structural element (disk of radius 1) for morphological processing. | |
dil=imdilate(BW2,se); | |
ge=imerode(BW2,se); % Eroding the gray image with structural element. | |
dil=imsubtract(dil,ge); % Morphological Gradient for edges enhancement. | |
dil=mat2gray(dil); % Converting the class to double. | |
dil=conv2(dil,[1 1;1 1]); % Convolution of the double image for brightening the edges. | |
dil=imadjust(dil,[0.5 0.7],[0 1],0.1); % Intensity scaling between the range 0 to 1. | |
%figure, imshow(dil); | |
% Filling all the regions of the image. | |
F=imfill(dil,'holes'); | |
F = medfilt2(F,[3 3]); % Median filtering to remove noise. | |
figure, imshow(F); | |
%Thinning the image to ensure character isolation. | |
H=bwmorph(F,'thin',1); | |
H=imerode(H,strel('line',3,90)); | |
% Selecting all the regions that are of pixel area more than 100. | |
final=bwareaopen(F,100); | |
figure, imshow(final); | |
%I2 = imcrop(x,[405 360 200 100]); | |
%figure, imshow(I2); | |
%Find Plate | |
[lab, n] = bwlabel(final); | |
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 && PlateWidth/PlateHeight < 2.7 && PlateExtent >= 0.3 && PlateExtent < 0.7 | |
im2 = imcrop(x, RectangleOfChoice); | |
figure, imshow(im2), title(strcat('w/h: ', num2str(PlateWidth/PlateHeight), ' extent: ', num2str(PlateExtent))); | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment