How to decide the best threshold to convert RGB image to Binary

2 views (last 30 days)
Hi,
my project is to make an automatic plate recognition system my code consists of 2 parts: 1- extracts the the plate from the recorded image. 2- extracts the numbers from the plate , my problem is to find the best threshold for the recorded image in which the numbers of plate is clear so i can identify it so here is my code:
tic
clc;
clear all;
% the user enters the dimension of the plate (i.e: the distance from camera)
U=input('enter The Width of the Plate(in integer value):');
T=input('enter The Height of the plate(only integers value):');
tic
I = imread ('82.JPG');
imagen=I;
% searching for the best threshold to convert my RGB image to Binary
% i found by experiment that Binary images that have clear %numbers ,its threshold lies in the range of 0.3-->0,7
imagen1 =~im2bw(imagen,0.3);
imagen1=imclearborder(imagen1,26);
imagen1 = bwareaopen(imagen1,30);
lp1=lpcropv(imagen1,U,T); % lpCrop is a function give it a binary image %and returns the plate only by finding the maximum edge density
imagen1=lp1;
stats1 = regionprops(imagen1);
figure; imshow(imagen1);
imagen2 =~im2bw(imagen,0.4);
imagen2=imclearborder(imagen2,26);
imagen2 = bwareaopen(imagen2,30);
lp2=lpcropv(imagen2,U,T);% lpCrop is a function give it a binary % image and returns the plate only by finding the maximum edge density
imagen2=lp2;
stats2 = regionprops(imagen2);
figure; imshow(imagen2);
imagen3 =~im2bw(imagen,0.5);
imagen3=imclearborder(imagen3,26);
imagen3 = bwareaopen(imagen3,30);
lp3=lpcropv(imagen3,U,T);% lpCrop is a function give it a binary % image and returns the plate only by finding the maximum edge density
imagen3=lp3;
stats3 = regionprops(imagen3);
figure; imshow(imagen3);
imagen4 =~im2bw(imagen,0.6);
imagen4=imclearborder(imagen4,26);
imagen4 = bwareaopen(imagen4,30);
lp4=lpcropv(imagen4,U,T);% lpCrop is a function give it a binary % image and returns the plate only by finding the maximum edge density
imagen4=lp4;
stats4 = regionprops(imagen4);
figure; imshow(imagen4);
imagen5 =~im2bw(imagen,0.7);
imagen5=imclearborder(imagen5,26);
imagen5 = bwareaopen(imagen5,30);
lp5=lpcropv(imagen5,U,T);% lpCrop is a function give it a binary % image and returns the plate only by finding the maximum edge density
imagen5=lp5;
stats5 = regionprops(imagen5);
figure; imshow(imagen5);
% here i want to make a set of tests to know which image from images that generated above in which its numbers are clear
% here this what i use to pass the plate image to extract the numbers
imagen=I;
figure; imshow(imagen);
stats = regionprops(imagen);
for index=1:length(stats)
if stats(index).Area >= ceil((75/250)*U) && stats(index).Area < ceil((950/250)*U) && stats(index).BoundingBox(3) < ceil((90/250)*U) && stats(index).BoundingBox(3) >ceil((5/250)*U)
x = ceil(stats(index).BoundingBox(1));
y= ceil(stats(index).BoundingBox(2));
widthX = floor(stats(index).BoundingBox(3)-1);
widthY = floor(stats(index).BoundingBox(4)-1);
if y-ceil((15/100)*T)<1
w=1;
else
w=y-ceil((15/100)*T);
end
if y+widthY+ceil((20/100)*T)>T+1
ww=T+1;
else
ww=y+widthY+ceil((20/100)*T);
end
if x-ceil((7/250)*U)<1
k=1;
else
k=x-ceil((7/250)*U);
end
if x+widthX+ceil((7/250)*U)>U+1
kk=U+1;
else
kk=x+widthX+c*eil((7/250)*U);
end
subimage(index) = {imagen(w:ww,k:kk,:)};
g=cell2mat(subimage(index));
figure; imshow(g);
end
end
toc

Answers (1)

Image Analyst
Image Analyst on 1 Jul 2012
Edited: Image Analyst on 1 Jul 2012
This code is of no use without your image. It may or may not work well with your image. Even if it does work well with your image, or can be modified to work well, there is no telling whether it will work well with any other images, say for images of license plates of different sizes, orientations, lighting, and on different colored cars. For more robust algorithms that work (at least in some situations that have been published in articles), see VisionBib: http://iris.usc.edu/Vision-Notes/bibliography/motion-f726.html#License%20Plate%20Recognition,%20Extraction,%20Analysis
To upload an image, try tinypic.com or one of the others listed here: http://www.mathworks.com/matlabcentral/answers/7924-where-can-i-upload-images-and-files-for-use-on-matlab-answers Be sure to upload the image, not a screenshot, a .gz file, a tar file, a .mat file, or a .fig file. Make sure I can get to it without signing up, clicking several times, or any other annoyances.
  7 Comments
vinod ch
vinod ch on 2 Mar 2014
what is the use of " stats = regionprops(imagen); " i mean what output it returns us
Image Analyst
Image Analyst on 2 Mar 2014
Edited: Image Analyst on 2 Mar 2014
regionprops returns a structure array. Each structure in the array is a structure with the members being the various measurements you asked it to make. You can turn it into a table, which you might find more convenient, with struct2table(), if you have MATLAB Release R2013b. See Steve's latest blog on the topic: http://blogs.mathworks.com/steve/2014/02/04/regionprops-tables-and-struct2table/

Sign in to comment.

Categories

Find more on Animation in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!