主要内容

imoverlay

将二值掩膜刻入二维图像

说明

B = imoverlay(A,BW) 基于二值掩膜输入 BW 中的 true 值对灰度或 RGB 图像 A 中的对应元素填充纯色。

示例

B = imoverlay(A,BW,color) 指定 imoverlay 填充图像所用的颜色。

示例

全部折叠

将灰度图像读入工作区。

A = imread('cameraman.tif');

将二值图像读入工作区。

BW = imread('text.png');

将二值图像刻入灰度图像,指定二值掩膜要使用的颜色。

B = imoverlay(A,BW,'yellow');

显示结果。

imshow(B)

Figure contains an axes object. The hidden axes object contains an object of type image.

将 RGB 图像读取到工作区。

RGB = imread('peppers.png');

将二值图像读入工作区。

BW = imread('text.png');

裁剪 RGB 图像,使其大小与二值掩膜相同。

RGB_cropped = imcrop(RGB,[64,128,255,255]);

将二值图像刻入裁剪后的 RGB 图像,选择要使用的颜色。

B = imoverlay(RGB_cropped,BW,'red');

显示结果。

figure
imshow(B)

Figure contains an axes object. The hidden axes object contains an object of type image.

输入参数

全部折叠

输入图像,指定为二维灰度图像或二维 RGB 图像。

数据类型: single | double | int16 | uint8 | uint16 | logical

掩膜图像,指定的二维二值矩阵或二维数值矩阵,其大小与图像 A 的前两个维度相同。对于数值输入,任何非零像素都被视为 1 (true)。

数据类型: single | double | int8 | int16 | int32 | uint8 | uint16 | uint32 | logical

叠加所用颜色,指定为 RGB 三元组、颜色名称或短颜色名称。

您可以使用 RGB 三元组指定任何颜色。RGB 三元组是一个包含 3 个元素的行向量,其元素分别指定颜色中红、绿、蓝分量的强度。强度必须在 [0, 1] 范围内。

您可以按名称将一些常见颜色指定为字符串标量或字符向量。下表列出了命名颜色选项和等效的 RGB 三元组。

颜色名称短名称RGB 三元组外观
"red""r"[1 0 0]

Sample of the color red

"green""g"[0 1 0]

Sample of the color green

"blue""b"[0 0 1]

Sample of the color blue

"cyan" "c"[0 1 1]

Sample of the color cyan

"magenta""m"[1 0 1]

Sample of the color magenta

"yellow""y"[1 1 0]

Sample of the color yellow

"black""k"[0 0 0]

Sample of the color black

"white""w"[1 1 1]

Sample of the color white

下表列出了浅色和深色主题中绘图的默认调色板。

调色板调色板颜色

"gem" - 浅色主题默认值

在 R2025a 之前的版本中: 大多数绘图默认使用这些颜色。

Sample of the "gem" color palette

"glow" - 深色主题默认值

Sample of the "glow" color palette

您可以使用 orderedcolors 函数获取这些调色板的 RGB 三元组 (自 R2023b 起)。例如,获取 "gem" 调色板的 RGB 三元组。

RGB = orderedcolors("gem");

示例: "r"

示例: "green"

示例: [0 0.4470 0.7410]

输出参量

全部折叠

输出图像,以二维 RGB 图像形式返回。

数据类型: uint8

扩展功能

全部展开

版本历史记录

在 R2016a 中推出