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

7 views (last 30 days)
Mayur on 3 Mar 2011
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....

Sean de Wolski on 3 Mar 2011
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 CommentsShowHide 1 older comment
Mayur on 4 Mar 2011
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.

Sean de Wolski on 4 Mar 2011
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');
Sean de Wolski on 7 Mar 2011
A should be replaced with I, typo on my part.
sz = size(I)

Sean de Wolski on 4 Mar 2011
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.

Brett Shoelson on 4 Mar 2011
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.
Mayur on 5 Mar 2011
Hey that seems good... Thanks will try out..