How to determine the aspect ratio of the detected components and throw the components which does not meet the threshold
2 次查看(过去 30 天)
显示 更早的评论
I have a code attached to which does the bounding box on rgb image. First I convert yellow portion to white and rest all to black. then mask it to find the bounding box. How to determine the aspect ratio of the detected components(white image) and throw the components which does not meet the threshold.
0 个评论
采纳的回答
Madhav Thakker
2020-8-20
Hi
I’m assuming you want to extract the bounding box from the binarized image and then calculate the aspect ratio of the detected components for further processing.
After getting the binarized image from yellow.m, you can use imdilate with a structuring element as ones(19) to merge all the white components. After that you can just use regionprops to get the region of the detected component. I am also attaching the code for easy understanding.
Hope this helps.
I = imread('fogg1.jpg');
J = rgb2ycbcr(I);
CB = J(:,:,2);
histCB = imhist(CB)/numel(CB);
CCB = zeros(size(histCB));
for j = 1:length(CCB)
CCB(j) = sum(histCB(1:j));
end
inx = find(CCB < 0.01,1,'last');
B = CB <= inx-1;
se = ones(19);
dilated = imdilate(B, se);
info = regionprops(dilated,'Boundingbox') ;
imshow(dilated)
hold on
for k = 1 : length(info)
BB = info(k).BoundingBox;
rectangle('Position', [BB(1),BB(2),BB(3),BB(4)],'EdgeColor','r','LineWidth',2) ;
end
lower_left_corner = [BB(1), BB(2)];
width = BB(3);
height = BB(4);
For more information, refer to imdilate MATLAB documentation - https://in.mathworks.com/help/images/ref/imdilate.html
0 个评论
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!