How to crop the image?
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/152294/image.png)
- I have above image and I want to crop it such that the white pixels just reach the corners from all sides using Matlab code automatically not manually
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/152295/image.png)
how could I do this...thanks In advance
0 commentaires
Réponse acceptée
Image Analyst
le 18 Juil 2015
Have you run my Image Segmentation Tutorial http://www.mathworks.com/matlabcentral/fileexchange/?term=authorid%3A31862? It goes over that.
labeledImage = bwlabel(binaryImage);
blobMeasurements = regionprops(labeledImage, 'BoundingBox');
% Find the bounding box of each blob.
thisBlobsBoundingBox = blobMeasurements.BoundingBox; % Get list of pixels in current blob.
% Extract out this blob into it's own image.
% I'm assuming just one blob. If you have multiple, see my tutorial.
subImage = imcrop(binaryImage, thisBlobsBoundingBox);
6 commentaires
Image Analyst
le 20 Juil 2015
You should have had this done long long ago - it's not that hard. So I did it for you. See the attached demo.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/183607/image.jpeg)
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Image Processing Toolbox dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!