Eliminating different regions based on height/width ratio calculated by boundingbox
2 次查看(过去 30 天)
显示 更早的评论
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....
0 个评论
回答(4 个)
Sean de Wolski
2011-3-3
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
Sean de Wolski
2011-3-4
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 个评论
Sean de Wolski
2011-3-4
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.
0 个评论
Brett Shoelson
2011-3-4
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 个评论
Brett Shoelson
2011-3-5
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
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Image Segmentation and Analysis 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!