Skip to content

Commit

Permalink
ENH: Added all new repository files from local repository with NM code.
Browse files Browse the repository at this point in the history
  • Loading branch information
francopestilli committed Aug 24, 2016
1 parent 338fb33 commit df7b95a
Show file tree
Hide file tree
Showing 499 changed files with 49,006 additions and 0 deletions.
875 changes: 875 additions & 0 deletions compute/MDF_block.prj

Large diffs are not rendered by default.

69 changes: 69 additions & 0 deletions compute/compute_BMD.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
% This function compute the Bundle-based Minimum Distance (BMD) between two bundles [Garyfallidis et al, 2015]
function [ distance ] = compute_BMD(bA, bB, Npoints)
% bA: Bundle A (set of fibers)
% bB: Bundle B (set of fibers)
% Npoints: Number of points used to interpolate fibers ([Garyfallidis et al, 2015] uses Npoints=20)
% distance: Bundle-based Minimum Distance (BMD) computed as in eq. (1) in [Garyfallidis et al, 2015]

I = size(bA,1);
J = size(bB,1);

% Interpolate bundles
bA = interpolate(bA,Npoints);
bB = interpolate(bB,Npoints);

vA = zeros(I,1);
vB = zeros(J,1);

% fix one fiber in Bundle A and compute the distances to every fibers in
% Bundle B
for i=1:I
disp(['across bA:',num2str(100*i/I),'%'])
fA = bA{i};
parfor j=1:J
vB(j) = MDF(fA,bB{j});
end
vA(i) = min(vB);
end
dA = mean(vA);

% fix one fiber in Bundle B and compute the distances to every fibers in
% Bundle A
for j=1:J
disp(['across bB:',num2str(100*j/J),'%'])
fB = bB{j};
parfor i=1:I
vA(i) = MDF(bA{i},fB);
end
vB(j) = min(vA);
end
dB = mean(vB);

distance = (dA + dB)/4;

end

% Function that provides an interpolated bundle with a constant N number of
% points each fiber
function [b] = interpolate(b,N)

parfor f=1:size(b,1)
% Interpolate using Splines Tensor Toolbox
CS=cscvn(b{f}); % obtain spline model from points
t_range = linspace(CS.breaks(1),CS.breaks(end),N); % define range of t parameter in order to provide N points
b{f} = fnval(CS,t_range); % Evaluate curve at N points
end

end

% Function that compute the Minimum average Direct-Flip (MDF) as defined in
% eq. (2) in [Garyfallidis et al, 2015]
function [dist] = MDF(f1,f2)
N = size(f1,2);
d_dir = mean(sqrt(sum((f1'-f2').^2,2)));
d_flip = mean(sqrt(sum((f1'-flip(f2',1)).^2,2)));

dist = min(d_dir,d_flip);

end

69 changes: 69 additions & 0 deletions compute/compute_BMD.m~
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
% This function compute the Bundle-based Minimum Distance (BMD) between two bundles [Garyfallidis et al, 2015]
function [ distance ] = compute_BMD(bA, bB, Npoints)
% bA: Bundle A (set of fibers)
% bB: Bundle B (set of fibers)
% Npoints: Number of points used to interpolate fibers ([Garyfallidis et al, 2015] uses Npoints=20)
% distance: Bundle-based Minimum Distance (BMD) computed as in eq. (1) in [Garyfallidis et al, 2015]

I = size(bA,1);
J = size(bB,1);

% Interpolate bundles
bA = interpolate(bA,Npoints);
bB = interpolate(bB,Npoints);

vA = zeros(I,1);
vB = zeros(J,1);

% fix one fiber in Bundle A and compute the distances to every fibers in
% Bundle B
for i=1:I
disp(['across bA:',num2str(100*i/I),'%'])
fA = bA(:,i);
parfor j=1:J
vB(j) = MDF(fA,bB(:,j));
end
vA(i) = min(vB);
end
dA = mean(vA);

% fix one fiber in Bundle B and compute the distances to every fibers in
% Bundle A
for j=1:J
disp(['across bB:',num2str(100*j/J),'%'])
fB = bB(:,j};
parfor i=1:I
vA(i) = MDF(bA{i},fB);
end
vB(j) = min(vA);
end
dB = mean(vB);

