左边的图片是我的背景图片,右边的图片是原始图片:
做减法后,我在去除脚踝背景时遇到了麻烦:
目的是只获取前景,是否有人有想法?下面显示的是关于如何执行背景减法以及显示它的代码。谢谢。
I = (imread('frame9.jpg'));
figure(1),imshow(I);
bg =(imread('background.jpg'));
figure(2),imshow(bg);
Ip = bg-I;
figure(3),imshow(Ip);
答案 0 :(得分:0)
以下解决方案不完整,但它可以为您提供领导:
我使用以下操作来创建一个掩码:
graythresh
找到阈值)。 检查以下代码:
%Read two images from hosting site.
twoImages = imread('https://i.stack.imgur.com/5dN5O.png');
%Convet from uint8 to double (pixels range [0, 1])
twoImages = im2double(twoImages);
B = twoImages(7:332, 23:599, :);
I = twoImages(7:332, 706:1282, :);
%Shrink images by factor of x2 in each axis.
sB = imresize(B, 0.5);
sI = imresize(I, 0.5);
%Diference of shrank images.
sD = abs(sB - sI);
%Convert to binary image, using threshold.
level = graythresh(sD);
sBW = im2bw(sD, level);
%Dilate binary image
se = strel('disk', 6);
sBW = imdilate(sBW, se);
%Resize binary image to size of I (create binary mask).
BW = imresize(sBW, [size(I,1), size(I,2)]);
%Mask elements with BW = 0 (BW is used as mask).
I = I .* double(cat(3, BW, BW, BW));
figure;imshow(I);