![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/176594/image.jpeg)
how to cut part of an image ?
조회 수: 8 (최근 30일)
이전 댓글 표시
I have a image
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/149760/image.jpeg)
I have created boundary for the necessary part of my image using bwboundaries();
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/149762/image.jpeg)
Now i want to remove rest of the image and make it black like :
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/149763/image.jpeg)
how will i do this?
댓글 수: 0
채택된 답변
Image Analyst
2015년 5월 5일
OK. Seems like you're having trouble so I made a full blown demo for you. See attached m-file below this image it creates. Be sure to change the folder and image file name to whatever you have on your computer.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/176594/image.jpeg)
댓글 수: 0
추가 답변 (2개)
Ahmet Cecen
2015년 5월 4일
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.
댓글 수: 0
Image Analyst
2015년 5월 4일
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)));
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Image Segmentation and Analysis에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!