用源背景图像替换源图像的定义颜色 [英] Replace defined colors of a source image with a background image

查看:151
本文介绍了用源背景图像替换源图像的定义颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要编写一个带4个参数的函数:
更改图像的蓝色背景并将其替换为其他图像

I need to write a function that takes 4 parameters: to change the blue background of an image and replace it with other image

推荐答案

function bluescreen(A,B,c,thresh)
A = imread(A);
B = imread(B);
Ar = A(:,:,1);
Ag = A(:,:,2);
Ab = A(:,:,3);
Br = B(:,:,1);
Bg = B(:,:,2);
Bb = B(:,:,3);
logmap = zeros([size(A,1),size(A,2)]);
logmap = (Ar > (c(1)-thresh)).*(Ar < (c(1)+thresh)).*...
     (Ag > (c(2)-thresh)).*(Ag < (c(2)+thresh)).*...
     (Ab > (c(3)-thresh)).*(Ab < (c(3)+thresh));
Ar(logmap == 1) = Br(logmap == 1);
Ag(logmap == 1) = Bg(logmap == 1); 
Ab(logmap == 1) = Bb(logmap == 1);
A = cat(3 ,Ar,Ag,Ab);
imshow(A);
end

当你打电话时,
bluescreen('peppers.png','tape.png',[200 10 10],50);

它给你,

我不确定你想要什么!

好的。我剪了两张图片并打电话给 bluescreen('A.png','B.png',[30 30 120],80);

Ok. I cut both images and called bluescreen('A.png','B.png',[30 30 120],80);

我明白了,

我觉得这很好,不是吗?!

I think It is good enough, don't you?!

这篇关于用源背景图像替换源图像的定义颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