Skip to content

Commit

Permalink
Add filters figures
Browse files Browse the repository at this point in the history
  • Loading branch information
mathieuboudreau committed Oct 4, 2024
1 parent 9bb6d42 commit 9f94e16
Show file tree
Hide file tree
Showing 14 changed files with 501 additions and 140 deletions.
Binary file modified .DS_Store
Binary file not shown.
80 changes: 0 additions & 80 deletions 03-T2/content/T2w_vs_T2map.asv

This file was deleted.

30 changes: 0 additions & 30 deletions 03-T2/content/multiexpo_T2_curves.asv

This file was deleted.

30 changes: 0 additions & 30 deletions 03-T2/content/multiexpo_T2_image.asv

This file was deleted.

7 changes: 7 additions & 0 deletions 04-B1/03-Filtering/binder/postBuild
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash

git clone https://www.github.com/qMRLab/qMRLab.git ../qMRLab
cd ../qMRLab
git checkout f481d86da7272ee0f74abdbe9020cf93be06000f
cd binder

1 change: 1 addition & 0 deletions 04-B1/03-Filtering/binder/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
repo2data
63 changes: 63 additions & 0 deletions 04-B1/03-Filtering/content/b1filt_fig1.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
clear all
clc
close all
%%

dim = 128;
x=linspace(1,dim,dim);

signal = 1000;

PulseOpt.slope = dim/100;

b1_func = signal*fermi_pulse(x, dim, PulseOpt);

%%

filtered_obj = filter_map();
filtered_obj.options.Smoothingfilter_Dimension = '2D';
data.Raw = repmat(b1_func, dim, 1);

vox_range = 1:25;

gauss_b1_1d = zeros(length(vox_range), dim);
median_b1_1d = zeros(length(vox_range), dim);

for ii=1:length(vox_range)
fwhm_vox = vox_range(ii);

filtered_obj.options.Smoothingfilter_sizex = fwhm_vox;
filtered_obj.options.Smoothingfilter_sizey = fwhm_vox;
filtered_obj.options.Smoothingfilter_sizez = fwhm_vox;

filtered_obj.options.Smoothingfilter_Type = 'gaussian';
fit_results = filtered_obj.fit(data);
gauss_b1_1d(ii,:) = fit_results.Filtered(1,:);


filtered_obj.options.Smoothingfilter_Type = 'median';
fit_results = filtered_obj.fit(data);
median_b1_1d(ii,:) = fit_results.Filtered(1,:);
end


order_range = 1:25;

spline_b1_1d = zeros(length(order_range), dim);
poly_b1_1d = zeros(length(order_range), dim);


for ii=1:length(order_range)
filtered_obj.options.Smoothingfilter_order = order_range(ii);

filtered_obj.options.Smoothingfilter_Type = 'spline';
fit_results = filtered_obj.fit(data);
spline_b1_1d(ii,:) = fit_results.Filtered(1,:);


filtered_obj.options.Smoothingfilter_Type = 'polynomial';
fit_results = filtered_obj.fit(data);
poly_b1_1d(ii,:) = fit_results.Filtered(1,:);
end

save("b1filt_fig1.mat", "b1_func", "gauss_b1_1d", "median_b1_1d", "spline_b1_1d", "poly_b1_1d", "vox_range", "order_range")
44 changes: 44 additions & 0 deletions 04-B1/03-Filtering/content/b1filt_fig1_fixed.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
clear all
clc
close all
%%

dim = 128;
x=linspace(1,dim,dim);

signal = 1000;

PulseOpt.slope = dim/100;

b1_func = signal*fermi_pulse(x, dim, PulseOpt);

%%

vox_range = 1:10;

gauss_b1_1d = zeros(length(vox_range), dim);
median_b1_1d = zeros(length(vox_range), dim);
spline_b1_1d = zeros(length(vox_range), dim);

for ii=1:length(vox_range)

% Gaussian
w = gausswin(2*vox_range(ii)+1, 2);
w = w/sum(w);

tmp_data = [zeros(1, vox_range(ii)) b1_func zeros(1, vox_range(ii))];

tmp = filter(w, 1, tmp_data);
shifted_tmp_data = [tmp(vox_range(ii)+1:end) zeros(1,vox_range(ii))];
shifted_tmp_data(1:vox_range(ii)) = [];
shifted_tmp_data(end-vox_range(ii)+1:end) = [];
gauss_b1_1d(ii,:) = shifted_tmp_data;

% Median
median_b1_1d(ii,:) = medfilt1(b1_func,vox_range(ii));

% Spline
spline_b1_1d(ii,:) = smoothn(b1_func, vox_range(ii));
end

