how to cut part of an image ?
Mostra commenti meno recenti
I have a image

I have created boundary for the necessary part of my image using bwboundaries();

Now i want to remove rest of the image and make it black like :

how will i do this?
Risposta accettata
Più risposte (2)
Ahmet Cecen
il 4 Mag 2015
0 voti
This might not be the most robust way to do it, but create a mask matrix with that red boundary as 1s and everywhere else 0. Then use imfill with holes argument to fill inside that boundary, then multiply the mask with the image element-wise.
Image Analyst
il 4 Mag 2015
Assuming it's a gray scale image, not color, create a mask and assign it
mask = grayImage > 138; % Whatever value gives you the flower.
mask = bwareaopen(mask, 1000); % Get rid of any small specks that might be there.
maskedImage = grayImage; % Initialize
maskedImage(~mask) = 0; % Zero outside the mask.
If it's a color image, you can mask like this:
% Mask the image using bsxfun() function
maskedRgbImage = bsxfun(@times, rgbImage, cast(mask, class(rgbImage)));
Categorie
Scopri di più su Image Segmentation in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
