alpha=imread('..\plasticbag.png');%read three image from local directory
b=imread('F:\matting\input_lowres\doll.png');%background img
f=imread('F:\matting\input_training_lowres\GT04.png');%foreground img
%%
alpha=im2double(alpha);%rgb color,r=g=b
alpha=alpha(:,:,1);% size(alpha)==size(f:froeground)
%%
b=im2double(b);
f=im2double(f);
[h,w,c]=size(f);%here we only use the foreground image,
[bh,bw,bc]=size(b);
b(:)=1;%设置为白色的背景
%%
% the size of b:background >= the size of f:foreground
%%
img=zeros(h,w,c);
for i=1:h
for j=1:w
img(i,j,1)=f(i,j,1)*alpha(i,j)+b(i,j,1)*(1-alpha(i,j));%融合函数
img(i,j,2)=f(i,j,2)*alpha(i,j)+b(i,j,2)*(1-alpha(i,j));
img(i,j,3)=f(i,j,3)*alpha(i,j)+b(i,j,3)*(1-alpha(i,j));
end
end
imshow(img);
b=imread('F:\matting\input_lowres\doll.png');%background img
f=imread('F:\matting\input_training_lowres\GT04.png');%foreground img
%%
alpha=im2double(alpha);%rgb color,r=g=b
alpha=alpha(:,:,1);% size(alpha)==size(f:froeground)
%%
b=im2double(b);
f=im2double(f);
[h,w,c]=size(f);%here we only use the foreground image,
[bh,bw,bc]=size(b);
b(:)=1;%设置为白色的背景
%%
% the size of b:background >= the size of f:foreground
%%
img=zeros(h,w,c);
for i=1:h
for j=1:w
img(i,j,1)=f(i,j,1)*alpha(i,j)+b(i,j,1)*(1-alpha(i,j));%融合函数
img(i,j,2)=f(i,j,2)*alpha(i,j)+b(i,j,2)*(1-alpha(i,j));
img(i,j,3)=f(i,j,3)*alpha(i,j)+b(i,j,3)*(1-alpha(i,j));
end
end
imshow(img);