如何获取二值图像的前景 (MATLAB)

发布于 2024-12-08 07:33:22 字数 203 浏览 0 评论 0原文

我有一个人摆姿势的二进制图片,我想忽略背景(黑色)部分,只获取前景(人本身,白色)。
我希望这能够融合不同背景的人。

我被困在这里了。我不知道如何继续:

mypic = imread('model1.jpg');

binarymypic = im2bw(mypic);

提前致谢。

I've a binary picture of a person posing and I want to ignore the background (black) part and get only the foreground (the person itself, white).
I want this to fuse the person with a different background.

I'm stucked here. I dont know how to continue:

mypic = imread('model1.jpg');

binarymypic = im2bw(mypic);

Thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

維他命╮ 2024-12-15 07:33:22

假设您有 AB,它们的大小相同,您可以将所需的像素从 A 复制到 B 使用逻辑掩码 I

B(I) = A(I);

在本例中,A 是 mypic,IbinarymypicB 包含背景。

编辑:尝试:

mypic = imread('model1.jpg');
backgroundimage = imread('background.jpg');

% Check assumptions
assert(size(mypic,3) == 3, 'Expecting true colour foreground image')
assert(size(mypic,3) == 3, 'Expecting true colour background image')
assert(isequal(size(mypic), size(backgroundimage)), 'Images should have the same size')

mask = im2bw(rgb2gray(mypic));

in = reshape(mypic, [], 3);
out = reshape(backgroundimage, [], 3);
out(mask,1) = in(mask,1); % Red
out(mask,2) = in(mask,2); % Green
out(mask,3) = in(mask,3); % Blue

finalimage = reshape(out, size(backgroundimage));
imshow(finalimage)

Assuming you have A and B, which are the same size, you can copy the pixels you want from A to B using a logical mask I:

B(I) = A(I);

In this case, A is mypic, I is binarymypic and B contains the background.

EDIT: Try:

mypic = imread('model1.jpg');
backgroundimage = imread('background.jpg');

% Check assumptions
assert(size(mypic,3) == 3, 'Expecting true colour foreground image')
assert(size(mypic,3) == 3, 'Expecting true colour background image')
assert(isequal(size(mypic), size(backgroundimage)), 'Images should have the same size')

mask = im2bw(rgb2gray(mypic));

in = reshape(mypic, [], 3);
out = reshape(backgroundimage, [], 3);
out(mask,1) = in(mask,1); % Red
out(mask,2) = in(mask,2); % Green
out(mask,3) = in(mask,3); % Blue

finalimage = reshape(out, size(backgroundimage));
imshow(finalimage)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文