how can i segment and detect the numbers on the number plate area if i have extracted the required region

1 view (last 30 days)
clc; clear all; close all; imtool close all; workspace; I=imread('car.jpg'); %converting image to gray*********** ig=rgb2gray(I); [row col]=size(ig); %dilation and removal of noise********** id=ig; for i=1:row for j=2:col-1 temp =max(ig(i,j-1), ig(i,j)); id(i,j) = max(temp, ig(i,j+1)); end end i=id; %EXAMPLE figure(1); % imshow(ig); % figure(2); % title('Dilated Image') % imshow(id); % figure(3); % imshow(I); diff=0; sum=0; total_sum=0; diff=uint32(diff); %convert to unsigned integer
%%PROCESS EDGE IN HORIZENTAL DIRECTION
disp('process edges horizently');
horiz1(i)=0;
max_hori=0;
maxim=0;
for i=2:col
sum=0;
for j=2:row
if(I(j,i)>I(j-1,i));
diff=uint32(I(j,i)-I(j-1,i));
else
diff=uint32(I(j-1,i)-I(j,i));
end
if(diff>20)
sum=sum+diff;
end
end
horiz1(i)=sum;
if(sum>maxim)
max_hori=i;
maxim=sum;
end
total_sum=total_sum+sum;
end
average=total_sum/col;
%histogram plot
figure(4);
subplot(3,1,1);
plot(horiz1);
title('horizental edge processing histogram');
xlabel('column number');
ylabel('difference');
%applying low pass filter (histogram become smooth)
disp('passing histogram through low pass filter');
sum=0;
horiz=horiz1;
for i=21:(col-21)
sum=0;
for j=(i-20):(i+20)
sum=sum+horiz1(j);
end
horiz(i)=sum/41;
end
subplot(3,1,2);
plot(horiz);
title('histogram after passing through low pass filter');
xlabel('column number');
ylabel('difference');
% Filter out Horizontal Histogram Values by applying Dynamic Threshold
disp('Filter out Horizontal Histogram...');
for i = 1:col
if(horiz(i) < average)
horiz(i) = 0;
for j = 1:row
I(j, i) = 0;
end
end
end
subplot(3,1,3);
plot (horiz);
title('Histogram after Filtering');
xlabel('column Number');
ylabel('difference');
%%process in vertical direction
difference = 0; total_sum = 0; difference = uint32(difference); disp('Processing Edges Vertically...'); maximum = 0; max_vert = 0; vert1(i)=0; for i = 2:row sum = 0; for j = 2:col if(I(i, j) > I(i, j-1)) difference = uint32(I(i, j) - I(i, j-1)); end if(I(i, j) I(i, j-1)) difference = uint32(I(i, j-1) - I(i, j)); end if(difference > 20) sum = sum + difference; end end vert1(i) = sum; % Find Peak in Vertical Histogram if(sum > maximum) max_vert = i; maximum = sum; end total_sum = total_sum + sum; end average = total_sum / row; figure(6) subplot(3,1,1); plot (vert1); title('Vertical Edge Processing Histogram'); xlabel('Row Number'); ylabel('Difference'); % Smoothen the Vertical Histogram by applying Low Pass Filter disp('Passing Vertical Histogram through Low Pass Filter...'); sum = 0; vert = vert1; for i = 21:(row-21) sum = 0; for j = (i-20):(i+20) sum = sum + vert1(j); end vert(i) = sum / 41; end subplot(3,1,2); plot (vert); title('Histogram after passing through Low Pass Filter'); xlabel('Row Number -'); ylabel('Difference ->'); % Filter out Vertical Histogram Values by applying Dynamic Threshold disp('Filter out Vertical Histogram...'); for i = 1:row if(vert(i) < average) vert(i) = 0; for j = 1:col I(i, j) = 0; end end end subplot(3,1,3); plot (vert); title('Histogram after Filtering'); xlabel('Row Number ->'); ylabel('Difference ->'); figure(7); imshow(I);
%%finding probable number plate j=1; for i=2:col-2 if(horiz(i)~=0&&horiz(i-1)==0&&horiz(i+1)==0) column(j) = i; column(j+1) = i; j = j + 2; elseif((horiz(i) ~= 0 && horiz(i-1) == 0) (horiz(i) ~= 0 && horiz(i+1) == 0)) column(j) = i; j = j+1; end end j = 1; for i = 2:row-2 if(vert(i) ~= 0 && vert(i-1) == 0 && vert(i+1) == 0) row1(j) = i; row1(j+1) = i; j = j + 2; elseif((vert(i) ~= 0 && vert(i-1) == 0) (vert(i) ~= 0 && vert(i+1) == 0)) row1(j) = i; j = j+1; end end [temp column_size] = size (column); if(mod(column_size, 2)) column(column_size+1) = col; end [temp row_size] = size (row1); if(mod(row_size, 2)) row1(row_size+1) = row; end %% Region of Interest Extraction %Check each probable candidate for i = 1:2:row_size for j = 1:2:column_size % If it is not the most probable region remove it from image if(~((max_hori >= column(j) && max_hori <= column(j+1)) && (max_vert >=row1(i) && max_vert <= row1(i+1)))) %This loop is only for displaying proper output to User for m = row1(i):row1(i+1) for n = column(j):column(j+1) I(m, n) = 0; end end end end end figure(8); imshow(I);

Answers (1)

Image Analyst
Image Analyst on 18 Oct 2013
What do you mean by "detect the numbers"? Do you mean just being able to threshold the plate to get a binary image of the numbers and letters? Or do you mean to take it a step further and actually do OCR on the binary image to identify the actual numbers and letters?
  4 Comments
Image Analyst
Image Analyst on 18 Oct 2013
I don't understand exactly what you're saying - it could be anything from saying you need to crop out some part of the image, to saying you want to perform image segmentation, to saying you want to perform "image understanding". All different things, going in order of complexity from simple (cropping) to very complicated (understanding). You might be doing all three on the same image. For example you could be doing segmentation to find the license place, then you could crop the image to extract only the license plate, then you could do OCR to identify that the characters on the license plate are "123 xyz", then you could look at the whole image again to "understand" that the image is of an Indian man driving a red Ford Fusion that has a license plate that belongs to a car that is not stolen.

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!