MATLAB: Add “virtual” background to masked Image

background replacementImage Processing ToolboxmaskingMATLAB

Hey Guys,
I have a question. I wrote a program which extracts the background from an Image (used difference). Then I created the masked Image.
Now I want to add a "virtual" background for example a landscape rgb image (same size as masked one) and place it as a new background for the masked image. So the black background from the masked image should contain/be now the landscape with the foreground of the masked image. It should place the foreground from the masked image at the bottom center of the virtual background
Thank you guys

Best Answer

Try this
rgbImage(maskImage) = backgroundImage(maskImage);
where mask image is the 3-D binary image of the part to be replaced by the background.