Overlay Images Using Binary Mask
This example shows you how to overlay one image on another image using a binary mask.
Example Model
Open the Simulink® model.
modelname = 'ex_blkCompositingMask.slx';
open_system(modelname)
This model reads two input binary images using Image From File blocks with their File name parameters set to text.png
and logo.tif
, respectively.
To overlay one image over another image and perform masking, the model uses these parameters for the Compositing block:
Operation —
Binary mask
Mask source —
Input port
Location source —
Specify via dialog
Location [x y] —
[19 89]
This model overlays the input Image2 on Image1. Location [x y] parameter specify the row and column coordinates in Image1 on which the upper left corner pixel of Image2 has to be positioned.
The Constant block specifies a 2-D binary mask, the same size as the image input to Image2, to the Mask port of the Compositing block.
Simulate the Model
Run the model. The Video Viewer block display the input images, the mask, and the masked output image.
sim(modelname);