how can I remove all the objects that are not connected to my central object in a binary image?
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
jack nn
am 8 Jun. 2015
Kommentiert: sajid rahim
am 6 Jul. 2017
I have a binary Image that includes some objects. the shape of these objects are irregular. the object that is in central of this image is important for me . how can I remove all the objects that are not connect to my central object? for example if this is my image:
I want to have this as output:
I have a lot of images that are like these example and I should separate central object.so I should find a general way for this.
thanks for your attention
1 Kommentar
Akzeptierte Antwort
Image Analyst
am 8 Jun. 2015
Just find the centroids with regionprops() and then find the distances from each blob to the center of the image. Then use min to find the index of the blob closest to the middle. Here is some untested code just off the top of my head.
% Give each blob a unique ID number (a label).
labeledImage = bwlabel(binaryImage);
% Get centroids.
measurements = regionprops(labeledImage, 'Centroid');
centroids = [measurements.Centroid];
xCentroids = centroids(1:2:end);
yCentroids = centroids(2:2:end);
% Find distances to middle of image
distances = sqrt((columns/2-xCentroids).^2 + (rows/2-yCentroids).^2);
% Find the min distance
[minDistance, indexOfMin] = min(distances);
% Extract binary image of only the closest blob
centralBlob = labeledImage == indexOfMin;
imshow(centralBlob);
4 Kommentare
Image Analyst
am 9 Jun. 2015
You're welcome. If it works, then can you click the "Accept this Answer" link? Thanks in advance.
sajid rahim
am 6 Jul. 2017
Hi jack nn i try the codes but not work proprely I think I may make some mistake... sooo plz send me the code plzzzzzzzzzz
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Get Started with Image Processing Toolbox 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!