| Video and Image Processing Blockset™ | ![]() |
Combine pixel values of two images, overlay one image over another, or highlight selected pixels
Text & Graphics

You can use the Compositing block to combine two images, where each pixel of the output image is a linear combination of the pixels in each input image. This process is defined by the following equation:
![]()
The opacity factor, X, where
, defines the amount by which
to scale each pixel value before combining them.
You can use the Compositing block to overlay a Image 2 over Image 1. The masking factor and the location determine which Image 1 pixels are overwritten. The masking factor(s) can be 0 or 1, where 0 corresponds to not overwriting pixels and 1 corresponds to overwriting pixels.
You can use the Compositing block to highlight selected pixels in the input image. Use a binary image, input at the Mask port, to specify which pixels to highlight.
Note This block supports intensity and color images on its ports. |
| Port | Input/Output | Supported Data Types | Complex Values Supported |
|---|---|---|---|
Image 1 | M-by-N matrix of intensity values or an M-by-N-by-P color video signal where P is the number of color planes |
| No |
Image 2 | M-by-N matrix of intensity values or an M-by-N-by-P color video signal where P is the number of color planes | Same as Image 1 port | No |
Factor | Scalar or matrix of opacity or masking factor |
| No |
Mask | Binary image that specifies which pixels to highlight | Same as Factor port When the Operation parameter is set to Highlight selected pixel, the input to the Mask port must be a Boolean data type. | No |
Location | Two-element vector that specifies the position of the upper-left corner of the image input at port I2 |
| No |
Output | Vector or matrix of intensity or color values | Same as Image 1 port | No |
Use the Operation parameter to specify the operation you want the block to perform. If you choose Blend, the block linearly combines the pixels of one image with another image. If you choose Binary mask, the block overwrites the pixel values of one image with the pixel values of another image. If you choose Highlight selected pixel, the block uses the binary image input at the Mask port to determine which pixels are set to the maximum value supported by their data type. For example, for every 1 in the binary image, the block sets the corresponding pixel in input image to the maximum value supported by its data type. For every 0 in the binary image, the block leaves the pixel value alone.
If, for the Operation parameter, you choose Blend, the Opacity factor(s) source parameter appears on the dialog box. Use this parameter to indicate where to specify the opacity factor(s).
If you choose Specify via dialog, the Opacity factor(s) parameter appears on the dialog box. Use this parameter to define the amount by which the block scales each I2 pixel value before combining them with the Image 1 pixel values. You can enter a scalar value used for all pixels or a matrix of values that is the same size as Image 2.
If you choose Input port, the Factor port appears on the block. The input to this port must be a scalar or matrix of values as described for the Opacity factor(s) parameter. If the input to the Image 1 and Image 2 ports is floating point, the input to this port must be the same floating-point data type.
If, for the Operation parameter, you choose Binary mask, the Mask source parameter appears on the dialog box. Use this parameter to indicate where to specify the masking factor(s).
If you choose Specify via dialog, the Mask parameter appears on the dialog box. Use this parameter and the location of the I2 image to define which pixels are overwritten. You can enter 0 or 1, which is used for all pixels in I2, or a matrix of 0s and 1s that defines the factor for each I2 pixel.
If you choose Input port, the Factor port appears on the block. The input to this port must be a 0 or 1 whose data type is Boolean or a matrix of 0s or 1s whose data type is Boolean as described for the Mask parameter.
Use the Location source parameter to specify where to enter the zero-based location of the upper-left corner of the image input at port I2.
If you choose Specify via dialog, the Location [row column] parameter appears on the dialog box. Enter a two-element vector that specifies the row and column position of the upper-left corner of the image input at port Image 2 relative to the upper-left corner of the image input at port Image 1. Positive values move the image down and to the right; negative values move the image up and to the left. If the first element is greater than the number of rows in the Image 1 matrix, the value is clipped to the total number of rows. If the second element is greater than the number of columns in the Image 1 matrix, the value is clipped to the total number of columns.
If you choose Input port, the Location port appears on the block. The input to this port must be a two-element vector as described for the Location [row column] parameter.
If, for the Operation parameter, you choose Highlight selected pixels, the Location source parameter appears on the dialog box. This parameter is described above.
The following diagram shows the data types used in the Compositing block for fixed-point signals. It is only applicable when the Operation parameter is set to Blend.