distance = (dA + dB)/4;

end

% Function that provides an interpolated bundle with a constant N number of
% points each fiber
function [bout] = interpolate(b,N)
bout = zeros(N,size(b,1));
parfor f=1:size(b,1)
% Interpolate using Splines Tensor Toolbox
CS=cscvn(b{f}); % obtain spline model from points
t_range = linspace(CS.breaks(1),CS.breaks(end),N); % define range of t parameter in order to provide N points
bout(:,f) = fnval(CS,t_range); % Evaluate curve at N points
end

end

% Function that compute the Minimum average Direct-Flip (MDF) as defined in
% eq. (2) in [Garyfallidis et al, 2015]
function [dist] = MDF(f1,f2)
N = size(f1,2);
d_dir = mean(sqrt(sum((f1'-f2').^2,2)));
d_flip = mean(sqrt(sum((f1'-flip(f2',1)).^2,2)));

dist = min(d_dir,d_flip);

end

80 changes: 80 additions & 0 deletions compute/compute_BMD_new.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
% This function compute the Bundle-based Minimum Distance (BMD) between two bundles [Garyfallidis et al, 2015]
function [ distance ] = compute_BMD_new(bA, bB, Npoints)
% bA: Bundle A (set of fibers)
% bB: Bundle B (set of fibers)
% Npoints: Number of points used to interpolate fibers ([Garyfallidis et al, 2015] uses Npoints=20)
% distance: Bundle-based Minimum Distance (BMD) computed as in eq. (1) in [Garyfallidis et al, 2015]
%parpool('local',12)

I = size(bA,1);
J = size(bB,1);

% Interpolate bundles
bA = interpolate(bA,Npoints);
bB = interpolate(bB,Npoints);

vA = zeros(I,1);
% fix one fiber in Bundle A and compute the distances to every fibers in
% Bundle B
parfor i=1:I
%disp(['across bA:',num2str(100*i/I),'%'])
fA = repmat(bA(:,:,i),[1,1,J]);
vB1 = MDF_block(fA,bB);

vA(i) = min(vB1);
end
dA = mean(vA);

vB = zeros(J,1);
% fix one fiber in Bundle B and compute the distances to every fibers in
% Bundle A
parfor j=1:J
%disp(['across bB:',num2str(100*j/J),'%'])
fB = repmat(bB(:,:,j),[1,1,I]);
vA1 = MDF_block(fB,bA);

vB(j) = min(vA1);
end
dB = mean(vB);

distance = (dA + dB)/4;

end

% Function that provides an interpolated bundle with a constant N number of
% points each fiber
function [bout] = interpolate(b,N)
Nf = size(b,1);
bout = zeros(3,N,Nf);
%lengths_b = zeros(Nf,1);

parfor f=1:Nf
% Interpolate using Splines Tensor Toolbox
CS=cscvn(b{f}); % obtain spline model from points
t_range = linspace(CS.breaks(1),CS.breaks(end),N); % define range of t parameter in order to provide N points
bout(:,:,f) = fnval(CS,t_range); % Evaluate curve at N points
%lengths_b(f) = size(b{f},2);
end

end

% Function that compute the Minimum average Direct-Flip (MDF) as defined in
% eq. (2) in [Garyfallidis et al, 2015]
function [dist] = MDF(f1,f2)
N = size(f1,2);
d_dir = mean(sqrt(sum((f1'-f2').^2,2)));
d_flip = mean(sqrt(sum((f1'-flip(f2',1)).^2,2)));

dist = min(d_dir,d_flip);

end

function [dist] = MDF_block(f1,f2)

d_dir = mean(sqrt(sum((f1-f2).^2,1)));
d_flip = mean(sqrt(sum((f1-flip(f2,2)).^2,1)));

dist = min([d_dir,d_flip],[],2);

end

61 changes: 61 additions & 0 deletions compute/compute_incoherence.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
% This function compute the Bundle-based Minimum Distance (BMD) between two bundles [Garyfallidis et al, 2015]
function [ incoherence ] = compute_incoherence(bA, Npoints)
% bA: Bundle A (set of fibers)
% bB: Bundle B (set of fibers)
% Npoints: Number of points used to interpolate fibers ([Garyfallidis et al, 2015] uses Npoints=20)
% distance: Bundle-based Minimum Distance (BMD) computed as in eq. (1) in [Garyfallidis et al, 2015]

