【问题标题】:Draw mask on image with transparency在具有透明度的图像上绘制蒙版
【发布时间】:2018-02-16 21:21:15
【问题描述】:

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

例如;我想在图像的左上角绘制一个红色矩形(alpha/opacity 为 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);

【问题讨论】:

  • 如果可能,您应该明确说明您是否需要 GNU Octave 或 Matlab 的解决方案。没有这样的“Matlab/Octave”东西。是的,有可能,只需在 i 的第三维添加一个矩形

标签: image matlab octave


【解决方案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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-03-15
    • 1970-01-01
    • 2019-04-17
    • 2018-04-02
    • 2018-12-21
    • 1970-01-01
    • 2021-10-01
    • 2020-09-07
    相关资源
    最近更新 更多