You can set the product output, accumulator, and output data types in the block mask as discussed in the next section.
The Main pane of the Compositing dialog box appears as shown in the following figure.

Specify the operation you want the block to perform. If you choose Blend, the block linearly combines the pixels of one image with another image. If you choose Binary mask, the block overwrites the pixel values of one image with the pixel values of another image. If you choose Highlight selected pixel, the block uses the binary image input at the Mask port to determine which pixels are set to the maximum value supported by their data type.
Indicate where to specify the opacity factor(s). Your choices are Specify via dialog and Input port. This parameter is visible if, for the Operation parameter you choose Blend.
Define the amount by which the block scales each pixel value before combining them. You can enter a scalar value used for all pixels or a matrix of values that defines the factor for each pixel. This parameter is visible if, for the Opacity factor(s) source parameter you choose Specify via dialog. Tunable.
Indicate where to specify the masking factor(s). Your choices are Specify via dialog and Input port. This parameter is visible if, for the Operation parameter you choose Binary mask.
Define which pixels are overwritten. You can enter 0 or 1, which is used for all pixels, or a matrix of 0s and 1s that defines the factor for each pixel. This parameter is visible if, for the Mask source parameter you choose Specify via dialog. Tunable.
Use this parameter to specify where to enter the location of the upper-left corner of the image input at port I2. Your choices are Specify via dialog and Input port.
Enter a two-element vector that specifies the row and column position of the upper-left corner of the image input at port Image 2 relative to the upper-left corner of the image input at port Image 1. This parameter is visible if, for the Location source parameter you choose Specify via dialog. Tunable.
The Fixed-point pane of the Compositing dialog box appears as follows. These parameters are applicable only when the Operation parameter is set to Blend.

Select the rounding mode for fixed-point operations.
Select the overflow mode for fixed-point operations.
Choose how to specify the word length and fraction length of the opacity factor:
When you select Same word length as input, these characteristics match those of the input to the block.
When you select Specify word length, enter the word length of the opacity factor.
When you select Binary point scaling, you can enter the word length of the opacity factor, in bits.
When you select Slope and bias scaling, you can enter the word length, in bits, of the opacity factor. The bias of all signals in the Video and Image Processing Blockset™ is 0.

As depicted in the previous figure, the output of the multiplier is placed into the product output data type and scaling. Use this parameter to specify how to designate this product output word and fraction lengths.
When you select Same as first input, these characteristics match those of the input to the block.
When you select Binary point scaling, you can enter the word length and the fraction length of the product output, in bits.
When you select Slope and bias scaling, you can enter the word length, in bits, and the slope of the product output. The bias of all signals in the Video and Image Processing Blockset is 0.

As depicted in the previous figure, inputs to the accumulator are cast to the accumulator data type. The output of the adder remains in the accumulator data type as each element of the input is added to it. Use this parameter to specify how to designate this accumulator word and fraction lengths.
When you select Same as product output, these characteristics match those of the product output.
When you select Same as first input, these characteristics match those of the input to the block.
When you select Binary point scaling, you can enter the word length and the fraction length of the accumulator, in bits.
When you select Slope and bias scaling, you can enter the word length, in bits, and the slope of the accumulator. The bias of all signals in the Video and Image Processing Blockset is 0.
Choose how to specify the word length and fraction length of the output of the block:
When you select Same as first input, these characteristics match those of the input to the block.
When you select Binary point scaling, you can enter the word length and the fraction length of the output, in bits.
When you select Slope and bias scaling, you can enter the word length, in bits, and the slope of the output. The bias of all signals in the Video and Image Processing Blockset is 0.
Select this parameter to prevent any fixed-point scaling you specify in this block mask from being overridden by the autoscaling tool in the Fixed-Point Tool. For more information, see fxptdlg, a reference page on the Fixed-Point Tool in the Simulink® documentation.
Video and Image Processing Blockset |
![]() | Color Space Conversion | Contrast Adjustment | ![]() |
| © 1984-2008- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |