如何更改图像的背景颜色? [英] How can I change the background color of the image?
问题描述
我希望删除/更改
Matlab中图像的背景颜色。
I want to remove/change
the background color of an image in Matlab.
任何人都知道如何这样做?
Anyone know how to do this?
这是一个示例图片,我想删除绿色背景颜色。
Here is an example image, I want to remove the green background color.
http://cdn4.frip.in/wp-content/uploads/2013/05/custom-widget-area-for-wordpress.jpg
推荐答案
最简单的答案是,
c = [70 100 70];
thresh = 50;
A = imread('image.jpg');
B = zeros(size(A));
Ar = A(:,:,1);
Ag = A(:,:,2);
Ab = A(:,:,3);
Br = B(:,:,1);
Bg = B(:,:,2);
Bb = B(:,:,3);
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);
您应该更改 c
(背景颜色)和 thresh
( c
的阈值)并找到最适合你背景的。
You should change c
(background color) and thresh
(threshold for c
) and find the best that fits your background.
您可以将 B
定义为新的背景图像。 Fr示例添加 Bb(:,:) = 255;
将为您提供蓝色背景。
You can define B
as your new background image. Fr example adding Bb(:,:) = 255;
will give you a blue background.
您甚至可以定义 B
作为图像。
You can even define B
as an image.
为了检测背景,您可以找到图像中使用最多的颜色,但这是我认为不一定是背景。
In order to detect background you could find the color that is most used in the image, but that is not necessarily background I think.
这篇关于如何更改图像的背景颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!