-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[format] complete reformat all matlab scripts with miss_hit
- Loading branch information
Showing
110 changed files
with
3,602 additions
and
3,622 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
addpath('../../../matlab/'); | ||
addpath('../../../matlab/'); | ||
|
||
if(~exist('MMC_Collins_Atlas_Mesh_Version_2L.mat','file')) | ||
f=websave('MMC_Collins_Atlas_Mesh_Version_2L.mat','https://github.com/fangq/Colin27BrainMesh/raw/master/MMC_Collins_Atlas_Mesh_Version_2L.mat'); | ||
if(~exist('MMC_Collins_Atlas_Mesh_Version_2L.mat','file')) | ||
warning('Please download Colin27 atlas mesh from https://github.com/fangq/Colin27BrainMesh/raw/master/MMC_Collins_Atlas_Mesh_Version_2L.mat') | ||
end | ||
if (~exist('MMC_Collins_Atlas_Mesh_Version_2L.mat', 'file')) | ||
f = websave('MMC_Collins_Atlas_Mesh_Version_2L.mat', 'https://github.com/fangq/Colin27BrainMesh/raw/master/MMC_Collins_Atlas_Mesh_Version_2L.mat'); | ||
if (~exist('MMC_Collins_Atlas_Mesh_Version_2L.mat', 'file')) | ||
warning('Please download Colin27 atlas mesh from https://github.com/fangq/Colin27BrainMesh/raw/master/MMC_Collins_Atlas_Mesh_Version_2L.mat'); | ||
end | ||
end | ||
|
||
load MMC_Collins_Atlas_Mesh_Version_2L.mat | ||
savemmcmesh('brain',node,elem); | ||
load MMC_Collins_Atlas_Mesh_Version_2L.mat; | ||
savemmcmesh('brain', node, elem); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,9 @@ | ||
addpath ../../matlab | ||
srcpos=[50.5 50.5 0]; | ||
addpath ../../matlab; | ||
srcpos = [50.5 50.5 0]; | ||
fprintf('Generating mesh...'); | ||
[node,elem] = genT5mesh(0:4:100,0:4:100,0:4:80); | ||
[node, elem] = genT5mesh(0:4:100, 0:4:100, 0:4:80); | ||
fprintf('done\nSaving mesh..'); | ||
savemmcmesh('dcs',node(:,1:3),elem); % 4th column of node is label and confuses savemmcmesh volume calculation | ||
savemmcmesh('dcs', node(:, 1:3), elem); % 4th column of node is label and confuses savemmcmesh volume calculation | ||
fprintf('done\nFinding element enclosing source: '); | ||
eid=tsearchn(node(:,1:3),elem(:,1:4),srcpos); | ||
fprintf('%d\n',eid); | ||
|
||
eid = tsearchn(node(:, 1:3), elem(:, 1:4), srcpos); | ||
fprintf('%d\n', eid); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,40 @@ | ||
addpath('../../matlab'); | ||
|
||
Db=1e-7; % simulated brownian motion diffusion coefficient | ||
sim_beta=0.4; | ||
Db = 1e-7; % simulated brownian motion diffusion coefficient | ||
sim_beta = 0.4; | ||
|
||
mua=0.01; | ||
mus=1; | ||
g=0.01; | ||
musp=mus*(1-g); | ||
sdsep=15; | ||
prob_scat_moving_scat=1; | ||
mua = 0.01; | ||
mus = 1; | ||
g = 0.01; | ||
musp = mus * (1 - g); | ||
sdsep = 15; | ||
prob_scat_moving_scat = 1; | ||
|
||
|
||
[tau,g1]=generate_g1('dcs.mch',logspace(-8,0,200),'brownian',Db); | ||
[tau, g1] = generate_g1('dcs.mch', logspace(-8, 0, 200), 'brownian', Db); | ||
|
||
figure(1); | ||
for I=1:4, | ||
subplot(2,2,I); | ||
semilogx(tau,g1(I,:),'.'); | ||
x=fminsearch(@(x) dcs_g1_Db_fms(x,tau,g1(I,:),sdsep,mua,musp,prob_scat_moving_scat),[1e-5]); | ||
for I = 1:4 | ||
subplot(2, 2, I); | ||
semilogx(tau, g1(I, :), '.'); | ||
x = fminsearch(@(x) dcs_g1_Db_fms(x, tau, g1(I, :), sdsep, mua, musp, prob_scat_moving_scat), [1e-5]); | ||
hold on; | ||
semilogx(tau,dcs_g1_Db(x,tau,sdsep,mua,musp,prob_scat_moving_scat),'r'); | ||
xlabel('\tau (s)'); ylabel('g_1(\tau)');axis tight; | ||
title(['Det ' num2str(I) ': fit Db: ' sprintf('%.2g',x) ' err: ' num2str((x-Db)/Db*100,'%.1f') '%']); | ||
semilogx(tau, dcs_g1_Db(x, tau, sdsep, mua, musp, prob_scat_moving_scat), 'r'); | ||
xlabel('\tau (s)'); | ||
ylabel('g_1(\tau)'); | ||
axis tight; | ||
title(['Det ' num2str(I) ': fit Db: ' sprintf('%.2g', x) ' err: ' num2str((x - Db) / Db * 100, '%.1f') '%']); | ||
end | ||
|
||
figure(2); | ||
for I=1:4, | ||
subplot(2,2,I); | ||
g2=1+sim_beta*g1(I,:).^2; | ||
semilogx(tau,g2,'.'); | ||
x=fminsearch(@(x) dcs_g2_Db_fms(x,tau,g2,sdsep,mua,musp,prob_scat_moving_scat),[1e-5 0.5]); | ||
figure(2); | ||
for I = 1:4 | ||
subplot(2, 2, I); | ||
g2 = 1 + sim_beta * g1(I, :).^2; | ||
semilogx(tau, g2, '.'); | ||
x = fminsearch(@(x) dcs_g2_Db_fms(x, tau, g2, sdsep, mua, musp, prob_scat_moving_scat), [1e-5 0.5]); | ||
hold on; | ||
semilogx(tau,dcs_g2_Db(x(1),tau,sdsep,mua,musp,prob_scat_moving_scat,x(2)),'r'); | ||
xlabel('\tau (s)'); ylabel('g_2(\tau)');axis tight; | ||
title(['Det ' num2str(I) ': fit Db: ' sprintf('%.2g',x(1)) ' err: ' num2str((x(1)-Db)/Db*100,'%.1f') '%']); | ||
semilogx(tau, dcs_g2_Db(x(1), tau, sdsep, mua, musp, prob_scat_moving_scat, x(2)), 'r'); | ||
xlabel('\tau (s)'); | ||
ylabel('g_2(\tau)'); | ||
axis tight; | ||
title(['Det ' num2str(I) ': fit Db: ' sprintf('%.2g', x(1)) ' err: ' num2str((x(1) - Db) / Db * 100, '%.1f') '%']); | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,18 @@ | ||
function result=dcs_g1_Db(Db,tau,sdsep,mu_a,mu_sp,alpha) | ||
% | ||
function result = dcs_g1_Db(Db, tau, sdsep, mu_a, mu_sp, alpha) | ||
% | ||
% this function generates analytical auto-correlation decay for a semi- | ||
% infinite medium | ||
% | ||
% sdsep, mu_a and mu_sp units must be mm | ||
|
||
zo=(mu_sp+mu_a)^-1; zb= 1.76/mu_sp; % this assumes n_tissue=1.35 | ||
r1=(sdsep^2+zo^2)^(1/2); r2=(sdsep^2+(zo+2*zb)^2)^(1/2); | ||
k0=2*pi*1.35/(785*1e-6); %wavelength=786e-6 mm! | ||
kd=(3*mu_sp*mu_a+mu_sp^2*k0^2*alpha.*(6*Db.*tau)).^(1/2); | ||
kd0=(3*mu_sp*mu_a).^(1/2); | ||
fit_g1=exp(-kd.*r1)/r1-exp(-kd.*r2)/r2; | ||
fit_g1_norm=exp(-kd0.*r1)/r1-exp(-kd0.*r2)/r2; | ||
zo = (mu_sp + mu_a)^-1; | ||
zb = 1.76 / mu_sp; % this assumes n_tissue=1.35 | ||
r1 = (sdsep^2 + zo^2)^(1 / 2); | ||
r2 = (sdsep^2 + (zo + 2 * zb)^2)^(1 / 2); | ||
k0 = 2 * pi * 1.35 / (785 * 1e-6); % wavelength=786e-6 mm! | ||
kd = (3 * mu_sp * mu_a + mu_sp^2 * k0^2 * alpha .* (6 * Db .* tau)).^(1 / 2); | ||
kd0 = (3 * mu_sp * mu_a).^(1 / 2); | ||
fit_g1 = exp(-kd .* r1) / r1 - exp(-kd .* r2) / r2; | ||
fit_g1_norm = exp(-kd0 .* r1) / r1 - exp(-kd0 .* r2) / r2; | ||
|
||
result=fit_g1/fit_g1_norm; | ||
result = fit_g1 / fit_g1_norm; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,18 @@ | ||
function result=dcs_g1_Db_fms(Db,tau,g1,sdsep,mu_a,mu_sp,alpha) | ||
% | ||
function result = dcs_g1_Db_fms(Db, tau, g1, sdsep, mu_a, mu_sp, alpha) | ||
% | ||
% this function generates analytical auto-correlation decay for a semi- | ||
% infinite medium, and computes the rms error for fminsearch fitting | ||
% | ||
% sdsep, mu_a and mu_sp units must be mm | ||
|
||
zo=(mu_sp+mu_a)^-1; zb= 1.76/mu_sp; % this assumes n_tissue=1.35 | ||
r1=(sdsep^2+zo^2)^(1/2); r2=(sdsep^2+(zo+2*zb)^2)^(1/2); | ||
k0=2*pi*1.35/(785*1e-6); %wavelength=786e-6 mm! | ||
kd=(3*mu_sp*mu_a+mu_sp^2*k0^2*alpha.*(6*Db.*tau)).^(1/2); | ||
kd0=(3*mu_sp*mu_a).^(1/2); | ||
fit_g1=exp(-kd.*r1)/r1-exp(-kd.*r2)/r2; | ||
fit_g1_norm=exp(-kd0.*r1)/r1-exp(-kd0.*r2)/r2; | ||
zo = (mu_sp + mu_a)^-1; | ||
zb = 1.76 / mu_sp; % this assumes n_tissue=1.35 | ||
r1 = (sdsep^2 + zo^2)^(1 / 2); | ||
r2 = (sdsep^2 + (zo + 2 * zb)^2)^(1 / 2); | ||
k0 = 2 * pi * 1.35 / (785 * 1e-6); % wavelength=786e-6 mm! | ||
kd = (3 * mu_sp * mu_a + mu_sp^2 * k0^2 * alpha .* (6 * Db .* tau)).^(1 / 2); | ||
kd0 = (3 * mu_sp * mu_a).^(1 / 2); | ||
fit_g1 = exp(-kd .* r1) / r1 - exp(-kd .* r2) / r2; | ||
fit_g1_norm = exp(-kd0 .* r1) / r1 - exp(-kd0 .* r2) / r2; | ||
|
||
result=sum((g1-fit_g1/fit_g1_norm).^2); | ||
result = sum((g1 - fit_g1 / fit_g1_norm).^2); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,20 @@ | ||
function g2=dcs_g2_Db(Db,tau,sdsep,mu_a,mu_sp,alpha,beta) | ||
% | ||
function g2 = dcs_g2_Db(Db, tau, sdsep, mu_a, mu_sp, alpha, beta) | ||
% | ||
% this function generates analytical field auto-correlation decay for a semi- | ||
% infinite medium, then uses the Siegert relationship to derive the | ||
% intensity temporal auto-correlation decay assuming ergodicity | ||
% | ||
% sdsep, mu_a and mu_sp units must be mm | ||
|
||
zo=(mu_sp+mu_a)^-1; zb= 1.76/mu_sp; % this assumes n_tissue=1.35 | ||
r1=(sdsep^2+zo^2)^(1/2); r2=(sdsep^2+(zo+2*zb)^2)^(1/2); | ||
k0=2*pi*1.35/(785*1e-6); %wavelength=786e-6 mm! | ||
kd=(3*mu_sp*mu_a+mu_sp^2*k0^2*alpha.*(6*Db.*tau)).^(1/2); | ||
kd0=(3*mu_sp*mu_a).^(1/2); | ||
fit_g1=exp(-kd.*r1)/r1-exp(-kd.*r2)/r2; | ||
fit_g1_norm=exp(-kd0.*r1)/r1-exp(-kd0.*r2)/r2; | ||
|
||
g1_norm=fit_g1/fit_g1_norm; | ||
g2=1+beta*(g1_norm).^2; | ||
zo = (mu_sp + mu_a)^-1; | ||
zb = 1.76 / mu_sp; % this assumes n_tissue=1.35 | ||
r1 = (sdsep^2 + zo^2)^(1 / 2); | ||
r2 = (sdsep^2 + (zo + 2 * zb)^2)^(1 / 2); | ||
k0 = 2 * pi * 1.35 / (785 * 1e-6); % wavelength=786e-6 mm! | ||
kd = (3 * mu_sp * mu_a + mu_sp^2 * k0^2 * alpha .* (6 * Db .* tau)).^(1 / 2); | ||
kd0 = (3 * mu_sp * mu_a).^(1 / 2); | ||
fit_g1 = exp(-kd .* r1) / r1 - exp(-kd .* r2) / r2; | ||
fit_g1_norm = exp(-kd0 .* r1) / r1 - exp(-kd0 .* r2) / r2; | ||
|
||
g1_norm = fit_g1 / fit_g1_norm; | ||
g2 = 1 + beta * (g1_norm).^2; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,25 @@ | ||
function result=dcs_g2_Db_fms(s,tau,g2,sdsep,mu_a,mu_sp,alpha) | ||
% | ||
function result = dcs_g2_Db_fms(s, tau, g2, sdsep, mu_a, mu_sp, alpha) | ||
% | ||
% this function generates analytical field auto-correlation decay for a semi- | ||
% infinite medium, then uses the Siegert relationship to derive the | ||
% intensity temporal auto-correlation decay assuming ergodicity | ||
% | ||
% sdsep, mu_a and mu_sp units must be mm | ||
|
||
Db=s(1); | ||
beta=s(2); | ||
Db = s(1); | ||
beta = s(2); | ||
|
||
zo=(mu_sp+mu_a)^-1; zb= 1.76/mu_sp; % this assumes n_tissue=1.35 | ||
r1=(sdsep^2+zo^2)^(1/2); r2=(sdsep^2+(zo+2*zb)^2)^(1/2); | ||
k0=2*pi*1.35/(785*1e-6); %wavelength=786e-6 mm! | ||
kd=(3*mu_sp*mu_a+mu_sp^2*k0^2*alpha.*(6*Db.*tau)).^(1/2); | ||
kd0=(3*mu_sp*mu_a).^(1/2); | ||
fit_g1=exp(-kd.*r1)/r1-exp(-kd.*r2)/r2; | ||
fit_g1_norm=exp(-kd0.*r1)/r1-exp(-kd0.*r2)/r2; | ||
zo = (mu_sp + mu_a)^-1; | ||
zb = 1.76 / mu_sp; % this assumes n_tissue=1.35 | ||
r1 = (sdsep^2 + zo^2)^(1 / 2); | ||
r2 = (sdsep^2 + (zo + 2 * zb)^2)^(1 / 2); | ||
k0 = 2 * pi * 1.35 / (785 * 1e-6); % wavelength=786e-6 mm! | ||
kd = (3 * mu_sp * mu_a + mu_sp^2 * k0^2 * alpha .* (6 * Db .* tau)).^(1 / 2); | ||
kd0 = (3 * mu_sp * mu_a).^(1 / 2); | ||
fit_g1 = exp(-kd .* r1) / r1 - exp(-kd .* r2) / r2; | ||
fit_g1_norm = exp(-kd0 .* r1) / r1 - exp(-kd0 .* r2) / r2; | ||
|
||
g1_norm=fit_g1/fit_g1_norm; | ||
fit_g2=1+beta*(g1_norm).^2; | ||
g1_norm = fit_g1 / fit_g1_norm; | ||
fit_g2 = 1 + beta * (g1_norm).^2; | ||
|
||
result=sum((g2-fit_g2).^2); | ||
result = sum((g2 - fit_g2).^2); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
dim=60; | ||
[xi,yi,zi]=meshgrid(1:dim,1:dim,1:dim); | ||
dist=(xi-30).^2+(yi-30).^2+(zi-30).^2; | ||
dim = 60; | ||
[xi, yi, zi] = meshgrid(1:dim, 1:dim, 1:dim); | ||
dist = (xi - 30).^2 + (yi - 30).^2 + (zi - 30).^2; | ||
|
||
v=zeros(size(xi)); | ||
v(dist<100)=1; | ||
v=v+1; | ||
v = zeros(size(xi)); | ||
v(dist < 100) = 1; | ||
v = v + 1; | ||
|
||
fid=fopen('spherebox.bin','wb'); | ||
aa=fwrite(fid,v,'uchar'); | ||
fid = fopen('spherebox.bin', 'wb'); | ||
aa = fwrite(fid, v, 'uchar'); | ||
fclose(fid); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.