MATLAB: How do i identify the background of binary image

background identificationImage Processing Toolbox

i have a binary image and I want to identify the background of the image? the image is bellow.

Best Answer

In your case, the background is white. So you already have a background mask and you just need to tell us what "remove" means to you. Do you want to blacken it in the original image? If so, just do
% Mask the image using bsxfun() function to multiply the mask by each channel individually.
maskedRgbImage = bsxfun(@times, rgbImage, cast(~mask, 'like', rgbImage));
You can also use a gray scale image instead of rgbImage in the above code. Or, simply do
grayImage(mask) = 0;