Background removal in matlab

9 views (last 30 days)
RYAN MTHEMBU
RYAN MTHEMBU on 12 Dec 2021
Commented: Image Analyst on 12 Dec 2021
Hi people.please help me with the following question: "using an input colour image and the provided ROI mask, remove the background from the image. Retain only the approximate ROI. treat the mask as ground truth. The ROI mask is only an approximation and not meant to be taken as being exact.
  1 Comment
Image Analyst
Image Analyst on 12 Dec 2021
Please tell us what you mean by "remove the background". You in general cannot remove pixels from an image, though you can set them to some color, like black or white. For example if you had a donut, you can make the background black or white, and you could crop out a rectangular sub-image of the bounding box of the donut, but you can't have the center of the donut or the pixels outside of it be "removed" or "missing" since arrays cannot have missing elements. You can set those locations to some certain color, or even NaN or 0 or inf or whatever but you can't just get rid of them.
% Mask the image using bsxfun() function to multiply the mask by each channel individually. Works for gray scale as well as RGB Color images.
maskedRgbImage = bsxfun(@times, rgbImage, cast(mask, 'like', rgbImage));

Sign in to comment.

Answers (1)

RYAN MTHEMBU
RYAN MTHEMBU on 12 Dec 2021
Oh hey . Thanks for the response.. I've managed to figure that one out. But if you may I have another problem that I'm currently struggling with. I'm given three binary images each of it's own shape. Now I want to put these shapes on top of each other in an order, say, Triangle on top, Circle in the middle and square at the bottom. How do I even begin to do that ? No built in functions may be used

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!