在MATLAB

时间:2018-01-18 16:03:22

标签: matlab image-processing

我试图在MATLAB中为灰度图像添加徽标,并且我已经使用this作为帮助。但我没有得到我预期的结果。如您所见,我不希望徽标的白色部分可见,只有徽标本身很重要。 Result of my code 这是我的代码:

clear;
clc;

RGBimage = imread('image.jpg');
GrayscaleImage = rgb2gray(RGBimage);

RGBlogo = imread('logo.png');
GrayscaleLogo = rgb2gray(RGBlogo);
GrayscaleLogo = imresize(GrayscaleLogo, 0.2, 'bilinear');

[m,n] = size(GrayscaleLogo);
alpha = 0.8;

ResultImage = GrayscaleImage;
ResultImage(1:m,1:n) = uint8(alpha .* double(GrayscaleLogo) + (1-alpha) .* double(GrayscaleImage(1:m,1:n)));

figure;
imshow(ResultImage);

但我不知道如何修改它。请帮帮我!

1 个答案:

答案 0 :(得分:0)

您的图片没有Alpha通道,因此您需要制作一个!

...
[m,n] = size(GrayscaleLogo);

alpha = im2double(GrayscaleLogo)<0.5; % create an alpha channel and show only black pixels.
...

enter image description here