Bugfixes, general improvements.

This commit is contained in:
Karthik 2025-08-19 12:28:58 +02:00
parent 33573b5810
commit b0f45aa7e6
4 changed files with 50 additions and 25 deletions

View File

@ -38,14 +38,9 @@ function results_all = batchAnalyze(dataSources, options)
end end
% Build folder path % Build folder path
folderPath = fullfile(baseFolder, runID); folderPath = fullfile(baseFolder, runID);
if ~endsWith(folderPath, filesep)
folderPath = [char(folderPath) filesep];
else
folderPath = char(folderPath);
end
options.folderPath = folderPath; options.folderPath = folderPath;
try try
% Convert struct -> name-value args % Convert struct -> name-value args
args = [fieldnames(options), struct2cell(options)]'; args = [fieldnames(options), struct2cell(options)]';

View File

@ -32,11 +32,17 @@ function [od_imgs, scan_parameter_values, file_list] = collectODImages(options)
critical_fields = {'folderPath','cam','angle','ImagingMode','PulseDuration','center','span','fraction','removeFringes','skipUnshuffling','scan_reference_values'}; critical_fields = {'folderPath','cam','angle','ImagingMode','PulseDuration','center','span','fraction','removeFringes','skipUnshuffling','scan_reference_values'};
if ~haveOptionsChanged(options, prior_options, critical_fields) if ~haveOptionsChanged(options, prior_options, critical_fields)
fprintf('\nReusing processed OD images, scan parameters, and file list from memory (options unchanged).\n'); fprintf('\nReusing processed OD images, scan parameters, and file list from memory.\n');
od_imgs = evalin('base','od_imgs'); od_imgs = evalin('base','od_imgs');
scan_parameter_values = evalin('base','scan_parameter_values'); scan_parameter_values = evalin('base','scan_parameter_values');
file_list = evalin('base','file_list'); file_list = evalin('base','file_list');
return; % skip rest of the function
% --- Ensure figures exist if requested now ---
if ~options.skipSaveFigures
saveODFigures(od_imgs, options.saveDirectory);
end
return; % safe to exit now
else else
fprintf('\nProcessed-data-related options changed. Reprocessing full OD image dataset...\n'); fprintf('\nProcessed-data-related options changed. Reprocessing full OD image dataset...\n');
end end
@ -46,7 +52,8 @@ function [od_imgs, scan_parameter_values, file_list] = collectODImages(options)
fullDataExists = evalin('base', 'exist(''full_od_imgs'', ''var'')') && ... fullDataExists = evalin('base', 'exist(''full_od_imgs'', ''var'')') && ...
evalin('base', 'exist(''full_bkg_imgs'', ''var'')') && ... evalin('base', 'exist(''full_bkg_imgs'', ''var'')') && ...
evalin('base', 'exist(''raw_scan_parameter_values'', ''var'')') && ... evalin('base', 'exist(''raw_scan_parameter_values'', ''var'')') && ...
evalin('base', 'exist(''raw_file_list'', ''var'')'); evalin('base', 'exist(''raw_file_list'', ''var'')') && ...
evalin('base', 'exist(''prior_options'',''var'')');
if fullDataExists if fullDataExists
% Both required datasets exist, check if raw-data options changed % Both required datasets exist, check if raw-data options changed
@ -174,25 +181,17 @@ function [od_imgs, scan_parameter_values, file_list] = collectODImages(options)
assignin('base', 'file_list', file_list); assignin('base', 'file_list', file_list);
assignin('base', 'prior_options', options); assignin('base', 'prior_options', options);
% --- Optionally save OD images as figures --- % --- Save OD images as figures if requested ---
if ~options.skipSaveFigures if ~options.skipSaveFigures
odFolder = fullfile(options.saveDirectory, "Results", "ODImages"); saveODFigures(od_imgs, options.saveDirectory);
if ~exist(odFolder, 'dir')
mkdir(odFolder);
end
for k = 1:length(od_imgs)
img = od_imgs{k};
fileName = fullfile(odFolder, sprintf('OD_img_%03d.png', k));
imwrite(mat2gray(img), fileName);
end
end end
fprintf('\nOD image dataset ready for further analysis.\n'); fprintf('\nOD image dataset ready for further analysis.\n');
end end
% --- Local helper function to compare options --- %% --- Local helper functions ---
function changed = haveOptionsChanged(options, prior_options, critical_fields) function changed = haveOptionsChanged(options, prior_options, critical_fields)
changed = false; changed = false;
for f = critical_fields for f = critical_fields
@ -205,4 +204,35 @@ function changed = haveOptionsChanged(options, prior_options, critical_fields)
changed = true; return changed = true; return
end end
end end
end end
function saveODFigures(od_imgs, saveDirectory)
odFolder = fullfile(saveDirectory, "Results", "ODImages");
if ~exist(odFolder, 'dir')
mkdir(odFolder);
end
nImgs = length(od_imgs);
filesExist = all(arrayfun(@(k) isfile(fullfile(odFolder, sprintf('OD_img_%03d.fig', k))), 1:nImgs));
if filesExist
fprintf('\nOD figures already exist in %s. Skipping save.\n', odFolder);
return;
end
fprintf('\nSaving OD figures to %s ...\n', odFolder);
for k = 1:nImgs
img = od_imgs{k};
% Create invisible figure for saving
hFig = figure('Visible','off');
imagesc(img);
axis image off; colormap gray;
fileName = fullfile(odFolder, sprintf('OD_img_%03d.fig', k));
% Save as .fig
savefig(hFig, fileName);
close(hFig);
end
fprintf('OD figures saved successfully.\n');
end

View File

@ -103,7 +103,7 @@ set(0,'DefaultUicontrolFontSize',10); % increase default font size
'ListString', allPaths, ... 'ListString', allPaths, ...
'ListSize',[400, 300]); % width x height in pixels 'ListSize',[400, 300]); % width x height in pixels
if tf if tf
options.folderPath = allPaths{selectedIndex}; % store in options options.folderPath = fullfile(allPaths{selectedIndex}); % store in options
fprintf('Path set to selection: %s\n', options.folderPath); fprintf('Path set to selection: %s\n', options.folderPath);
else else
error('No path selected. Aborting.'); error('No path selected. Aborting.');

View File

@ -67,7 +67,7 @@ options.skipPreprocessing = true;
options.skipMasking = true; options.skipMasking = true;
options.skipIntensityThresholding = true; options.skipIntensityThresholding = true;
options.skipBinarization = true; options.skipBinarization = true;
options.skipSaveFigures = false; options.skipSaveFigures = true;
options.skipLivePlot = false; options.skipLivePlot = false;
options.showProgressBar = true; options.showProgressBar = true;