MATLAB Answers

0

how to extract the given type of number plates and the characters ?

Latest activity Commented on by Image Analyst
on 23 Nov 2018
I am working on license plate recognition, but I am stuck on how to develop the code for extracting or localizing the rectangular shape of a number plate from the car image .

  0 Comments

Sign in to comment.

1 Answer

Answer by Image Analyst
on 9 Nov 2018
 Accepted Answer

Try the code below. It works for the given image. You'll need to adapt it to handle cars of different colors and different size plates, but at least this gives you a start on the idea.
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 16;
%===============================================================================
% Get the name of the image the user wants to use.
baseFileName = 'anpr3.jpg';
folder = pwd;
fullFileName = fullfile(folder, baseFileName);
% Check if file exists.
if ~exist(fullFileName, 'file')
% The file doesn't exist -- didn't find it there in that folder.
% Check the entire search path (other folders) for the file by stripping off the folder.
fullFileNameOnSearchPath = baseFileName; % No path this time.
if ~exist(fullFileNameOnSearchPath, 'file')
% Still didn't find it. Alert user.
errorMessage = sprintf('Error: %s does not exist in the search path folders.', fullFileName);
uiwait(warndlg(errorMessage));
return;
end
end
%=======================================================================================
% Read in demo image.
rgbImage = imread(fullFileName);
% Get the dimensions of the image.
[rows, columns, numberOfColorChannels] = size(rgbImage)
% Display image.
subplot(2, 2, 1);
imshow(rgbImage, []);
impixelinfo;
axis on;
caption = sprintf('Original Color Image\n%s', baseFileName);
title(caption, 'FontSize', fontSize, 'Interpreter', 'None');
hp = impixelinfo(); % Set up status line to see values when you mouse over the image.
% Set up figure properties:
% Enlarge figure to full screen.
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0 0.05 1 0.95]);
% Get rid of tool bar and pulldown menus that are along top of figure.
% set(gcf, 'Toolbar', 'none', 'Menu', 'none');
% Give a name to the title bar.
set(gcf, 'Name', 'Demo by ImageAnalyst', 'NumberTitle', 'Off')
drawnow;
[mask, maskedRGBImage] = createMask(rgbImage);
% Get the convex hull to get rid of boundary noise (wiggles).
mask = imfill(mask, 'holes');
% Count the blobs
[~, numBlobs] = bwlabel(mask);
% Display the mask image.
subplot(2, 2, 2);
imshow(mask);
caption = sprintf('Color Segmentation Image : %d blobs', numBlobs);
title(caption, 'FontSize', fontSize, 'Interpreter', 'None');
axis on;
drawnow;
% Measure sizes of blobs.
props = regionprops(mask, 'Area', 'Solidity');
allAreas = [props.Area];
subplot(2, 2, 4);
histogram(allAreas, 50);
grid on;
title('Histogram Of Areas', 'FontSize', fontSize);
% Extract only blobs in the 5000-10000 pixel size range
mask = bwareafilt(mask, [1000, 7000]);
% Remove blobs touching border because we assume license plate will be in the field of view, not off of it.
mask = imclearborder(mask);
% Measure bounding boxes of blobs.
props = regionprops(mask, 'BoundingBox');
allBB = [props.BoundingBox];
allWidths = allBB(3:4:end);
allheights = allBB(4:4:end);
aspectRatios = allWidths ./ allheights
% Take only thos where aspect ratio in in the right range - around 2 so in the range 1.5 - 3.
goodBlobIndexes = find(aspectRatios > 1.5 & aspectRatios < 3)
% Extract that/those blobs only:
labeledImage = bwlabel(mask);
mask = ismember(labeledImage, goodBlobIndexes);
% Take the convex hull
mask = bwconvhull(mask);
% Display the mask image.
subplot(2, 2, 3);
imshow(mask);
title('Final Plate Found', 'FontSize', fontSize, 'Interpreter', 'None');
axis on;
drawnow;
% Mask the image using bsxfun() function to multiply the mask by each channel individually.
maskedRgbImage = bsxfun(@times, rgbImage, cast(mask, 'like', rgbImage));
% Display the mask image.
subplot(2, 2, 4);
imshow(maskedRgbImage);
title('Final Plate Found (RGB Image)', 'FontSize', fontSize, 'Interpreter', 'None');
axis on;
drawnow;
fprintf('DONE!\n');
uiwait(helpdlg('Done!'));
function [BW,maskedRGBImage] = createMask(RGB)
%createMask Threshold RGB image using auto-generated code from colorThresholder app.
% [BW,MASKEDRGBIMAGE] = createMask(RGB) thresholds image RGB using
% auto-generated code from the colorThresholder app. The colorspace and
% range for each channel of the colorspace were set within the app. The
% segmentation mask is returned in BW, and a composite of the mask and
% original RGB images is returned in maskedRGBImage.
% Auto-generated by colorThresholder app on 09-Nov-2018
%------------------------------------------------------
% Convert RGB image to chosen color space
I = rgb2hsv(RGB);
% Define thresholds for channel 1 based on histogram settings
channel1Min = 0.004;
channel1Max = 0.998;
% Define thresholds for channel 2 based on histogram settings
channel2Min = 0.000;
channel2Max = 0.102;
% Define thresholds for channel 3 based on histogram settings
channel3Min = 0.399;
channel3Max = 1.000;
% Create mask based on chosen histogram thresholds
sliderBW = (I(:,:,1) >= channel1Min ) & (I(:,:,1) <= channel1Max) & ...
(I(:,:,2) >= channel2Min ) & (I(:,:,2) <= channel2Max) & ...
(I(:,:,3) >= channel3Min ) & (I(:,:,3) <= channel3Max);
BW = sliderBW;
% Initialize output masked image based on input image.
maskedRGBImage = RGB;
% Set background pixels where BW is false to zero.
maskedRGBImage(repmat(~BW,[1 1 3])) = 0;
end

  8 Comments

I do not have that code. I cannot even read Bengali, so I have no reason to have the code. Character segmentation is just identifying blobs where the character is (like thresholding). It is different than "character recognition" which determines which letter of the alphabet is represented by that blob.
For your assignment, are you allowed to just hand in code that someone gives you? Aren't you supposed to code it up yourself??? Did the assignment say "Segment the characters", "Recognize the characters" or "ask someone for their code so you can turn in their code"?
no,there is no problem with other's code, i must submit the reference from where i take it. Then I have to understand the code by myself and then brief him about it.
It's actually charactar recognition, i have to show the charachters on the number plate in notepad of the car's picture.
OK, good luck. You should probably start by emailing the authors in the link I gave to see if any of them will give you MATLAB code for free. Good luck.

Sign in to comment.