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/discretisation.m | 49 ++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100755 SD-VBS/common/toolbox/MultiNcut/discretisation.m (limited to 'SD-VBS/common/toolbox/MultiNcut/discretisation.m') diff --git a/SD-VBS/common/toolbox/MultiNcut/discretisation.m b/SD-VBS/common/toolbox/MultiNcut/discretisation.m new file mode 100755 index 0000000..70b5650 --- /dev/null +++ b/SD-VBS/common/toolbox/MultiNcut/discretisation.m @@ -0,0 +1,49 @@ +function [SegLabel,EigenVectors]=discretisation(EigenVectors,nr,nc) +% +% EigenvectorsDiscrete=discretisation(EigenVectors) +% +% Input: EigenVectors = continuous Ncut vector, size = ndata x nbEigenvectors +% Output EigenvectorsDiscrete = discrete Ncut vector, size = ndata x nbEigenvectors +% +% Timothee Cour, Stella Yu, Jianbo Shi, 2004 + +[n,k]=size(EigenVectors); + +vm = sqrt(sum(EigenVectors.*EigenVectors,2)); +EigenVectors = EigenVectors./repmat(vm,1,k); + +R=zeros(k); +R(:,1)=EigenVectors(1+round(rand(1)*(n-1)),:)'; +c=zeros(n,1); +for j=2:k + c=c+abs(EigenVectors*R(:,j-1)); + [minimum,i]=min(c); + R(:,j)=EigenVectors(i,:)'; +end + +lastObjectiveValue=0; +exitLoop=0; +nbIterationsDiscretisation = 0; +nbIterationsDiscretisationMax = 20;%voir +while exitLoop== 0 + nbIterationsDiscretisation = nbIterationsDiscretisation + 1 ; + EigenvectorsDiscrete = discretisationEigenVectorData(EigenVectors*R); + [U,S,V] = svd(EigenvectorsDiscrete'*EigenVectors,0); + NcutValue=2*(n-trace(S)); + + if abs(NcutValue-lastObjectiveValue) < eps | nbIterationsDiscretisation > nbIterationsDiscretisationMax + exitLoop=1; + else + lastObjectiveValue = NcutValue; + R=V*U'; + end +end + +%%%% + +SegLabel = zeros(nr,nc); +for j=1:size(EigenvectorsDiscrete,2), + SegLabel = SegLabel + j*reshape(EigenvectorsDiscrete(:,j),nr,nc); +end +EigenVectors = reshape(EigenVectors,nr,nc,size(EigenVectors,2)); + -- cgit v1.2.2