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

2 vues (au cours des 30 derniers jours)
Mayur
Mayur le 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....

Réponses (4)

Sean de Wolski
Sean de Wolski le 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 commentaires
Mayur
Mayur le 4 Mar 2011
Hey thanks for the answer but my matlab doesnt have the bwconncomp file. Can you provide me that file.
Mayur
Mayur le 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.

Connectez-vous pour commenter.


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

Connectez-vous pour commenter.


Sean de Wolski
Sean de Wolski le 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
Brett Shoelson le 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.
  3 commentaires
Brett Shoelson
Brett Shoelson le 5 Mar 2011
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
Mayur
Mayur le 5 Mar 2011
Hey that seems good... Thanks will try out..

Connectez-vous pour commenter.

Catégories

En savoir plus sur Image Segmentation and Analysis dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by