Eliminating different regions based on height/width ratio calculated by boundingbox

I am currently doing a project on License plate recognition. In its first step we have to first locate the license plate by eliminating other unwanted areas. The license plate being more horizontal the height/width ratio of box containing plate will be lower than 1 always. So i want to remove other areas whose height/width ratio is less than 1. I am calculating height/width ratio by BoundingBox as follows
S = regionprops(labeledimage , 'BoundingBox');
for i=1:numberofregions
bw2 = ismember(L,find(([S(i).BoundingBox(4)]/[S(i).BoundingBox(3)])<.3));
end
but this is not working. There are 2 regions in the image whose height/width ratio are 1.7759 and 0.2968. So the o/p is expected to be the region containing the height/width ratio of 0.2968 by the condition but its taking the first one i.e. 1.7759.
Also if the non-plate region appears first in the image then it gives o/p as above and if non-plate region appears after the plate region then it removes both the areas. Please help me immediately....

Answers (4)

Extract the Bounding Box of all of them, do the comparison, set the bad ones to false.
CC = bwconncomp(I);
RP = regionprops(CC);
Bboxes = {RP(:).BoundingBox};
idx = cellfun(@(x)(x(4)/x(3))<.3,Bboxes);
I(cell2mat(CC.PixelIdxList(~idx)')) = false; %Set not above to false

2 Comments

Hey thanks for the answer but my matlab doesnt have the bwconncomp file. Can you provide me that file.
I have Matlab7.0(R14) It doesnt support the bwconncomp function.
See my profie picture. Its the binary image and i want remove the first area and keep the area in the bottom which is the probable no. plate area. This has to be done by calculating and comparing Height/width ratio of each area. Please tell me how would you do this without bwconncomp function.

Sign in to comment.

Then you'll need to write something similar to bwconncomp to use the above. Or you can make a few modifications to and use bwlabel. Personally, I despise bwlabel and avoid it at all costs. Here's a few lines that generate the same thing as bwconncomp, given a label image L.
Maybe:
L = bwlabel(I);
idxmat = reshape(1:numel(A),[size(I)]);
CC.PixelIdxList = accumarray(L(L~=0),idxmat(L~=0),[],@(x){x})';
CC.ImageSize = size(I);
CC.NumObjects = length(CC.PixelIdxList);
CC.Connectivity = 8;
RP = regionprops(CC,'BoundingBox');

4 Comments

Thank you very much will try this one.... Anyways here are some images i m working on
http://www.uploadhouse.com/viewfile.php?id=8342021
http://www.uploadhouse.com/viewfile.php?id=8342018
http://www.uploadhouse.com/viewfile.php?id=8342015
Check out by your way if bwconncomp works on these
Hey i got a problem in executing above code.. Whats the A in 2nd line..
There is also error in the3rd line
>> With column vector IND, the third input SZ must be a real full double row vector with two entries.
A should be replaced with I, typo on my part.
sz = size(I)

Sign in to comment.

Actually, given a label matrix you don't even need to use REGIONPROPS to find the boundingbox. You could just use ACCUMARRAY and do the check on length to width ratio in the function call to accumarray. I.e:
idxmat = reshape(1:numel(A),[size(I)]);
idx = accumarray(L(L~=0),idxmat(L~=0),[],isHgtW);
Then write a function isHgtW which accepts a few linear indices, knows the size of the image (perhaps through a global), calls ind2sub and gets the range of heights/range of widths and returns a logical based on this determination. I would probably not go this route, just wanted to throw it out there as an option.
You can also use the 'Eccentricity' property returned by REGIONPROPS. Eccentricity give the ratio of the major axis length to the minor axis length for each object.

3 Comments

Yea i tried that one too but the thing is that in my image there can be regions which are of same size and area but in vertical direction so if i go by eccentricity thing there will be two ellipse one horizontal and one vertical so both may get detected but that will not be the case of height width ratio as height of vertical region will be high and that of the horizontal will be low. I hope you get what i mean
So perhaps you could use regionprops to calculate both eccentricity and orientation, and use both to detect the horizontal objects with the expected eccentricity.
Cheers,
Brett
Hey that seems good... Thanks will try out..

Sign in to comment.

Products

Asked:

on 3 Mar 2011

Community Treasure Hunt

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

Start Hunting!