Skip to content

Commit a925c6d

Browse files
committed
[optional bug] fix MNI summary plots
Fix errors for tissue-specific heating spec; save combined files in simulation-specific in root of subdirectory; cleanup temp; properly deal with skipping missing files
1 parent 56ffa52 commit a925c6d

File tree

2 files changed

+26
-23
lines changed

2 files changed

+26
-23
lines changed

functions/combine_plots_by_suffix.m

+13-18
Original file line numberDiff line numberDiff line change
@@ -7,33 +7,28 @@ function combine_plots_by_suffix(suffix, outputs_path, subject_list, parameters,
77

88
options.font_size = 64
99
end
10-
if ~exist(sprintf('%stmp/', outputs_path),'dir')
11-
mkdir(sprintf('%stmp/', outputs_path));
10+
if ~exist(sprintf('%s/tmp/', outputs_path),'dir')
11+
mkdir(sprintf('%s/tmp/', outputs_path));
1212
end
13-
system(sprintf('cd "%stmp/"; rm *.png', outputs_path));
14-
if parameters.subject_subfolder
15-
orig_imsize = size(imread(fullfile(outputs_path, sprintf('sub-%03i/sub-%03i_%s.png', subject_list(1),subject_list(1), suffix))));
16-
% imarray = uint8(zeros(size(imread(fullfile(outputs_path, sprintf('sub-%03i/sub-%03i_%s.png', subject_list(end), subject_list(end), suffix))))));
17-
else
18-
orig_imsize = size(imread(fullfile(outputs_path, sprintf('sub-%03i_%s.png', subject_list(1), suffix))));
19-
% imarray = uint8(zeros(size(imread(fullfile(outputs_path, sprintf('sub-%03i_%s.png', subject_list(end), suffix))))));
20-
end
21-
22-
% imarray = repmat(imarray, 1, 1, 1, length(subject_list));
13+
2314
for subject_i = 1:length(subject_list)
2415
if parameters.subject_subfolder
25-
old_name = fullfile(outputs_path, sprintf('sub-%03i/sub-%03i_%s.png', subject_list(subject_i), subject_list(subject_i), suffix));
16+
sub_path = fullfile(outputs_path, sprintf('sub-%03i', subject_list(subject_i)));
2617
else
27-
old_name = fullfile(outputs_path, sprintf('sub-%03i_%s.png', subject_list(subject_i), suffix));
18+
sub_path = fullfile(outputs_path);
2819
end
20+
old_name = fullfile(sub_path, sprintf('sub-%03i_%s.png', subject_list(subject_i), suffix));
21+
orig_imsize = size(imread(old_name));
2922
I = imread(old_name);
3023
I = padarray(I, max([0 0 0; orig_imsize-size(I)],[], 1), I(1), 'pre');
31-
3224
I = insertText(I,[0 5],sprintf('P%02i',subject_list(subject_i)),'FontSize', options.font_size, 'BoxOpacity',0,'TextColor','white');
33-
%imarray(1:size(I, 1), 1:size(I, 2), 1:size(I, 3), subject_i) = I;
34-
new_name = sprintf('%stmp/%i.png', outputs_path, subject_list(subject_i));
25+
new_name = sprintf('%s/tmp/%i.png', outputs_path, subject_list(subject_i));
3526
imwrite(I, new_name);
3627
end
3728

38-
system(sprintf('cd "%stmp/"; montage -background black -gravity south -mode concatenate $(ls -1 *.png | sort -g) ../all_%s.png', convertCharsToStrings(outputs_path), suffix));
29+
system(sprintf('cd "%s/tmp/"; montage -background black -gravity south -mode concatenate $(ls -1 *.png | sort -g) ../all_%s.png', convertCharsToStrings(outputs_path), suffix));
30+
31+
% remove temporary directory
32+
system(sprintf('cd "%s/tmp/"; rm *.png', outputs_path));
33+
rmdir(sprintf('%s/tmp/', outputs_path));
3934
end

functions/create_group_MNI_plots.m

+13-5
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,17 @@ function create_group_MNI_plots(subject_list, parameters, options)
2020
assert(xor(options.plot_max_intensity,options.slice_to_plot), "You should indicate either the slice number to plot ('slice_to_plot') or ask for a max intensity plot ('plot_max_intensity')")
2121
slice_labels = {'x','y','z'};
2222

23-
2423
outputs_path = parameters.temp_output_dir;
2524
bg_range_to_use = [];
2625
isppa_range_to_use = [5, 6];
27-
temp_range_to_use = [parameters.thermal.temp_0, parameters.thermal.temp_0 + 0.5];
26+
% Note: with tissue-specific heating values, the plotting may not work as intended?
27+
if isstruct(parameters.thermal.temp_0)
28+
temp_range_to_use = [parameters.thermal.temp_0.skin, parameters.thermal.temp_0.water + 0.5];
29+
temp_0_min = parameters.thermal.temp_0.skin;
30+
else
31+
temp_range_to_use = [parameters.thermal.temp_0, parameters.thermal.temp_0 + 0.5];
32+
temp_0_min = parameters.thermal.temp_0;
33+
end
2834

2935
full_subject_list = subject_list;
3036
% first pass: get background intensity at the target slice & isppa range
@@ -65,7 +71,7 @@ function create_group_MNI_plots(subject_list, parameters, options)
6571
if ~exist(filename{:}, 'file')
6672
if options.skip_missing
6773
sprintf('File does not exist: %s; skipping this subject', filename{:})
68-
subject_list(subject_i) = [];
74+
subject_list(subject_i) = NaN;
6975
all_files_exist = 0;
7076

7177
break;
@@ -136,7 +142,7 @@ function create_group_MNI_plots(subject_list, parameters, options)
136142
new_water_ind = zeros(1, length(water_ind));
137143
heating_mask = logical(changem_vectorized(segmented_image_mni, new_water_ind, water_ind));
138144
maxT_mni = maxT_mni.*heating_mask;
139-
maxT_mni(maxT_mni==0) = parameters.thermal.temp_0;
145+
maxT_mni(maxT_mni==0) = temp_0_min;
140146

141147
maxT_slice = get_slice_by_label(maxT_mni, options.slice_label, slice_n);
142148

@@ -148,6 +154,8 @@ function create_group_MNI_plots(subject_list, parameters, options)
148154
end
149155
end
150156

157+
% remove unavailable subjects
158+
subject_list(isnan(subject_list)) = [];
151159

152160
% second pass, doing the actual images
153161
for subject_i = 1:length(subject_list)
@@ -221,7 +229,7 @@ function create_group_MNI_plots(subject_list, parameters, options)
221229
new_water_ind = zeros(1, length(water_ind));
222230
heating_mask = logical(changem_vectorized(segmented_image_mni, new_water_ind, water_ind));
223231
maxT_mni = maxT_mni.*heating_mask;
224-
maxT_mni(maxT_mni==0) = parameters.thermal.temp_0;
232+
maxT_mni(maxT_mni==0) = temp_0_min;
225233
end
226234

227235
if options.slice_to_plot

0 commit comments

Comments
 (0)