Skip to content

Commit

Permalink
[format] automatic format all matlab script with miss_hit
Browse files Browse the repository at this point in the history
  • Loading branch information
fangq committed Jan 1, 2024
1 parent 9951dd8 commit 51003bc
Show file tree
Hide file tree
Showing 78 changed files with 3,665 additions and 3,598 deletions.
11 changes: 11 additions & 0 deletions .miss_hit
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
project_root

suppress_rule: "redundant_brackets"
suppress_rule: "line_length"
suppress_rule: "file_length"
suppress_rule: "copyright_notice"
suppress_rule: "naming_functions"
suppress_rule: "naming_parameters"
suppress_rule: "naming_scripts"
suppress_rule: "unicode"
indent_function_file_body: false
23 changes: 11 additions & 12 deletions example/masktest/plotresults.m
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
fid=fopen('mtest.mask','rb');
dat=fread(fid,inf,'uchar');
fid = fopen('mtest.mask', 'rb');
dat = fread(fid, inf, 'uchar');
fclose(fid);

dat=reshape(dat,[8 8 8]);
pcolor(dat(:,:,1)')
dat = reshape(dat, [8 8 8]);
pcolor(dat(:, :, 1)');

r=3;
s=0:pi/20:2*pi;
c0=[4.9,4.1];
x=c0(1)+r*cos(s);
y=c0(2)+r*sin(s);

hold on
plot(x,y,'y-');
r = 3;
s = 0:pi / 20:2 * pi;
c0 = [4.9, 4.1];
x = c0(1) + r * cos(s);
y = c0(2) + r * sin(s);

hold on;
plot(x, y, 'y-');
14 changes: 7 additions & 7 deletions example/multipattern/plotresults.m
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
dat=loadjson('multipattern.jnii',[3 60 60 60]);
dat = loadjson('multipattern.jnii', [3 60 60 60]);
figure;
subplot(131);
imagesc(squeeze(log10(abs(dat(1,:,:,10))))')
axis equal
imagesc(squeeze(log10(abs(dat(1, :, :, 10))))');
axis equal;
subplot(132);
imagesc(squeeze(log10(abs(dat(2,:,:,10))))')
axis equal
imagesc(squeeze(log10(abs(dat(2, :, :, 10))))');
axis equal;
subplot(133);
imagesc(squeeze(log10(abs(dat(3,:,:,10))))')
axis equal
imagesc(squeeze(log10(abs(dat(3, :, :, 10))))');
axis equal;
78 changes: 47 additions & 31 deletions example/polarized/onelayer_plot_results.m
Original file line number Diff line number Diff line change
Expand Up @@ -5,62 +5,78 @@
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%% load mcx input and output file
data=loadjson("onelayer_detp.jdat");
cfg=loadjson("onelayer.json");
data = loadjson("onelayer_detp.jdat");
cfg = loadjson("onelayer.json");

%% compute total reflectance
nphotons=cfg.Session.Photons;
nphotons = cfg.Session.Photons;

% extract simulation settings needed for post-processing
unitinmm=cfg.Domain.LengthUnit; % dx,dy,dz in mm
unitinmm = cfg.Domain.LengthUnit; % dx,dy,dz in mm

% default ambient medium
prop=[0 0 1 1];
prop = [0 0 1 1];

% absorption coefficent (in 1/mm) of each tissue type
mua=cellfun(@(f)getfield(f,'mua'),cfg.Domain.MieScatter)';
prop=[prop;mua, zeros(size(mua,1),3)];
mua = cellfun(@(f)getfield(f, 'mua'), cfg.Domain.MieScatter)';
prop = [prop; mua, zeros(size(mua, 1), 3)];

% photon exiting direction
u=data(:,6:8);
phi=atan2(u(:,2),u(:,1));
u = data(:, 6:8);
phi = atan2(u(:, 2), u(:, 1));

% photon exiting Stokes Vector
s=data(:,10:13);
S2=[s(:,1),s(:,2).*cos(2.*phi)+s(:,3).*sin(2.*phi),...
-s(:,2).*sin(2.*phi)+s(:,3).*cos(2.*phi),s(:,4)];
s = data(:, 10:13);
S2 = [s(:, 1), s(:, 2) .* cos(2 .* phi) + s(:, 3) .* sin(2 .* phi), ...
-s(:, 2) .* sin(2 .* phi) + s(:, 3) .* cos(2 .* phi), s(:, 4)];

% final weight of exiting photons
detphoton=struct();
detphoton.ppath=data(:,2);
w=mcxdetweight(detphoton,prop,unitinmm);
detphoton = struct();
detphoton.ppath = data(:, 2);
w = mcxdetweight(detphoton, prop, unitinmm);

% total reflected IQUV
R=S2'*w/nphotons;
R = S2' * w / nphotons;

%% plot 2-D images for I, Q, U, V
% extract x and y values of the exiting positions.
x=data(:,3);
y=data(:,4);
x = data(:, 3);
y = data(:, 4);

% define image dimension
NN=100;
NN = 100;

% 2D exiting positions are binned on the 2D plane (z=0)
xedges=0:cfg.Domain.Dim(1,1)/NN:cfg.Domain.Dim(1,1);
yedges=0:cfg.Domain.Dim(1,2)/NN:cfg.Domain.Dim(1,2);
ix=discretize(x,xedges);
iy=discretize(y,yedges);
idx1d=sub2ind([NN,NN],iy,ix); % x and y is flipped to match Jessica's code
xedges = 0:cfg.Domain.Dim(1, 1) / NN:cfg.Domain.Dim(1, 1);
yedges = 0:cfg.Domain.Dim(1, 2) / NN:cfg.Domain.Dim(1, 2);
ix = discretize(x, xedges);
iy = discretize(y, yedges);
idx1d = sub2ind([NN, NN], iy, ix); % x and y is flipped to match Jessica's code

% accumulate I Q U V
HIQUV=zeros(4,NN,NN);
for i=1:4
HIQUV(i,:,:)=reshape(accumarray(idx1d,S2(:,i)),[NN,NN]);
HIQUV = zeros(4, NN, NN);
for i = 1:4
HIQUV(i, :, :) = reshape(accumarray(idx1d, S2(:, i)), [NN, NN]);
end

% plot
subplot(2,2,1);imagesc(squeeze(HIQUV(1,:,:)));axis equal;title("HI");colorbar;
subplot(2,2,2);imagesc(squeeze(HIQUV(2,:,:)));axis equal;title("HQ");colorbar;
subplot(2,2,3);imagesc(squeeze(HIQUV(3,:,:)));axis equal;title("HU");colorbar;
subplot(2,2,4);imagesc(squeeze(HIQUV(4,:,:)));axis equal;title("HV");colorbar;
subplot(2, 2, 1);
imagesc(squeeze(HIQUV(1, :, :)));
axis equal;
title("HI");
colorbar;
subplot(2, 2, 2);
imagesc(squeeze(HIQUV(2, :, :)));
axis equal;
title("HQ");
colorbar;
subplot(2, 2, 3);
imagesc(squeeze(HIQUV(3, :, :)));
axis equal;
title("HU");
colorbar;
subplot(2, 2, 4);
imagesc(squeeze(HIQUV(4, :, :)));
axis equal;
title("HV");
colorbar;
11 changes: 5 additions & 6 deletions example/shapetest/plotshapemask.m
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
fid=fopen('jsonshape.mask','rb');
dat=fread(fid,inf,'uchar');
fid = fopen('jsonshape.mask', 'rb');
dat = fread(fid, inf, 'uchar');
fclose(fid);

dat=reshape(dat,[40 60 50]);
dat = reshape(dat, [40 60 50]);
figure;
imagesc(squeeze(dat(:,:,15)));
axis equal

imagesc(squeeze(dat(:, :, 15)));
axis equal;
85 changes: 42 additions & 43 deletions example/sphbox/plotresults.m
Original file line number Diff line number Diff line change
@@ -1,56 +1,55 @@
%%-----------------------------------------------------------------
%% -----------------------------------------------------------------
%% add paths to the necessary toolboxes
%%-----------------------------------------------------------------
%% -----------------------------------------------------------------

addpath('~/space/Projects/mcx/utils/')
addpath('~/space/Projects/mmc/matlab/')
addpath('~/space/Projects/mcx/utils/');
addpath('~/space/Projects/mmc/matlab/');

c0=299792458000;
twin=[5e-11:1e-10:5e-9];
gates=50;
clines=[-1:0.5:8];
c0 = 299792458000;
twin = [5e-11:1e-10:5e-9];
gates = 50;
clines = [-1:0.5:8];

%%-----------------------------------------------------------------
%% -----------------------------------------------------------------
%% load MCX results
%%-----------------------------------------------------------------
mcx=loadmc2('spherebox.mc2', [60 60 60 gates]);
cwmcx=sum(mcx,4);
%% -----------------------------------------------------------------
mcx = loadmc2('spherebox.mc2', [60 60 60 gates]);
cwmcx = sum(mcx, 4);

%%-----------------------------------------------------------------
%% -----------------------------------------------------------------
%% generate/load analytical solution for sphere inside infinite slab
%%-----------------------------------------------------------------
%% -----------------------------------------------------------------

%[phi_ana,xa,ya,za]=sphdiffusionslab(0,0,60,-22:0.8:22,0,-30:0.8:10);
%save sphdiffsemiinf.mat phi_ana xa ya za
% [phi_ana,xa,ya,za]=sphdiffusionslab(0,0,60,-22:0.8:22,0,-30:0.8:10);
% save sphdiffsemiinf.mat phi_ana xa ya za

load sphdiffsemiinf.mat
idx=find((xa(:)<-12 | xa(:)>12) & za(:)>-5);
phi_ana(idx)=nan;
idx=find((xa(:)<-10 | xa(:)>10) & za(:)>0);
phi_ana(idx)=nan;
load sphdiffsemiinf.mat;
idx = find((xa(:) < -12 | xa(:) > 12) & za(:) > -5);
phi_ana(idx) = nan;
idx = find((xa(:) < -10 | xa(:) > 10) & za(:) > 0);
phi_ana(idx) = nan;

%%-----------------------------------------------------------------
%% -----------------------------------------------------------------
%% generate the contour of the inclusion
%%-----------------------------------------------------------------

[xcirc,ycirc] = cylinder(10,200);
xcirc=xcirc(1,:)+30;
ycirc=ycirc(1,:)+30;

figure
hold on
[cc,hc]=contour(xa+30,za+31,log10(abs(phi_ana))+10,clines,'color',[0.7 0.7 0.7],'linewidth',2);
contour(log10(squeeze(abs(cwmcx(:,30,:)))'),clines,'b-')
plot(xcirc,ycirc,'k--','linewidth',2);

axis equal
set(gca,'xlim',[1 60]);
set(gca,'ylim',[1 60]);
set(gca,'fontsize',18)
xlabel('x (mm)')
ylabel('z (mm)')
legend('Diffusion','MCX')
%% -----------------------------------------------------------------

[xcirc, ycirc] = cylinder(10, 200);
xcirc = xcirc(1, :) + 30;
ycirc = ycirc(1, :) + 30;

figure;
hold on;
[cc, hc] = contour(xa + 30, za + 31, log10(abs(phi_ana)) + 10, clines, 'color', [0.7 0.7 0.7], 'linewidth', 2);
contour(log10(squeeze(abs(cwmcx(:, 30, :)))'), clines, 'b-');
plot(xcirc, ycirc, 'k--', 'linewidth', 2);

axis equal;
set(gca, 'xlim', [1 60]);
set(gca, 'ylim', [1 60]);
set(gca, 'fontsize', 18);
xlabel('x (mm)');
ylabel('z (mm)');
legend('Diffusion', 'MCX');
legend boxoff;
box on;
set(gcf,'PaperPositionMode','auto');

set(gcf, 'PaperPositionMode', 'auto');
Loading

0 comments on commit 51003bc

Please sign in to comment.