Error in Iprops=reg​ionprops(f​inal,;Boun​dingBox','​Image')

function numberPlateExtraction
%NUMBERPLATEEXTRACTION extracts the characters from the input number plate image.
f=imread('car3.jpg'); % Reading the number plate image.
f=imresize(f,[400 NaN]); % Resizing the image keeping aspect ratio same.
g=rgb2gray(f); % Converting the RGB (color) image to gray (intensity).
g=medfilt2(g,[3 3]); % Median filtering to remove noise.
se=strel('disk',1); % Structural element (disk of radius 1) for morphological processing.
gi=imdilate(g,se); % Dilating the gray image with the structural element.
ge=imerode(g,se); % Eroding the gray image with structural element.
gdiff=imsubtract(gi,ge); % Morphological Gradient for edges enhancement.
gdiff=mat2gray(gdiff); % Converting the class to double.
gdiff=conv2(gdiff,[1 1;1 1]); % Convolution of the double image for brightening the edges.
gdiff=imadjust(gdiff,[0.5 0.7],[0 1],0.1); % Intensity scaling between the range 0 to 1.
B=logical(gdiff); % Conversion of the class from double to binary.
% Eliminating the possible horizontal lines from the output image of regiongrow
% that could be edges of license plate.
er=imerode(B,strel('line',50,0));
out1=imsubtract(B,er);
% Filling all the regions of the image.
F=imfill(out1,'holes');
% 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(H,100);
% final=bwlabel(final); % Uncomment to make compitable with the previous versions of MATLAB®
% Two properties 'BoundingBox' and binary 'Image' corresponding to these
% Bounding boxes are acquired.
Iprops=regionprops(final,'BoundingBox','Image'); %error
% Selecting all the bounding boxes in matrix of order numberofboxesX4;
NR=cat(1,Iprops.BoundingBox);
% Calling of controlling function.
r=controlling(NR); % Function 'controlling' outputs the array of indices of boxes required for extraction of characters.
if ~isempty(r) % If succesfully indices of desired boxes are achieved.
I={Iprops.Image}; % Cell array of 'Image' (one of the properties of regionprops)
noPlate=[]; % Initializing the variable of number plate string.
for v=1:length(r)
N=I{1,r(v)}; % Extracting the binary image corresponding to the indices in 'r'.
letter=readLetter(N); % Reading the letter corresponding the binary image 'N'.
while letter=='O' || letter=='0' % Since it wouldn't be easy to distinguish
if v<=3 % between '0' and 'O' during the extraction of character
letter='O'; % in binary image. Using the characteristic of plates in Karachi
else % that starting three characters are alphabets, this code will
letter='0'; % easily decide whether it is '0' or 'O'. The condition for 'if'
end % just need to be changed if the code is to be implemented with some other
break; % cities plates. The condition should be changed accordingly.
end
noPlate=[noPlate letter]; % Appending every subsequent character in noPlate variable.
end
fid = fopen('noPlate.txt', 'wt'); % This portion of code writes the number plate
fprintf(fid,'%s\n',noPlate); % to the text file, if executed a notepad file with the
fclose(fid); % name noPlate.txt will be open with the number plate written.
winopen('noPlate.txt')
% Uncomment the portion of code below if Database is to be organized. Since my
% project requires database so I have written this code. DB is the .mat
% file containing the array of structure of all entries of database.
% load DB
% for x=1:length(DB)
% recordplate=getfield(DB,{1,x},'PlateNumber');
% if strcmp(noPlate,recordplate)
% disp(DB(x));
% disp('*-*-*-*-*-*-*');
% end
% end
else % If fail to extract the indexes in 'r' this line of error will be displayed.
fprintf('Unable to extract the characters from the number plate.\n');
fprintf('The characters on the number plate might not be clear or touching with each other or boundries.\n');
end
end
error: numberPlateExtraction Error using fprintf Invalid file identifier. Use fopen to generate a valid file identifier.
??? Error using ==> regionprops>ParseInputs at 837 Use bwlabel(BW) or double(BW) convert binary image to a label matrix before calling regionprops.
Error in ==> regionprops at 114 [L, requestedStats] = ParseInputs(officialStats, varargin{:});
Error in ==> numberPlateExtraction at 30 Iprops=regionprops(final,'BoundingBox','Image');
please help...Thanks! any better code for number plate recognition will be appreciated...

2 Comments

The same above code I got error in r=controlling(NR) in free trail.can you help me sir
@Gayathri Saravanan what version do you have? regionprops() no longer gives an error if the first argument is a binary image instead of a labeled image. But the error above refers to regionprops while youi say your error refers to some function you call controlling(). I suggest you read this link:
and then post your question as a new question in a new/ separate thread.

Sign in to comment.

Answers (1)

Well the error message tells you exactly how to correct it
Use bwlabel(BW)
and what did you do:
% final=bwlabel(final);
You commented out the call to bwlabel(), for some reason. Put it back in like it told you to.

Asked:

on 4 Apr 2017

Commented:

on 22 Jan 2022

Community Treasure Hunt

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

Start Hunting!