在透明的图像上绘制蒙版

时间:2017-09-08 03:28:46

标签: image matlab octave

在Matlab / Octave(Image包)中,是否可以在图像区域上绘制略微透明的彩色矩形?

例如;我想在图像的左上角绘制一个红色矩形(alpha /不透明度为0.5)。

pkg load image;
pkg load signal;

i = imread('foo.jpg');

% Somehow draw a transparent rectangle over the top left of the image

imshow(i);

1 个答案:

答案 0 :(得分:1)

您可以使用hold on和属性'AlphaData'绘制透明叠加层,如下所示:

image = rand(100); % a random image
imshow(image); % show the image

% create the red overlay
red = zeros(100, 100, 3);
red(:, :, 1) = 1;

% create the alpha channel with the right transparency
alpha = zeros(100); % everywhere completely transparent
alpha(1:50, 1:50) = 0.5; % except for the top left corner

hold on
h = imshow(red); % show the overlay
set(h, 'AlphaData', alpha); % apply the transparency

enter image description here