-
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathMPB_2.m
More file actions
48 lines (45 loc) · 1.47 KB
/
MPB_2.m
File metadata and controls
48 lines (45 loc) · 1.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
%MPB: A modified Poisson blending technique
%Read the paper: http://link.springer.com/article/10.1007/s41095-015-0027-z
%Citation:
%@article{
%year={2015},
%issn={2096-0433},
%journal={Computational Visual Media},
%doi={10.1007/s41095-015-0027-z},
%title={MPB: A modified Poisson blending technique},
%url={http://dx.doi.org/10.1007/s41095-015-0027-z},
%publisher={Springer Berlin Heidelberg},
%keywords={image processing; image inpainting; image blending; image cloning; image enhancement},
%author={Afifi, Mahmoud and Hussain, KhaledF.},
%pages={1-11},
%language={English}
%}
%Apply the third step in MPB (Solve Color bleeding Problem)
function F = MPB_2( fg, bg, mask , out)
%you can tune these parameters to get different results
T=0.25;
Ha=20;
N1=100;
N2=100;
gamma=0.1;
MPB(fg,bg,mask(:,:,1),'temp1.jpg');
MPB(bg,fg,255-mask(:,:,1),'temp2.jpg');
fg1=imread('temp1.jpg');
fg2= imread('temp2.jpg');
differentFrame= (fg1-bg)+(bg-fg1);
[X_no_dither,map]= rgb2ind(differentFrame,4,'dither');
BW = im2bw(X_no_dither,map,T);
BW=imfill(BW,'holes');
temp(:,:,1)=uint8(BW)*255;
temp(:,:,2)=uint8(BW)*255;
temp(:,:,3)=uint8(BW)*255;
H = fspecial('average',Ha);
average = imfilter(temp,H,'same');
H = fspecial('gaussian',[N1 N2],gamma);
gaussian = imfilter(average+1,H,'same');
temp1=double(fg1).*double(imcomplement(gaussian))/255;
temp2=double(fg2).*double(gaussian)/255;
result=temp1+temp2;
delete('temp1.jpg');
delete('temp2.jpg');
imwrite(result/255,out);