MATLAB: How to cut part of an image

image analysisimage processingimage segmentation

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?

Best Answer

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.