An object with the biggest amount of scope in the Binary image

3 ビュー (過去 30 日間)
Felix
Felix 2013 年 9 月 12 日
Hello, I have a binary image with n white objects (not connected). How can I leave only the object with the biggest amount of scope in the picture I can do it by - bwareaopen, but in this way I have to know approximate size of an object. sorry for my english. thnx

採用された回答

Image Analyst
Image Analyst 2013 年 9 月 13 日
Try this:
grayImage = imread('coins.png');
subplot(2,2,1);
imshow(grayImage);
binaryImage = grayImage > 100;
binaryImage = imfill(binaryImage, 'holes'); % Fill holes.
[labeledImage, numObjects] = bwlabel(binaryImage);
stats = regionprops(labeledImage,'Area');
allAreas = [stats.Area]
[~, indexOfLargest] = max(allAreas);
largestBlob = ismember(labeledImage, indexOfLargest)>0;
subplot(2,2,2);
imshow(largestBlob);
title('Largest');
keeperIndexes = 1:numObjects;
keeperIndexes(indexOfLargest) = [];
binaryImage2 = ismember(labeledImage, keeperIndexes)>0;
subplot(2,2,3);
imshow(binaryImage2);
title('All Except Largest');

その他の回答 (2 件)

Adam Filion
Adam Filion 2013 年 9 月 12 日
編集済み: Adam Filion 2013 年 9 月 12 日
If you have Image Processing Toolbox you can use the function regionprops. It comes out to something like this, where tm is the binary image.
cc = bwconncomp(tm);
stats = regionprops(cc,'Area');
A = [stats.Area];
[~,biggest] = max(A);
tm(labelmatrix(cc)~=biggest) = 0;
You can watch a recorded presentation that steps through a similar example here:
  2 件のコメント
Felix
Felix 2013 年 9 月 12 日
編集済み: Image Analyst 2013 年 9 月 13 日
Thanks for the help, it close enough to what I asked, however, it erased all the small arias except the closest ones to the object . can you tall me why is that? sorry i can't upload an image, can i send it to your e-mail?
Image Analyst
Image Analyst 2013 年 9 月 13 日
編集済み: Image Analyst 2013 年 9 月 13 日
Try uploading an image to http://snag.gy or http://tinypic.com.

サインインしてコメントする。


Sean de Wolski
Sean de Wolski 2013 年 9 月 17 日
Good timing, I just posted this function a few minutes ago!

カテゴリ

Help Center および File ExchangeImage Segmentation and Analysis についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by