怎么做软抠图之类的?算法是什么?
if (~exist('epsilon ',' var '))
ε= 0.0000001;
结束
if(is empty(ε))
ε= 0.0000001;
结束
if (~exist('win_size ',' var '))
win _ size = 1;
结束
if (isempty(win_size))
win _ size = 1;
结束
neb_size=(win_size*2+1)^2;
[h,w,c]=大小(I);
n = h;m = w;
img _ size = w * h;
consts=imerode(consts,ones(win _ size * 2+1));
indsM = shape([1:img _ size],h,w);
tlen=sum(sum(1-consts(win_size+1:end-win_size,win_size+1:end-win_size)))*(neb_size^2);
row_inds=zeros(tlen,1);
col_inds=zeros(tlen,1);
vals=zeros(tlen,1);
len = 0;
对于j=1+win_size:w-win_size
for I = win _ size+1:h-win _ size
if (consts(i,j))
继续
结束
win _ inds = indsM(I-win _ size:I+win _ size,j-win _ size:j+win _ size);
win _ inds = win _ inds(:);
winI=I(i-win_size:i+win_size,j-win_size:j+win_size,);
winI = shape(winI,neb_size,c);
win_mu=mean(winI,1)';
win _ var = inv(winI ' * winI/Neb _ size-win _ mu * win _ mu '+epsilon/Neb _ size * eye(c));
winI=winI-repmat(win_mu ',neb_size,1);
tvals =(1+winI * win _ var * winI ')/Neb _ size;
row_inds(1+len:neb_size^2+len)=reshape(repmat(win_inds,1,neb_size),...
neb_size^2,1);
col_inds(1+len:neb_size^2+len)=reshape(repmat(win_inds',neb_size,1),...
neb_size^2,1);
vals(1+len:neb_size^2+len)=tvals(:);
len=len+neb_size^2;
结束
结束
vals = vals(1:len);
row _ inds = row _ inds(1:len);
col _ inds = col _ inds(1:len);
A=sparse(row_inds,col_inds,vals,img_size,img _ size);
sumA=sum(A,2);
A=spdiags(sumA(:),0,img_size,img _ size)-A;