An object with the biggest amount of scope in the Binary image
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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
0 Kommentare
Akzeptierte Antwort
Image Analyst
am 13 Sep. 2013
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');
Weitere Antworten (2)
Adam Filion
am 12 Sep. 2013
Bearbeitet: Adam Filion
am 12 Sep. 2013
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:
Sean de Wolski
am 17 Sep. 2013
Good timing, I just posted this function a few minutes ago!
0 Kommentare
Siehe auch
Kategorien
Mehr zu Image Segmentation and Analysis finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!