I = size(bA,1);
J = I;

% Interpolate bundles
bA = interpolate(bA,Npoints);
bB = bA;

vA = zeros(I,1);
vB = zeros(J,1);

% fix one fiber in Bundle A and compute the distances to every fibers in
% Bundle B
for i=1:I
i
fA = bA{i};
parfor j=1:J
if j~=i
vB(j) = MDF(fA,bB{j});
else
vB(j) = NaN;
end
end
vA(i) = min(vB);
end


incoherence = vA/2;

end

% Function that provides an interpolated bundle with a constant N number of
% points each fiber
function [b] = interpolate(b,N)

parfor f=1:size(b,1)
% Interpolate using Splines Tensor Toolbox
CS=cscvn(b{f}); % obtain spline model from points
t_range = linspace(CS.breaks(1),CS.breaks(end),N); % define range of t parameter in order to provide N points
b{f} = fnval(CS,t_range); % Evaluate curve at N points
end

end

% Function that compute the Minimum average Direct-Flip (MDF) as defined in
% eq. (2) in [Garyfallidis et al, 2015]
function [dist] = MDF(f1,f2)
N = size(f1,2);
d_dir = mean(sqrt(sum((f1'-f2').^2,2)));
d_flip = mean(sqrt(sum((f1'-flip(f2',1)).^2,2)));

dist = min(d_dir,d_flip);

end

75 changes: 75 additions & 0 deletions compute/compute_wBMD.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
% This function compute the weighted Bundle-based Minimum Distance (wBMD)
% between two bundles. The wBMD is a modified BMD [Garyfallidis et al,
% 2015] that takes into account the fiber weights assigned in LiFE.
function [ distance ] = compute_wBMD(bA, bB, wA, wB, Npoints)
% bA: Bundle A (set of fibers)
% bB: Bundle B (set of fibers)
% wA: weights for Bundle A
% wB: weights for Bundle B
% Npoints: Number of points used to interpolate fibers ([Garyfallidis et al, 2015] uses Npoints=20)
% distance: Bundle-based Minimum Distance (BMD) computed as in eq. (1) in [Garyfallidis et al, 2015]

I = size(bA,1);
J = size(bB,1);

% Interpolate bundles
bA = interpolate(bA,Npoints);
bB = interpolate(bB,Npoints);

vA = zeros(I,1);
vB = zeros(J,1);

% normalize weights
wA = wA./sum(wA);
wB = wB./sum(wB);

% fix one fiber in Bundle A and compute the distances to every fibers in
% Bundle B
for i=1:I
fA = bA{i};
parfor j=1:J
vB(j) = MDF(fA,bB{j});
end
vA(i) = min(vB);
end
dA = sum(wA.*vA);

% fix one fiber in Bundle B and compute the distances to every fibers in
% Bundle A
for j=1:J
fB = bB{j};
parfor i=1:I
vA(i) = MDF(bA{i},fB);
end
vB(j) = min(vA);
end
dB = sum(wB.*vB);

distance = (dA + dB)/4;

end

% Function that provides an interpolated bundle with a constant N number of
% points each fiber
function [b] = interpolate(b,N)

parfor f=1:size(b,1)
% Interpolate using Splines Tensor Toolbox
CS=cscvn(b{f}); % obtain spline model from points
t_range = linspace(CS.breaks(1),CS.breaks(end),N); % define range of t parameter in order to provide N points
b{f} = fnval(CS,t_range); % Evaluate curve at N points
end

end

% Function that compute the Minimum average Direct-Flip (MDF) as defined in
% eq. (2) in [Garyfallidis et al, 2015]
function [dist] = MDF(f1,f2)
N = size(f1,2);
d_dir = mean(sqrt(sum((f1'-f2').^2,2)));
d_flip = mean(sqrt(sum((f1'-flip(f2',1)).^2,2)));

dist = min(d_dir,d_flip);

end

Loading

0 comments on commit df7b95a

Please sign in to comment.