how can i select labeled images that are touching the x axis?
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
i have some labeled objects in an image,is it possible to select only the ones which are connected to the x axis?forexample in this picture the ones i want to choose are the 2 orange ones which are touching the x axis
0 commentaires
Réponse acceptée
Image Analyst
le 12 Avr 2015
To get rid of blobs that are touching the edge of the image you can do this:
binaryImage = imclearborder(binaryImage);
That would give the green and blue blobs. Now if you wanted to get just the orange ones and not the green and blue ones, then you have to subtract that from the original image
binaryImage = binaryImage - imclearborder(binaryImage);
or, you can use the xor() function
binaryImage = xor(binaryImage, imclearborder(binaryImage));
This gets extracts the blobs touching any border. If you want only those on the bottom edge, then there is a few more steps. Let me know if that's required.
5 commentaires
Image Analyst
le 30 Mai 2015
To get rid of objects touching just one border is simple. Simply store the 3 edges of the image that you want to keep. Then zero out those 3 edges and call imclearborder(). Then restore the 3 edges that you zeroed out. Let's say you wanted to delete blobs touching the bottom edge only. Then
% Save 3 edges.
topEdge = binaryImage(1, :);
leftEdge = binaryImage(:, 1);
rightEdge = binaryImage(:, end);
% Zero 3 edges.
binaryImage(1, :) = false;
binaryImage(:, 1) = false;
binaryImage(:, end) = false;
% Get rid of blob(s) touching bottom edge
binaryImage = imclearborder(binaryImage);
% Restore the 3 edges.
binaryImage(1, :) = topEdge;
binaryImage(:, 1) = leftEdge ;
binaryImage(:, end) = rightEdge ;
You could build all that into a function where you pass in the edge(s) you want to remove from.
Plus de réponses (0)
Voir également
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!