From f618466c25d43f3bae9e40920273bf77de1e1149 Mon Sep 17 00:00:00 2001 From: leochanj105 Date: Mon, 19 Oct 2020 23:09:30 -0400 Subject: initial sd-vbs initial sd-vbs add sd-vbs sd-vbs --- SD-VBS/common/toolbox/MultiNcut/computeMultiW.m | 245 ++++++++++++++++++++++++ 1 file changed, 245 insertions(+) create mode 100755 SD-VBS/common/toolbox/MultiNcut/computeMultiW.m (limited to 'SD-VBS/common/toolbox/MultiNcut/computeMultiW.m') diff --git a/SD-VBS/common/toolbox/MultiNcut/computeMultiW.m b/SD-VBS/common/toolbox/MultiNcut/computeMultiW.m new file mode 100755 index 0000000..b2cb7ea --- /dev/null +++ b/SD-VBS/common/toolbox/MultiNcut/computeMultiW.m @@ -0,0 +1,245 @@ +%inputs : image, number of layers, distance defining the subgrid, the edge filter scales for each layer, radius for each layer, +%edge variance for filter, shape of the neighbourhood layout ('square', 'star', 'cross'), sigma for intensity affinity, +% sigma for distance influence in affinity, weight coefficients for Wpps in the multiscale matrix. +%output : multiscale affinity matrix , extern constraint matrix, affinity matrices of each layer seperatly. + + +function [multiWpp,constraintMat, Wind,data,emag,ephase]= computeMultiW (image,data); + +%variables + +if isempty(data.layers.number) + n=2; +else + n=data.layers.number; +end + +if isempty(data.layers.dist) + dist_grid=3; +else + dist_grid=data.layers.dist; +end + +if isempty(data.W.scales) + s=1:n; +elseif (length(data.W.scales)==n) + s=data.W.scales; +else + s=1:n; +end + +if isempty(data.W.radius) + r(1)=2; + for i=2:n + r(i)=10; + end +else + r=data.W.radius; +end + + +if isempty(data.W.edgeVariance) + data.W.edgeVariance=0.1; +end + +if isempty(data.W.gridtype) + data.W.gridtype='square'; +end + +if isempty(data.W.sigmaI) + data.W.sigmaI=0.12; +end + +if isempty(data.W.sigmaX) + data.W.sigmaX=10; +end + +if isempty(data.layers.weight) + coef(1)=5; + coef(2:n)=200; +elseif (length(data.layers.weight)==n) + coef=data.layers.weight; +else + coef(1)=5; + coef(2:n)=100; %200 +end + +if isempty(data.W.mode) + data.W.mode=mixed; +end + + +[p1,q1,ignore]=size(image); +image=image(:,:,1); +filter_par = [4,30,4]; %[9,30,4] +[x,y,gx,gy,par,threshold,emag,ephase,g,FIe,FIo,mago] = quadedgep2(image,filter_par,data,0.001); +minW=10^(-2); %-3 + + +% function [multiWpp,constraintMat,p,q,Wppp,subgrid] = computemultiWpp(n,imageX,r,dist_grid,s,dataWpp,emag,ephase,minW,mode,facteurMul,contrainte,tt,gridtype,colormode,imageOriginale,subgridImageReduite,pG,qG) + +p= p1*ones(n,1); +q= q1*ones(n,1); +d= dist_grid*ones(n,1); +d(1)=1; +for (i=2:n) + d(i)=d(i)*3^(i-2); +end +p=ceil(p1./d); +q=ceil(q1./d); + +%computation of the subgrids (the first pixel is coded by one). S{i,j}(k) is the index of +%the kth pixel of the jth grid in the ith grid. + +for i=1:n-1 + for j=i+1:n + a=[0:p(j)*q(j)-1]; + subgrid{i,j}=p(i)*(floor(a/p(j)))*d(j)/d(i)+(1+mod(a,p(j))*d(j)/d(i)); + end +end + +%computation of the independent W matrix for each layer Wind{i} 1=1) + for j=i-1:-1:1 + Wpp{i}=[C{j,i}',Wpp{i}]; + end + end + if (i1) +% for j=i-1:-1:1 +% Wpp{i}=[sparse(p(i)*q(i),p(j)*q(j)),Wpp{i}]; +% end +% end +% if (i2 + for i=3:n + piqi=p(i)*q(i); + if i~=n + constraintMat=[constraintMat,[sparse(sum(p(1:i-2).*q(1:i-2)),piqi);-C{i-1,i};speye(piqi);sparse(pq-sum(p(2:i).*q(2:i)),piqi)]]; + else + constraintMat=[constraintMat,[sparse(sum(p(1:i-2).*q(1:i-2)),piqi);-C{i-1,i};speye(piqi)]]; + end + end + end + + % saving useful information + %subgrids, p and q + data.subgrid=subgrid; + data.p=p; + data.q=q; -- cgit v1.2.2