imblend
Description
fine-tunes the image blending using one or more optional name-value arguments, in addition
to any combination of input arguments from previous syntaxes. For example,
I
= imblend(___,Name=Value
)Mode="Guided"
specifies to use the guided mode for image
blending.
Examples
Blend Images Using Alpha Blending
Load an image into the workspace as the background image.
bg = imread("cameraman.tif");
figure
imshow(bg)
Create a foreground image of a digital object to blend, as augmented reality, with the cameraman scene.
fg = ones(size(bg)); fg(200:225,200:225) = 0; figure imshow(fg)
Blend the foreground image with the background image using alpha blending. Visualize the blended image.
I = imblend(fg,bg); figure imshow(I)
To blend only the digital object in the image, create a mask by segmenting the object in the foreground image. Then, perform alpha blending of the foreground and background images with the specified mask and visualize the blended image.
thresh = graythresh(fg); mask = fg <= thresh; figure imshow(mask)
I = imblend(fg,bg,mask); figure imshow(I)
Compare Different Blend Modes
Load an image into the workspace as the background image.
bg = imread("peppers.png");
figure
imshow(bg)
Create a foreground image of a digital object to blend, as augmented reality, with the natural scene.
fg = ones(size(bg,1),size(bg,2)); fg(200:225,200:225) = 0; figure imshow(fg)
Create a mask by segmenting the object in the foreground image.
thresh = graythresh(fg); mask = fg <= thresh;
Blend the foreground image on the background image using the mask and different blend modes. Visualize and compare the blended images from the different blend modes.
Mode
Alpha
creates a partial transparency effect.Mode
Guided
changes the trnasition region between the foreground and background images.Mode
Min
retains the darkest areas in the foreground and background images.Mode
Max
retains the brightest areas in the foreground and background images.Mode
Average
averages the foreground and background images.Mode
Overlay
retains the highlights and shadows of the background image while integrating the textures of the foreground image.
I1 = imblend(fg,bg,mask,Mode="Alpha",ForegroundOpacity=0.6); I2 = imblend(fg,bg,mask,Mode="Guided",FilterSize=[5 5]); I3 = imblend(fg,bg,mask,Mode="Min"); I4 = imblend(fg,bg,mask,Mode="Max"); I5 = imblend(fg,bg,mask,Mode="Average"); I6 = imblend(fg,bg,mask,Mode="Overlay"); figure tiledlayout(2,3) nexttile imshow(I1) title("Mode = Alpha") nexttile imshow(I2) title("Mode = Guided") nexttile imshow(I3) title("Mode = Min") nexttile imshow(I4) title("Mode = Max") nexttile imshow(I5) title("Mode = Average") nexttile imshow(I6) title("Mode = Overlay")
Input Arguments
fg
— Foreground image
2-D grayscale image | 2-D RGB image
Foreground image, specified as a 2-D grayscale image or 2-D RGB image. The size of the foreground image can be different from the size of the background image. The function uses the first minRows rows and the first minCols columns of the foreground image for blending, where minRows is the minimum of the number of rows between the foreground and background images, and minCols is the minimum of the number of columns between the foreground and background images.
Data Types: single
| double
| int16
| uint8
| uint16
bg
— Background image
2-D grayscale image | 2-D RGB image
Background image, specified as a 2-D grayscale image or 2-D RGB image.
Data Types: single
| double
| int16
| uint8
| uint16
mask
— Mask of foreground pixels to blend
true
or 1
(default) | false
or 0
| logical matrix
Mask of foreground pixels to blend, specified as a logical 1
(true
) or 0
(false
), or a
logical matrix of the same size as the foreground image. If mask
is a
scalar with a value of true
, all pixels of the foreground image. are
included in the mask.
Data Types: logical
Name-Value Arguments
Specify optional pairs of arguments as
Name1=Value1,...,NameN=ValueN
, where Name
is
the argument name and Value
is the corresponding value.
Name-value arguments must appear after other arguments, but the order of the
pairs does not matter.
Example: imblend(F,B,Location=[10 12])
specifies that the blending of
the foreground image must start from the 10th row and 12th column of the background
image.
Mode
— Blend mode
"Alpha"
(default) | "Guided"
| "Min"
| "Max"
| "Average"
| "Overlay"
Blend mode, specified as "Alpha"
, "Guided"
,
"Min"
, "Max"
, "Average"
, or
"Overlay"
.
Blend Mode | Algorithm | Output | Applications |
---|---|---|---|
"Alpha" |
|
| You can use this mode in applications such as augmented reality, computer-generated graphics, and multimodal medical image visualization. |
"Guided" |
|
| You can use this mode in applications such as augmented reality and computer-generated graphics. |
"Min" |
|
| You can use this mode in applications such as astrophotography, for noise reduction, or in security applications to enhance details in dark regions. |
"Max" |
|
| You can use this mode in applications such as medical imaging to emphasize certain features, or in surveillance to detect motion or changes in a series of images. |
"Average" |
|
| You can use this mode in applications such as noise reduction in photography, where averaging multiple shots of the same scene can reduce random noise. |
"Overlay" |
|
| You can use this mode in applications such as digital art and photo editing to add textures, adjust lighting, or create special effects by blending textures or patterns with original photographs. |
Data Types: char
| string
Location
— Starting location of blending in background image
[1 1]
(default) | 1-by-2 numeric vector
Starting location of blending in the background image, specified as a 1-by-2 numeric vector. The first and second elements specify the x-coordinate (column index) and y-coordinate (row index), respectively, of the location in the background image from where the top-left corner of the foreground image is blended. The row and column indices of the starting location can be zero, negative, or even fractional. The function determines the mapping between the pixels of the background and foreground images for blending by using image translation and interpolation.
Data Types: single
| double
ForegroundOpacity
— Opacity of foreground in alpha blending
0.7
(default) | positive scalar in the range (0,1]
Opacity of the foreground in alpha blending, specified as a positive scalar less
than or equal to 1
. Decreasing the foreground opacity increases the
partial transparency effect in the blended image.
Note
Specify ForegroundOpacity
only when the
Mode
is "Alpha"
.
Data Types: single
| double
FilterSize
— Size of filter in guided blending
[3 3]
(default) | 2-element vector of positive integers
Size of the filter in guided blending, specified as a 2-element vector of positive integers. Increasing the filter size increases the smoothing of the edges of the mask.
Note
Specify FilterSize
only when the Mode
is
"Guided"
.
Data Types: single
| double
| int8
| int16
| int32
| int64
| uint8
| uint16
| uint32
| uint64
Output Arguments
I
— Blended image
2-D grayscale image | 2-D RGB image
Blended image, returned as a 2-D grayscale or RGB image with the same size and data type as the background image.
Version History
Introduced in R2024b
See Also
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)