save("b1filt_fig1.mat", "b1_func", "gauss_b1_1d", "median_b1_1d", "spline_b1_1d", "vox_range")
63 changes: 63 additions & 0 deletions 04-B1/03-Filtering/content/b1filt_fig2.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
clear all
clc
close all
%%

dim = 128;
x=linspace(1,dim,dim);

signal = 1000;

PulseOpt.slope = dim/100;

b1_func = signal*fermi_pulse(x, dim, PulseOpt);

%% Add noise

SNR_range = 1:100;
noisy_b1_1d = zeros(length(SNR_range), dim);

%%

filtered_obj = filter_map();
filtered_obj.options.Smoothingfilter_Dimension = '2D';

fwhm_vox = 5;
filtered_obj.options.Smoothingfilter_sizex = fwhm_vox;
filtered_obj.options.Smoothingfilter_sizey = fwhm_vox;
filtered_obj.options.Smoothingfilter_sizez = fwhm_vox;

filtered_obj.options.Smoothingfilter_order = 6;

noisy_b1 = zeros(length(SNR_range), dim);
gauss_b1_1d = zeros(length(SNR_range), dim);
median_b1_1d = zeros(length(SNR_range), dim);
spline_b1_1d = zeros(length(SNR_range), dim);
poly_b1_1d = zeros(length(SNR_range), dim);

for ii=1:length(SNR_range)
noisy_b1(ii,:) = addNoise(b1_func, SNR_range(ii));
data.Raw = repmat(noisy_b1(ii,:), dim, 1);


filtered_obj.options.Smoothingfilter_Type = 'gaussian';
fit_results = filtered_obj.fit(data);
gauss_b1_1d(ii,:) = fit_results.Filtered(1,:);


filtered_obj.options.Smoothingfilter_Type = 'median';
fit_results = filtered_obj.fit(data);
median_b1_1d(ii,:) = fit_results.Filtered(1,:);


filtered_obj.options.Smoothingfilter_Type = 'spline';
fit_results = filtered_obj.fit(data);
spline_b1_1d(ii,:) = fit_results.Filtered(1,:);


filtered_obj.options.Smoothingfilter_Type = 'polynomial';
fit_results = filtered_obj.fit(data);
poly_b1_1d(ii,:) = fit_results.Filtered(1,:);
end

save("b1filt_fig2.mat", "b1_func", "noisy_b1", "gauss_b1_1d", "median_b1_1d", "spline_b1_1d", "poly_b1_1d", "SNR_range")
62 changes: 62 additions & 0 deletions 04-B1/03-Filtering/content/b1filt_fig2_fixed.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
clear all
clc
close all
%%

dim = 128;
x=linspace(1,dim,dim);

signal = 1000;

PulseOpt.slope = dim/100;

b1_func = signal*fermi_pulse(x, dim, PulseOpt);

%% Add noise

SNR_range = 1:100;
noisy_b1_1d = zeros(length(SNR_range), dim);

%%

filtered_obj = filter_map();
filtered_obj.options.Smoothingfilter_Dimension = '2D';

fwhm_vox = 5;
filtered_obj.options.Smoothingfilter_sizex = fwhm_vox;
filtered_obj.options.Smoothingfilter_sizey = fwhm_vox;
filtered_obj.options.Smoothingfilter_sizez = fwhm_vox;

smoothingfilter_order = 6;

noisy_b1 = zeros(length(SNR_range), dim);
gauss_b1_1d = zeros(length(SNR_range), dim);
median_b1_1d = zeros(length(SNR_range), dim);
spline_b1_1d = zeros(length(SNR_range), dim);
poly_b1_1d = zeros(length(SNR_range), dim);

for ii=1:length(SNR_range)

noisy_b1(ii,:) = addNoise(b1_func, SNR_range(ii));
data.Raw = repmat(noisy_b1(ii,:), dim, 1);

% Gaussian
w = gausswin(2*fwhm_vox+1, 2);
w = w/sum(w);

tmp_data = [zeros(1, fwhm_vox) noisy_b1(ii,:) zeros(1, fwhm_vox)];

tmp = filter(w, 1, tmp_data);
shifted_tmp_data = [tmp(fwhm_vox+1:end) zeros(1,fwhm_vox)];
shifted_tmp_data(1:fwhm_vox) = [];
shifted_tmp_data(end-fwhm_vox+1:end) = [];
gauss_b1_1d(ii,:) = shifted_tmp_data;

% Median
median_b1_1d(ii,:) = medfilt1(noisy_b1(ii,:),fwhm_vox);

% Spline
spline_b1_1d(ii,:) = smoothn(noisy_b1(ii,:), smoothingfilter_order);
end

save("b1filt_fig2.mat", "b1_func", "noisy_b1", "gauss_b1_1d", "median_b1_1d", "spline_b1_1d", "SNR_range")
Loading

0 comments on commit 9f94e16

Please sign in to comment.