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,12 +38,7 @@ function results_all = batchAnalyze(dataSources, options)
end
% Build folder path
folderPath = fullfile(baseFolder, runID);
if ~endsWith(folderPath, filesep)
folderPath = [char(folderPath) filesep];
else
folderPath = char(folderPath);
end
folderPath = fullfile(baseFolder, runID);
options.folderPath = folderPath;
try

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'};
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');
scan_parameter_values = evalin('base','scan_parameter_values');
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
fprintf('\nProcessed-data-related options changed. Reprocessing full OD image dataset...\n');
end
@ -46,7 +52,8 @@ function [od_imgs, scan_parameter_values, file_list] = collectODImages(options)
fullDataExists = evalin('base', 'exist(''full_od_imgs'', ''var'')') && ...
evalin('base', 'exist(''full_bkg_imgs'', ''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
% 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', 'prior_options', options);
% --- Optionally save OD images as figures ---
% --- Save OD images as figures if requested ---
if ~options.skipSaveFigures
odFolder = fullfile(options.saveDirectory, "Results", "ODImages");
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
saveODFigures(od_imgs, options.saveDirectory);
end
fprintf('\nOD image dataset ready for further analysis.\n');
end
% --- Local helper function to compare options ---
%% --- Local helper functions ---
function changed = haveOptionsChanged(options, prior_options, critical_fields)
changed = false;
for f = critical_fields
@ -206,3 +205,34 @@ function changed = haveOptionsChanged(options, prior_options, critical_fields)
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, ...
'ListSize',[400, 300]); % width x height in pixels
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);
else
error('No path selected. Aborting.');

View File

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