필터 지우기
필터 지우기

Detect largest bounding box and applying centroid.

조회 수: 4 (최근 30일)
Sarmad Paracha
Sarmad Paracha 2018년 12월 6일
댓글: Sarmad Paracha 2019년 3월 3일
I have written this code to use bounding box and centroid properties. Due to noise of the image i am getting many unwated boxes and centroids. so i want to edit this code so that only the biggest bounded box is shown and centroid is shown only on that box. i need help in this regards.
binaryY = im2bw(rgb2gray(F));
Ibw1 = imfill(binaryY,'holes');
K1 = medfilt2(Ibw1);
subplot(2,2,2);
imshow(K1, []);
%centrod
Ilabel1 = bwlabel(K1);
stat = regionprops(Ilabel1,'centroid');
subplot(2,2,3);
imshow(Im1); hold on;
for x = 1: numel(stat)
plot(stat(x).Centroid(1),stat(x).Centroid(2),'r+');
end
% Make sure image is not artificially stretched because of screen's aspect ratio.
[L,num]=bwlabel(K1);
bboxes=regionprops(L,'BoundingBox');
subplot(2,2,4)
imshow(Im1),title('Bounding Box');
hold on;
for k=1:length(bboxes)
CurrBB=bboxes(k).BoundingBox;
rectangle('position',[CurrBB(1),CurrBB(2),CurrBB(3),CurrBB(4)],'EdgeColor','g','LineWidth',2);
end
hold off;
FIRE.png
  댓글 수: 2
Walter Roberson
Walter Roberson 2019년 3월 2일
regionprops the Area as well. max [stat.Area] to find the index of the largest .
Sarmad Paracha
Sarmad Paracha 2019년 3월 3일
Thank you for your response .
but using regionprops for the area i can find max area of the blobs but how can i use that to remove all the other boxes and centroids... Please help .A sample may help me alot. Thanks

댓글을 달려면 로그인하십시오.

채택된 답변

Image Analyst
Image Analyst 2019년 3월 3일
Near the top, do this:
Ibw1 = bwareafilt(Ibw1, 1); % Extract largest blob only.
Then continue with the rest of your code, though I don't believe the median filter is needed.
  댓글 수: 1
Sarmad Paracha
Sarmad Paracha 2019년 3월 3일
Oh man Thank You very much.... That solved my problem ...

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

제품


릴리스

R2017a

Community Treasure Hunt

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

Start Hunting!

Translated by