From 2579e11196a9f3c94a0c616580863eab3f8fbaff Mon Sep 17 00:00:00 2001 From: johnaoga Date: Sat, 5 Apr 2025 09:21:31 +0200 Subject: [PATCH 1/2] init --- src/dic_param.m | 48 ++- src/lib/dic_matching.m | 95 ++++++ src/lib/dic_preparation.m | 218 +++++++++++++ src/lib/perform_tracking.m | 41 +++ src/lib/stepD_2DDIC.m | 623 ++++--------------------------------- 5 files changed, 452 insertions(+), 573 deletions(-) create mode 100644 src/lib/dic_matching.m create mode 100644 src/lib/dic_preparation.m create mode 100644 src/lib/perform_tracking.m diff --git a/src/dic_param.m b/src/dic_param.m index ac81284..86fc953 100644 --- a/src/dic_param.m +++ b/src/dic_param.m @@ -1,21 +1,57 @@ % STEP D, E, F: 2D-DIC, 3D Reconstruction, Deformation analysis + +%% Subject and Trial Settings subject_id = "S09"; % Subject identifier phase_id = "loading"; % Phase identifier material_id = 2; % Material identifier nfcond_set = [5]; % Number of conditions spddxlcond_set = [0.04, 0.08]; % Speed conditions -% Calibration settings +%% Calibration Settings calib_folder_set = "2"; +ref_trial_id = 5; % Reference trial number -% Reference trial number -ref_trial_id = 5; - -% Frame settings +%% Frame Settings idx_frame_start = 1; idx_frame_end = 150; frame_jump = 1; -% Visualization settings +%% Visualization Settings showvisu = 0; % Boolean for visualization debug_mode = 0; % Debug mode flag + +%% DIC Global Constants +DIC.TRUE_FPS = 50; +DIC.LIMIT_GRAYSCALE = struct(... + 'default', 100,... + 'early_subjects', 70,... + 'threshold', 8 % Subject numbers below this use early_subjects value +); + +%% DIC Analysis Parameters +DIC.filtering = struct(... + 'enabled', true +); + +DIC.ncorr = struct(... + 'analysis_direction', 'regular',... + 'subset_radius', struct(... + 'tracking', 40,... + 'matching', 60 + ),... + 'subset_spacing', 10,... + 'cutoff', struct(... + 'tracking', 1e-5,... + 'matching', 1e-5 + ),... + 'solver', struct(... + 'max_iterations', 100,... + 'num_threads', 1 + ),... + 'strain_analysis', struct(... + 'enabled', 1,... + 'propagation', 'seed',... + 'auto_ref_change', 1,... + 'step_ref_change', 10 + ) +); diff --git a/src/lib/dic_matching.m b/src/lib/dic_matching.m new file mode 100644 index 0000000..39a58c9 --- /dev/null +++ b/src/lib/dic_matching.m @@ -0,0 +1,95 @@ +function [matching_results] = dic_matching(prep_params) +% Get required parameters +base_parameters = prep_params.base_parameters; +step1_2_parameters = prep_params.step1_2_parameters; +cam_data = prep_params.cam_data; + +% Define file paths +roifile = fullfile(base_parameters.baseResultPath, base_parameters.subject, ... + base_parameters.material, sprintf("REF_MASK_%s_%s_pair%d.mat", ... + prep_params.reftrial, base_parameters.phase, base_parameters.stereopair)); + +matchingfile = fullfile(prep_params.outputPath, ... + sprintf("MATCHING2%s_pair%d.mat", prep_params.reftrial, base_parameters.stereopair)); + +seedfile = fullfile(base_parameters.baseResultPath, base_parameters.subject, ... + base_parameters.material, sprintf("REF_SEED_%s_%s_pair%d.mat", ... + prep_params.reftrial, base_parameters.phase, base_parameters.stereopair)); + +%% ROI and Seed initialization +% Draw ROI if needed +if ~exist(roifile, 'file') + draw_ref_roi(base_parameters); +end + +% Perform matching if needed +if ~exist(matchingfile, 'file') + ncorr_matching2ref(cam_data.first_satur(:,:,1), base_parameters, step1_2_parameters); +end + +% Load matching results +matching = load(matchingfile); +refmask_REF = matching.reference_save(1).roi.mask; +refmask_trial = matching.current_save(1).roi.mask; +fprintf('--> STEP: ROI loaded and formatted\n'); + +% Handle seed points +if ~exist(seedfile, 'file') + draw_ref_seed(base_parameters, 'roi', refmask_REF); +end + +% Load and map seed points +seed_point = load(seedfile); +ref_seed_point.pw = seed_point.seed_point; +ref_seed_point.sw = map_pixel2subset(ref_seed_point.pw, step1_2_parameters.spacing); + +% Map coordinates +U_mapped = matching.data_dic_save.displacements(1).plot_u_ref_formatted/(step1_2_parameters.spacing + 1); +V_mapped = matching.data_dic_save.displacements(1).plot_v_ref_formatted/(step1_2_parameters.spacing + 1); + +initial_seed_point_set1.sw = map_pointcoordinate(ref_seed_point.sw, {U_mapped, V_mapped}); +initial_seed_point_set1.pw = map_subset2pixel(initial_seed_point_set1.sw, step1_2_parameters.spacing); + +fprintf('--> STEP: SEED loaded and formatted\n'); + +%% Perform matching analysis +tic; +step1_2_parameters.initial_seed = initial_seed_point_set1.pw; + +siz = size(cam_data.first); +input1 = cam_data.first_satur(:,:,1); +input2 = zeros(siz(1), siz(2), 2, 'uint8'); +input2(:,:,1) = cam_data.second_satur(:,:,1); +input2(:,:,2) = cam_data.first_satur(:,:,1); + +[h12, file_logic] = ncorr_dic_rewrited('cam_number', [cam_data.cam_1, cam_data.cam_2],... + 'cam_data_ref', input1,... + 'cam_data_cur', input2,... + 'mask', refmask_trial,... + 'automatic_process', base_parameters.automatic_process,... + 'step_param', step1_2_parameters,... + 'base_param', base_parameters); + +% Get results for next step +refmask_trial_matched = h12.current(1).roi.mask; +U_mapped = h12.data_dic.displacements(1).plot_u_ref_formatted/(step1_2_parameters.spacing + 1); +V_mapped = h12.data_dic.displacements(1).plot_v_ref_formatted/(step1_2_parameters.spacing + 1); + +initial_seed_point_set2.sw = map_pointcoordinate(initial_seed_point_set1.sw, {U_mapped, V_mapped}); +initial_seed_point_set2.pw = map_subset2pixel(initial_seed_point_set2.sw, step1_2_parameters.spacing); + +if ~file_logic + close(h12.handles_gui.figure); +end +clear('h12'); + +elapsedTime = toc; +fprintf("--> STEP: Ncorr matching 1-2 done in %1.1fs\n", elapsedTime); + +%% Prepare output structure +matching_results = struct(... + 'refmask_trial', refmask_trial,... + 'refmask_trial_matched', refmask_trial_matched,... + 'initial_seed_point_set1', initial_seed_point_set1,... + 'initial_seed_point_set2', initial_seed_point_set2); +end diff --git a/src/lib/dic_preparation.m b/src/lib/dic_preparation.m new file mode 100644 index 0000000..a6e3d9c --- /dev/null +++ b/src/lib/dic_preparation.m @@ -0,0 +1,218 @@ +function [prep_params] = dic_preparation(varargin) +%% Parse input arguments +p = inputParser; +p.addParameter('baseDataPath',[]); +p.addParameter('baseResultPath',[]); +p.addParameter('subject',[]); +p.addParameter('material',[]); +p.addParameter('trial',[]); +p.addParameter('stereopair',[]); +p.addParameter('phase',[]); +p.addParameter('jump',[]); +p.addParameter('idxstart_set',[]); +p.addParameter('idxend_set',[]); +p.addParameter('showvisu',0); +p.addParameter('savedata',1); +p.addParameter('reftrial_setmanual',[]); +p.addParameter('param_filt_im',[25 300]); +p.addParameter('automatic_process', true); + +p.parse(varargin{:}); +base_parameters = struct(... + 'baseDataPath', p.Results.baseDataPath,... + 'baseResultPath', p.Results.baseResultPath,... + 'subject', p.Results.subject,... + 'material', p.Results.material,... + 'trial', p.Results.trial,... + 'stereopair', p.Results.stereopair,... + 'phase', p.Results.phase,... + 'jump', p.Results.jump,... + 'idxstart_set', p.Results.idxstart_set,... + 'idxend_set', p.Results.idxend_set,... + 'automatic_process', p.Results.automatic_process); + +%% Load DIC parameters +run('../dic_param.m'); + +%% Get subject-specific grayscale limit +subject_number = str2double(cell2mat(regexp(base_parameters.subject, '\d+', 'match'))); +if subject_number < DIC.LIMIT_GRAYSCALE.threshold + LIMIT_GRAYSCALE = DIC.LIMIT_GRAYSCALE.early_subjects; +else + LIMIT_GRAYSCALE = DIC.LIMIT_GRAYSCALE.default; +end + +% Get DIC parameters +TRUE_FPS = DIC.TRUE_FPS; +im_filter_mode = DIC.filtering.enabled; + +% Get Ncorr parameters +analysis_direction = DIC.ncorr.analysis_direction; +subset_radius_ncorr_tracking = DIC.ncorr.subset_radius.tracking; +subset_radius_ncorr_matching = DIC.ncorr.subset_radius.matching; +subset_spacing = DIC.ncorr.subset_spacing; +cutoff_tracking = DIC.ncorr.cutoff.tracking; +cutoff_matching = DIC.ncorr.cutoff.matching; +number_iteration_solver = DIC.ncorr.solver.max_iterations; +number_threads = DIC.ncorr.solver.num_threads; +high_strain_analysis = DIC.ncorr.strain_analysis.enabled; +seed_propagation = DIC.ncorr.strain_analysis.propagation; +auto_ref_change = DIC.ncorr.strain_analysis.auto_ref_change; +step_ref_change = DIC.ncorr.strain_analysis.step_ref_change; + +%% Setup paths and load protocol +outputPath = fullfile(base_parameters.baseResultPath, base_parameters.subject, ... + base_parameters.material, base_parameters.trial, base_parameters.phase); +if ~exist(outputPath, 'dir') + mkdir(outputPath); +end + +% load protocol +protocolPath = fullfile(fullfile(base_parameters.baseDataPath, "rawdata", ... + base_parameters.subject, "speckles", base_parameters.material, "protocol", sprintf('*.mat'))); +S = dir(protocolPath); +if isempty(S) + error('Error: Protocol not found.'); +end +p = load(fullfile(S.folder, S.name)); +protocol = p.cond; + +dircond = protocol.table(:,strcmp(protocol.titles,'dir')); +nfcond = cell2mat(protocol.table(:,strcmp(protocol.titles,'nf'))); +spdcond = cell2mat(protocol.table(:,strcmp(protocol.titles,'spd'))); +repcond = cell2mat(protocol.table(:,strcmp(protocol.titles,'rep'))); + +% reference trial determination +if (strcmp(base_parameters.phase,"loading") || nfcond(str2double(base_parameters.trial)) == 1) + reftrial = sprintf("%03d",find(nfcond == 1 & strcmp(dircond,"Ubnf"),1)); +elseif strcmp(base_parameters.phase,"slide1") && nfcond(str2double(base_parameters.trial)) == 5 + reftrial = sprintf("%03d",find(nfcond == 5 & strcmp(dircond,"Ubnf"),1)); +else + error('Error: no ref trial assigned'); +end + +if ~isempty(p.Results.reftrial_setmanual) + reftrial = p.Results.reftrial_setmanual; +end + +%% Read and process images +tic; +[cam_first_raw, cam_second_raw, cam_1, cam_2] = import_vid(base_parameters.baseDataPath,... + 'subject', base_parameters.subject,... + 'material', base_parameters.material,... + 'trial', base_parameters.trial,... + 'stereopair', base_parameters.stereopair,... + 'phase', base_parameters.phase,... + 'idxstart_set', base_parameters.idxstart_set,... + 'idxend_set', base_parameters.idxend_set,... + 'framejump', base_parameters.jump); +elapsedTime = toc; +fprintf("reading done in %1.1fs\n", elapsedTime); + +% Process phase-specific data +if strcmp(base_parameters.phase, "slide1") + cam_first_raw = cam_first_raw(:,:,1:end/2+5); + cam_second_raw = cam_second_raw(:,:,1:end/2+5); +end + +% Image saturation +cam_first_satur = satur(cam_first_raw, 'level', LIMIT_GRAYSCALE); +cam_second_satur = satur(cam_second_raw, 'level', LIMIT_GRAYSCALE); + +% Image filtering +if im_filter_mode + [cam_first, gsboundaries] = filter_like_ben(cam_first_satur, 'paramfilt', p.Results.param_filt_im); + cam_second = filter_like_ben(cam_second_satur, 'gsbound', gsboundaries, 'paramfilt', p.Results.param_filt_im); + fprintf('--> STEP: filtering done\n'); +else + cam_first = cam_first_raw; + cam_second = cam_second_raw; + fprintf('--> STEP: raw data used\n'); +end + +%% Create parameter structures for DIC analysis +step1_parameters = struct(... + 'type', analysis_direction,... + 'radius', subset_radius_ncorr_tracking,... + 'spacing', subset_spacing,... + 'cutoff_diffnorm', cutoff_tracking,... + 'cutoff_iteration', number_iteration_solver,... + 'total_threads', number_threads,... + 'stepanalysis_params', struct(... + 'enabled', high_strain_analysis,... + 'type', seed_propagation,... + 'auto', auto_ref_change,... + 'step', step_ref_change)); + +step1_2_parameters = struct(... + 'type', analysis_direction,... + 'radius', subset_radius_ncorr_matching,... + 'spacing', subset_spacing,... + 'cutoff_diffnorm', cutoff_matching,... + 'cutoff_iteration', number_iteration_solver,... + 'total_threads', number_threads,... + 'stepanalysis_params', struct(... + 'enabled', high_strain_analysis,... + 'type', seed_propagation,... + 'auto', auto_ref_change,... + 'step', step_ref_change)); + +%% Save frame information +idxframe = base_parameters.idxstart_set:base_parameters.jump:base_parameters.idxend_set; +actual_fps_meas = TRUE_FPS/base_parameters.jump; + +savefileName = fullfile(outputPath, sprintf('dic_info_data_target_pair%d.mat', base_parameters.stereopair)); +save(savefileName, 'actual_fps_meas', 'idxframe'); + +%% Prepare tracking configurations +tracking_configs = { + struct(... + 'cam_number', cam_1,... + 'ref_data', cam_first(:,:,1),... + 'cur_data', cam_first(:,:,1:end),... + 'step_number', 1 + ), + struct(... + 'cam_number', cam_2,... + 'ref_data', cam_second(:,:,1),... + 'cur_data', cam_second(:,:,2:end),... + 'step_number', 2 + ) +}; + +%% Prepare output structure +prep_params = struct(... + 'base_parameters', base_parameters,... + 'step1_parameters', step1_parameters,... + 'step1_2_parameters', step1_2_parameters,... + 'outputPath', outputPath,... + 'reftrial', reftrial,... + 'cam_data', struct(... + 'first_raw', cam_first_raw,... + 'second_raw', cam_second_raw,... + 'first', cam_first,... + 'second', cam_second,... + 'first_satur', cam_first_satur,... + 'second_satur', cam_second_satur,... + 'cam_1', cam_1,... + 'cam_2', cam_2),... + 'tracking_configs', tracking_configs,... + 'LIMIT_GRAYSCALE', LIMIT_GRAYSCALE,... + 'actual_fps_meas', actual_fps_meas,... + 'idxframe', idxframe); + +% Print summary +fprintf("Trial information summary '%s' %s %s %s\n > Dir: %s\n > Force: %dN\n > Spd: %dmm/s\n > Rep: %d\n > REFtrial: '%s'\n > NbrFr: %d\n > Frame : %s\n > Actual FPS : %d\n",... + base_parameters.trial,... + base_parameters.phase,... + base_parameters.material,... + base_parameters.subject,... + dircond{str2double(base_parameters.trial)},... + nfcond(str2double(base_parameters.trial)),... + spdcond(str2double(base_parameters.trial)),... + repcond(str2double(base_parameters.trial)),... + reftrial,... + size(cam_first,3),... + mat2str(idxframe),... + actual_fps_meas); +end diff --git a/src/lib/perform_tracking.m b/src/lib/perform_tracking.m new file mode 100644 index 0000000..f8412ad --- /dev/null +++ b/src/lib/perform_tracking.m @@ -0,0 +1,41 @@ +function perform_tracking(config, base_parameters, step_parameters) +% PERFORM_TRACKING Helper function to perform tracking for a single camera +% This function executes the tracking analysis for a single camera using the +% provided configuration and parameters. +% +% Parameters: +% config: Structure containing tracking configuration for one camera +% - cam_number: Camera number identifier +% - ref_data: Reference image data +% - cur_data: Current image data for tracking +% - mask: Mask for the region of interest +% - initial_seed: Initial seed point for tracking +% - step_number: Step number identifier +% base_parameters: Structure containing base parameters +% step_parameters: Structure containing step-specific parameters + +tic; + +% Set initial seed for this tracking step +step_parameters.initial_seed = config{1}.initial_seed; + +% Perform tracking analysis +[h, file_logic] = ncorr_dic_rewrited(... + 'cam_number', config{1}.cam_number,... + 'cam_data_ref', config{1}.ref_data,... + 'cam_data_cur', config{1}.cur_data,... + 'mask', config{1}.mask,... + 'automatic_process', base_parameters.automatic_process,... + 'step_param', step_parameters,... + 'base_param', base_parameters); + +% Clean up +if ~file_logic + close(h.handles_gui.figure); +end +clear('h'); + +% Report timing +elapsedTime = toc; +fprintf('--> STEP: Ncorr %d done in %1.1fs\n', config{1}.step_number, elapsedTime); +end diff --git a/src/lib/stepD_2DDIC.m b/src/lib/stepD_2DDIC.m index a969a3c..236ff2f 100644 --- a/src/lib/stepD_2DDIC.m +++ b/src/lib/stepD_2DDIC.m @@ -1,579 +1,68 @@ function varargout = stepD_2DDIC(varargin) -%% Parse input arguments -p = inputParser; -p.addParameter('baseDataPath',[]); -p.addParameter('baseResultPath',[]); -p.addParameter('subject',[]); -p.addParameter('material',[]); -p.addParameter('trial',[]); -p.addParameter('stereopair',[]); -p.addParameter('phase',[]); -p.addParameter('jump',[]); -p.addParameter('idxstart_set',[]); -p.addParameter('idxend_set',[]); -p.addParameter('showvisu',0); -p.addParameter('savedata',1); -p.addParameter('reftrial_setmanual',[]); -p.addParameter('param_filt_im',[25 300]); -p.addParameter('automatic_process', true); - -p.parse(varargin{:}); -baseDataPath = p.Results.baseDataPath; -baseResultPath = p.Results.baseResultPath; -subject = p.Results.subject; -material = p.Results.material; -trial = p.Results.trial; -stereopair = p.Results.stereopair; -phase = p.Results.phase; -idxstart_set = p.Results.idxstart_set; -idxend_set = p.Results.idxend_set; -jump = p.Results.jump; -showvisu = p.Results.showvisu; -savedata = p.Results.savedata; -reftrial_setmanual = p.Results.reftrial_setmanual; -param_filt_im = p.Results.param_filt_im; -automatic_process = p.Results.automatic_process; - -%% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -% % TEST PARAMETERS : TO BE COMMENTED !!!! -% baseDataPath = pwd; -% subject = 'S02'; -% material = 'glass'; -% trial = '003'; -% stereopair = 1; -% phase = 'slide1'; -% jump = 5; -% showvisu = 1; -% savedata = 1; -% idxstart_set=[]; -% idxend_set=[]; -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - -fprintf("-------------------------------------------\n"); -fprintf("-------------------------------------------\n"); -fprintf("Digital Image Correlation analysis launch\n"); - -%Global constant -TRUE_FPS = 50; -if str2double(cell2mat(regexp(subject, '\d+', 'match')))<8 - LIMIT_GRAYSCALE = 70;%70; -else - LIMIT_GRAYSCALE = 100; -end - -% Filtering parameters -im_filter_mode = true; - -% Ncorr DIC parameters -analysis_direction = 'regular'; -subset_radius_ncorr_tracking = 40; %40%careful :35 -subset_radius_ncorr_matching = 60; %50%S02 : 60 -subset_spacing = 10;%10 %20 -cutoff_tracking = 1e-5; -cutoff_matching = 1e-5; -number_iteration_solver = 100; -number_threads = 1; -high_strain_analysis = 1; -seed_propagation = 'seed'; -auto_ref_change = 1; -step_ref_change = 10; - -% ensure output path exists -outputPath = fullfile(baseResultPath,subject,material,trial,phase); %,sprintf('filt_%d_%d',param_filt_im(1),param_filt_im(2))); -if ~exist(outputPath,'dir') - mkdir(outputPath); -end - -% load protocol -protocolPath = fullfile(fullfile(baseDataPath,"rawdata",subject,"speckles",... - material,"protocol",sprintf('*.mat'))); -S = dir(protocolPath); -if isempty(S) - error('Error: Protocol not found.'); -end -p = load(fullfile(S.folder,S.name)); protocol = p.cond; - -dircond = protocol.table(:,strcmp(protocol.titles,'dir')); -nfcond = cell2mat(protocol.table(:,strcmp(protocol.titles,'nf'))); -spdcond = cell2mat(protocol.table(:,strcmp(protocol.titles,'spd'))); -repcond = cell2mat(protocol.table(:,strcmp(protocol.titles,'rep'))); -spddxlcond = repelem([0.08],length(repcond)); - - -% reference trial for ROI tracing -if (strcmp(phase,"loading") || nfcond(str2double(trial)) == 1) - %REF for all when phase loading - %REF for 1N when in slide1 phase - reftrial = sprintf("%03d",find(nfcond == 1&... - strcmp(dircond,"Ubnf"),1)); -elseif strcmp(phase,"slide1") && nfcond(str2double(trial)) == 5 - %REF for 5N when in slide1 phase - reftrial = sprintf("%03d",find(nfcond == 5 &... - strcmp(dircond,"Ubnf"),1)); -else - fprintf("error : no ref trial assigned\n"); - return; -end - -%manual set -if ~isempty(reftrial_setmanual) - reftrial = reftrial_setmanual; -end - -%pair order for 3D reconstruction -if strcmp(dircond(str2double(trial)),"Ubnf") - pairOrder = [2,1]; - pairForced = true; -elseif strcmp(dircond(str2double(trial)),"Rbnf") - pairOrder = [1,2]; - pairForced = true; -else - pairOrder = [1,2]; - pairForced = false; -end - -%% parameter structure -%filename -roifile = fullfile(baseResultPath,subject,material,... - "REF_MASK_"+reftrial+"_"+phase+"_pair"+num2str(stereopair)+".mat"); -matchingfile = fullfile(outputPath,... - "MATCHING2"+reftrial+"_pair"+num2str(stereopair)+".mat"); -seedfile = fullfile(baseResultPath,subject,material,... - "REF_SEED_"+reftrial+"_"+phase+"_pair"+num2str(stereopair)+".mat"); - -base_parameters = struct(... - 'baseDataPath',baseDataPath,... - 'baseResultPath',baseResultPath,... - 'subject',subject,... - 'material',material,... - 'trial',trial,... - 'stereopair',stereopair,... - 'phase',phase,... - 'jump',jump,... - 'outputPath',outputPath,... - 'reftrial',reftrial,... - 'roifile',roifile,... - 'matchingfile',matchingfile,... - 'seedfile',seedfile,... - 'idxstart_set',idxstart_set,... - 'idxend_set',idxend_set,... - 'limit_grayscale',LIMIT_GRAYSCALE); - -step1_parameters = struct( ... - 'type',analysis_direction,... - 'radius',subset_radius_ncorr_tracking,... - 'spacing',subset_spacing, ... - 'cutoff_diffnorm',cutoff_tracking, ... - 'cutoff_iteration',number_iteration_solver, ... - 'total_threads',number_threads, ... - 'stepanalysis_params', struct( ... - 'enabled',high_strain_analysis, ... - 'type',seed_propagation, ... - 'auto',auto_ref_change, ... - 'step',step_ref_change) ... - ); -step1_2_parameters = struct( ... - 'type',analysis_direction,... - 'radius',subset_radius_ncorr_matching,... - 'spacing',subset_spacing, ... - 'cutoff_diffnorm',cutoff_matching, ... - 'cutoff_iteration',number_iteration_solver, ... - 'total_threads',number_threads, ... - 'stepanalysis_params', struct( ... - 'enabled',high_strain_analysis, ... - 'type',seed_propagation, ... - 'auto',auto_ref_change, ... - 'step',step_ref_change) ... - ); - -step2_parameters = step1_parameters; -fprintf('global parameters set\n'); - - -%% Read data -% read images from video file and retreive camera number according to -% stereopair given. -tic; -[cam_first_raw, cam_second_raw, cam_1, cam_2] = import_vid(baseDataPath,... - 'subject',subject,... - 'material',material,... - 'trial',trial,... - 'stereopair',stereopair,... - 'phase',phase,... - 'idxstart_set',idxstart_set,... - 'idxend_set',idxend_set,... - 'framejump',jump); -elapsedTime = toc; -fprintf("reading done in %1.1fs\n",elapsedTime); - -%% filtering images : use all images -%limit_grayscale_level = 75; -if strcmp(phase,"slide1") - cam_first_raw = cam_first_raw(:,:,1:end/2+5); - cam_second_raw = cam_second_raw(:,:,1:end/2+5); -end - -%saturation of images -cam_first_satur = satur(cam_first_raw,'level',LIMIT_GRAYSCALE); -cam_second_satur = satur(cam_second_raw,'level',LIMIT_GRAYSCALE); - - -%% Initialization of ROI - SEED - MATCHING PAIR -% Load ROI -if ~exist(roifile,'file') - draw_ref_roi(base_parameters); -end - -% Matching is done between a reference trial to the current one to skip -% making the roi for each cameras at each trial. It is done over the -% saturated images -% verify that the matching exist and if not, ncorr is run to acquire -% displacement field data from -if ~exist(matchingfile,'file') - ncorr_matching2ref(cam_first_satur(:,:,1),base_parameters,step1_2_parameters); -end - -% compute reformatted roi -matching = load(matchingfile); -refmask_REF = matching.reference_save(1).roi.mask; -refmask_trial = matching.current_save(1).roi.mask; -disp('--> STEP : ROI loaded and formatted'); - -% SEED placement -if ~exist(seedfile,'file') - %manual seed placement in the reference trial - draw_ref_seed(base_parameters,'roi',refmask_REF); -end - -%load seed position -seed_point = load(seedfile); - -%mapping coordinate -ref_seed_point.pw = seed_point.seed_point; %pixel world -ref_seed_point.sw = map_pixel2subset(ref_seed_point.pw,subset_spacing); %subset world - -% mapping : format seed point for ncorr1 and ncorr12 -U_mapped = matching.data_dic_save.displacements(1).plot_u_ref_formatted/(subset_spacing+1); -V_mapped = matching.data_dic_save.displacements(1).plot_v_ref_formatted/(subset_spacing+1); - -initial_seed_point_set1.sw = map_pointcoordinate(ref_seed_point.sw,{U_mapped,V_mapped}); -initial_seed_point_set1.pw = map_subset2pixel(initial_seed_point_set1.sw,subset_spacing); - -disp('--> STEP : SEED loaded and formatted'); -%% -if im_filter_mode == true - % We reuse the mask that has been processed to keep bounds of gs - % intensity over the roi of the first cam at initial step. - [cam_first,gsboundaries] = filter_like_ben(cam_first_satur,'mask',refmask_trial,'paramfilt',param_filt_im); - % Keep the same bounds (should be a good approximation) - cam_second = filter_like_ben(cam_second_satur,'gsbound',gsboundaries,'paramfilt',param_filt_im); - disp('--> STEP : filtering done'); -else - cam_first = cam_first_raw; - cam_second = cam_second_raw; - disp('--> STEP : raw data used'); - -end -%% trial info -idxframe = idxstart_set:jump:idxend_set; -actual_fps_meas = TRUE_FPS/jump; -fprintf("Trial information summary \'%s\' %s %s %s\n > Dir: %s\n > Force: %dN\n > Spd: %dmm/s\n > Rep: %d\n > REFtrial: \'%s\'\n > NbrFr: %d\n > Frame : %s\n > Actual FPS : %d\n",... - trial,... - phase,... - material,... - subject,... - dircond{str2double(trial)},... - nfcond(str2double(trial)),... - spdcond(str2double(trial)),... - repcond(str2double(trial)),... - reftrial,... - size(cam_first,3),... - mat2str(idxstart_set:jump:idxend_set),... - actual_fps_meas); - -savefileName = fullfile(outputPath,sprintf('dic_info_data_target_pair%d.mat',stereopair)); -save(savefileName,'actual_fps_meas','idxframe'); -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%% Run ncorr analysis -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%% -%% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -% MATCHING STEP - RUN #1 -tic; -step1_2_parameters.initial_seed = initial_seed_point_set1.pw; -% We keep the ROI of the ncorr matching step - +% STEPD_2DDIC Main function for Digital Image Correlation analysis +% This function orchestrates the DIC analysis pipeline by: +% 1. Preparing data and parameters (using dic_preparation) +% 2. Performing matching between image pairs (using dic_matching) +% 3. Executing tracking analysis for both cameras % -siz = size(cam_first); -input1 = cam_first_satur(:,:,1); -input2 = zeros(siz(1),siz(2),2,'uint8'); -input2(:,:,1) = cam_second_satur(:,:,1); -input2(:,:,2) = cam_first_satur(:,:,1); %needed to avoid a bug in ncorr -[h12,file_logic] = ncorr_dic_rewrited('cam_number',[cam_1,cam_2],... - 'cam_data_ref',input1,... - 'cam_data_cur',input2,... - 'mask',refmask_trial,... - 'automatic_process',automatic_process,... - 'step_param',step1_2_parameters,... - 'base_param',base_parameters); - -% Retreive info for next step -refmask_trial_matched = h12.current(1).roi.mask; -% mapping : format seed point for ncorr2 -U_mapped = h12.data_dic.displacements(1).plot_u_ref_formatted/(subset_spacing+1); -V_mapped = h12.data_dic.displacements(1).plot_v_ref_formatted/(subset_spacing+1); - -initial_seed_point_set2.sw = map_pointcoordinate(initial_seed_point_set1.sw,{U_mapped,V_mapped}); -initial_seed_point_set2.pw = map_subset2pixel(initial_seed_point_set2.sw,subset_spacing); - -if ~file_logic - close(h12.handles_gui.figure); -end -clear('h12'); -elapsedTime = toc; -fprintf("--> STEP : Ncorr matching 1-2 done in %1.1fs\n",elapsedTime); - - -%% Visualisation -if showvisu - siz = size(cam_first); - cam_first_1 = cam_first(:,:,1); - cam_second_1 = cam_second(:,:,1); - cam_first_1(~refmask_trial) = 0.25*cam_first_1(~refmask_trial); - cam_second_1(~refmask_trial_matched) = 0.25*cam_second_1(~refmask_trial_matched); - h1 = player([repmat([reshape(cam_first_1,[siz(1),siz(2)]),reshape(cam_second_1,[siz(1),siz(2)])],1,1,siz(3));... - cam_first,cam_second],'fps',TRUE_FPS/jump,'movie',0); hold on; - drawpoint('Position',[initial_seed_point_set1.pw(1),initial_seed_point_set1.pw(2)]); hold on; - drawpoint('Position',[initial_seed_point_set2.pw(1)+siz(2),initial_seed_point_set2.pw(2)]); - - pause(30); - - % if not already closed, close player - isDeletedObj = isobject(h1) & ~isgraphics(h1); - if ~isDeletedObj - close(h1); - end -end -%% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -% TRACKING STEP 1 - -tic; -step1_parameters.initial_seed = initial_seed_point_set1.pw; -% We keep the ROI of the ncorr matching step -[h1,file_logic] = ncorr_dic_rewrited('cam_number',cam_1,... - 'cam_data_ref',cam_first(:,:,1),... - 'cam_data_cur',cam_first(:,:,1:end),... - 'mask',refmask_trial,... - 'automatic_process',automatic_process,... - 'step_param',step1_parameters,... - 'base_param',base_parameters); - -if ~file_logic - close(h1.handles_gui.figure); -end -clear('h1'); -elapsedTime = toc; -fprintf("--> STEP : Ncorr 1 done in %1.1fs\n",elapsedTime); +% Parameters: +% varargin: Variable input arguments including: +% - baseDataPath: Base path for data files +% - baseResultPath: Base path for results +% - subject: Subject identifier +% - material: Material type +% - trial: Trial number +% - stereopair: Stereo pair number +% - phase: Analysis phase +% - jump: Frame jump size +% - idxstart_set: Start index +% - idxend_set: End index +% - showvisu: Visualization flag +% - savedata: Save data flag +% - reftrial_setmanual: Manual reference trial +% - param_filt_im: Image filtering parameters +% - automatic_process: Automatic processing flag +% +% Returns: +% varargout: Optional output structure containing: +% - prep_params: Parameters and data from preparation step +% - matching_results: Results from the matching analysis +% +% See also: +% dic_preparation, dic_matching, perform_tracking -%% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -% TRACKING STEP 2 +% Print analysis start message +fprintf('-------------------------------------------\n'); +fprintf('-------------------------------------------\n'); +fprintf('Digital Image Correlation analysis launch\n'); -tic; -step2_parameters.initial_seed = initial_seed_point_set2.pw; -% We keep the ROI of the ncorr matching step -[h2,file_logic] = ncorr_dic_rewrited('cam_number',cam_2,... - 'cam_data_ref',cam_second(:,:,1),... - 'cam_data_cur',cam_second(:,:,2:end),... - 'mask',refmask_trial_matched,... - 'automatic_process',automatic_process,... - 'step_param',step2_parameters,... - 'base_param',base_parameters); +% Prepare data and parameters +prep_params = dic_preparation(varargin{:}); -if ~file_logic - close(h2.handles_gui.figure); -end -clear('h2'); -elapsedTime = toc; -fprintf("--> STEP : Ncorr 2 done in %1.1fs\n",elapsedTime); +% Perform matching analysis +matching_results = dic_matching(prep_params); -%% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -% Format output +% Execute tracking analysis for both cameras +configs = prep_params.tracking_configs; +configs{1}.mask = matching_results.refmask_trial; +configs{1}.initial_seed = matching_results.initial_seed_point_set1.pw; +configs{2}.mask = matching_results.refmask_trial_matched; +configs{2}.initial_seed = matching_results.initial_seed_point_set2.pw; -step2_dic_finish(outputPath,... - 'cam_1',cam_1,... - 'cam_2',cam_2); -if savedata == 0 - delete(fullfile(outputPath,'ncorr1.mat')); - delete(fullfile(outputPath,'ncorr12.mat')); - delete(fullfile(outputPath,'ncorr2.mat')); +for config = configs + perform_tracking(config, prep_params.base_parameters, prep_params.step1_parameters); end -disp('--> STEP : Ncorr analysis completed'); - -if nargout >= 1 - varargout{1} = outputPath; +% Return any output arguments if needed +if nargout > 0 + varargout{1} = struct(... + 'prep_params', prep_params,... + 'matching_results', matching_results); end -if nargout >= 2 - varargout{2} = pairOrder; -end -if nargout >= 3 - varargout{3} = pairForced; -end - -%% Visu -% if showvisu == 1 -% bool_point = true; -% factor = 4; -% while bool_point -% siz = size(cam_first_satur); -% fig = figure; imshow([cam_first_satur(:,:,1),cam_second_satur(:,:,1)],[]); -% [X,Y] = ginput(2); -% close(fig); -% c1 = round([X(1),Y(1)]); c2 = round([X(2)-siz(2),Y(2)]); -% R = subset_radius_ncorr_tracking; -% -% [x1,y1] = circle_coordinates(c1,R); -% [xy1] = findboundary([x1,y1],'connex_factor',1); -% x1 = xy1(:,1); y1 = xy1(:,2); -% mask1 = poly2mask(x1,y1,siz(1),siz(2)); -% maxxy=max(xy1); minxy=min(xy1); -% mask1_small = mask1(minxy(2):maxxy(2),minxy(1):maxxy(1)); -% -% [x2,y2] = circle_coordinates(c2,R); -% [xy2] = findboundary([x2,y2],'connex_factor',1); -% x2 = xy2(:,1); y2 = xy2(:,2); -% mask2 = poly2mask(x2,y2,siz(1),siz(2)); -% maxxy=max(xy2); minxy=min(xy2); -% mask2_small = mask2(minxy(2):maxxy(2),minxy(1):maxxy(1)); -% -% im_first_raw = cam_first_raw(:,:,1); -% im_second_raw = cam_second_raw(:,:,1); -% im_first = cam_first_satur(:,:,1); -% im_second = cam_second_satur(:,:,1); -% -% %highlight circle -% im_first_raw(~mask1) = im_first_raw(~mask1)/factor; -% im_second_raw(~mask2) = im_second_raw(~mask2)/factor; -% im_first(~mask1) = im_first(~mask1)/factor; -% im_second(~mask2) = im_second(~mask2)/factor; -% -% %zoom -% z = zeros(round(maxxy(2)-minxy(2))+1,round(maxxy(1)-minxy(1))+1); -% im_first_raw_zoom = z; im_second_raw_zoom = z; -% im_first_zoom = z; im_second_zoom = z; -% -% im_first_raw_zoom(mask1_small) = im_first_raw(mask1); -% im_first_raw_zoom = imresize(im_first_raw_zoom,[siz(1),siz(1)]); -% -% im_second_raw_zoom(mask2_small) = im_second_raw(mask2); -% im_second_raw_zoom = imresize(im_second_raw_zoom,[siz(1),siz(1)]); -% -% im_first_zoom(mask1_small) = im_first(mask1); -% im_first_zoom = imresize(im_first_zoom,[siz(1),siz(1)]); -% -% im_second_zoom(mask2_small) = im_second(mask2); -% im_second_zoom = imresize(im_second_zoom,[siz(1),siz(1)]); -% -% fig = figure; -% imshow([im_first_raw, im_first_raw_zoom,... -% im_second_raw,im_second_raw_zoom;... -% im_first, im_first_zoom,... -% im_second, im_second_zoom]); -% -% answer = questdlg('Correct points ?', ... -% 'Zoom point', ... -% 'Yes','No','Yes'); -% % Handle response -% switch answer -% case 'Yes' -% bool_point = false; -% case 'No' -% bool_point = true; -% end -% close(fig); -% end -% -% im_c = zeros(siz(1)*2,siz(2)*2+siz(1)*2,siz(3)); -% z = zeros(round(maxxy(2)-minxy(2))+1,round(maxxy(1)-minxy(1))+1); -% for ii = 1:siz(3) -% im_first_raw = cam_first_raw(:,:,ii); -% im_second_raw = cam_second_raw(:,:,ii); -% im_first = cam_first_satur(:,:,ii); -% im_second = cam_second_satur(:,:,ii); -% -% %highlight circle -% im_first_raw(~mask1) = im_first_raw(~mask1)/factor; -% im_second_raw(~mask2) = im_second_raw(~mask2)/factor; -% im_first(~mask1) = im_first(~mask1)/factor; -% im_second(~mask2) = im_second(~mask2)/factor; -% -% %zoom -% im_first_raw_zoom = z; im_second_raw_zoom = z; -% im_first_zoom = z; im_second_zoom = z; -% -% im_first_raw_zoom(mask1_small) = im_first_raw(mask1); -% im_first_raw_zoom = imresize(im_first_raw_zoom,[siz(1),siz(1)]); -% -% im_second_raw_zoom(mask2_small) = im_second_raw(mask2); -% im_second_raw_zoom = imresize(im_second_raw_zoom,[siz(1),siz(1)]); -% -% im_first_zoom(mask1_small) = im_first(mask1); -% im_first_zoom = imresize(im_first_zoom,[siz(1),siz(1)]); -% -% im_second_zoom(mask2_small) = im_second(mask2); -% im_second_zoom = imresize(im_second_zoom,[siz(1),siz(1)]); -% -% im_c(:,:,ii) = [im_first_raw,im_first_raw_zoom,... -% im_second_raw,im_second_raw_zoom;... -% im_first,im_first_zoom,... -% im_second,im_second_zoom]; -% end -% -% end -% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -% % MATCHING STEP - RUN #2 : -% % From second camera to first camera -% tic; -% step1_2_parameters.initial_seed = initial_seed_point_set2.pw; -% % We keep the ROI of the ncorr matching step -% -% -% -% % -% siz = size(cam_second_satur); -% input1 = cam_first_satur(:,:,1); -% input2 = zeros(siz(1),siz(2),2,'uint8'); -% input2(:,:,1) = cam_second_satur(:,:,1); -% input2(:,:,2) = cam_first_satur(:,:,1); %needed to avoid a bug in ncorr -% h12 = ncorr_dic_rewrited('cam_number',[cam_1,cam_2],... -% 'cam_data_ref',input1,... -% 'cam_data_cur',input2,... -% 'mask',refmask_trial,... -% 'automatic_process',automatic_process,... -% 'step_param',step1_2_parameters,... -% 'base_param',base_parameters); -% -% % Retreive info for next step -% ref2_roi = h12.current(1).roi; -% -% % mapping : format seed point for ncorr2 -% U_mapped = h12.data_dic.displacements(1).plot_u_ref_formatted/(subset_spacing+1); -% V_mapped = h12.data_dic.displacements(1).plot_v_ref_formatted/(subset_spacing+1); -% -% initial_seed_point_set2.sw = map_pointcoordinate(initial_seed_point_set1.sw,{U_mapped,V_mapped}); -% initial_seed_point_set2.pw = map_subset2pixel(initial_seed_point_set2.sw,subset_spacing); -% -% if isfield(h12,'handles_gui') -% close(h12.handles_gui.figure); -% end -% clear('h12'); -% -% elapsedTime = toc; -% fprintf("--> STEP : Ncorr 1_2 done in %1.1fs\n",elapsedTime); \ No newline at end of file +% Print completion message +fprintf('-------------------------------------------\n'); +fprintf('Digital Image Correlation analysis complete\n'); +fprintf('-------------------------------------------\n'); +end \ No newline at end of file From 361b47cc261425000eb42c6fd15343812f8e0796 Mon Sep 17 00:00:00 2001 From: John Aoga Date: Sat, 5 Apr 2025 18:16:24 +0200 Subject: [PATCH 2/2] debuging --- src/dic_param.m | 14 +++++----- src/lib/dic_matching.m | 13 +++------ src/lib/dic_preparation.m | 41 ++++++++++++++++++++++------- src/lib_script/ncorr_matching2ref.m | 14 ++++++---- 4 files changed, 51 insertions(+), 31 deletions(-) diff --git a/src/dic_param.m b/src/dic_param.m index 86fc953..97b1868 100644 --- a/src/dic_param.m +++ b/src/dic_param.m @@ -25,33 +25,33 @@ DIC.LIMIT_GRAYSCALE = struct(... 'default', 100,... 'early_subjects', 70,... - 'threshold', 8 % Subject numbers below this use early_subjects value + 'threshold', 8 ... % Subject numbers below this use early_subjects value ); %% DIC Analysis Parameters DIC.filtering = struct(... - 'enabled', true + 'enabled', true... ); DIC.ncorr = struct(... 'analysis_direction', 'regular',... 'subset_radius', struct(... 'tracking', 40,... - 'matching', 60 + 'matching', 60 ... ),... 'subset_spacing', 10,... 'cutoff', struct(... 'tracking', 1e-5,... - 'matching', 1e-5 + 'matching', 1e-5 ... ),... 'solver', struct(... 'max_iterations', 100,... - 'num_threads', 1 + 'num_threads', 1 ... ),... 'strain_analysis', struct(... 'enabled', 1,... 'propagation', 'seed',... 'auto_ref_change', 1,... - 'step_ref_change', 10 - ) + 'step_ref_change', 10 ... + ) ... ); diff --git a/src/lib/dic_matching.m b/src/lib/dic_matching.m index 39a58c9..2d2213f 100644 --- a/src/lib/dic_matching.m +++ b/src/lib/dic_matching.m @@ -5,16 +5,11 @@ cam_data = prep_params.cam_data; % Define file paths -roifile = fullfile(base_parameters.baseResultPath, base_parameters.subject, ... - base_parameters.material, sprintf("REF_MASK_%s_%s_pair%d.mat", ... - prep_params.reftrial, base_parameters.phase, base_parameters.stereopair)); +roifile = prep_params.roifile; -matchingfile = fullfile(prep_params.outputPath, ... - sprintf("MATCHING2%s_pair%d.mat", prep_params.reftrial, base_parameters.stereopair)); +matchingfile = prep_params.matchingfile; -seedfile = fullfile(base_parameters.baseResultPath, base_parameters.subject, ... - base_parameters.material, sprintf("REF_SEED_%s_%s_pair%d.mat", ... - prep_params.reftrial, base_parameters.phase, base_parameters.stereopair)); +seedfile = prep_params.seedfile; %% ROI and Seed initialization % Draw ROI if needed @@ -24,7 +19,7 @@ % Perform matching if needed if ~exist(matchingfile, 'file') - ncorr_matching2ref(cam_data.first_satur(:,:,1), base_parameters, step1_2_parameters); + ncorr_matching2ref(cam_data.first_satur(:,:,1), prep_params, step1_2_parameters); end % Load matching results diff --git a/src/lib/dic_preparation.m b/src/lib/dic_preparation.m index a6e3d9c..3f0d32a 100644 --- a/src/lib/dic_preparation.m +++ b/src/lib/dic_preparation.m @@ -29,10 +29,16 @@ 'jump', p.Results.jump,... 'idxstart_set', p.Results.idxstart_set,... 'idxend_set', p.Results.idxend_set,... - 'automatic_process', p.Results.automatic_process); + 'automatic_process', p.Results.automatic_process, ... + 'reftrial_setmanual', p.Results.reftrial_setmanual, ... + 'param_filt_im', p.Results.param_filt_im, ... + 'savedata', p.Results.savedata, ... + 'showvisu', p.Results.showvisu ... + ); + %% Load DIC parameters -run('../dic_param.m'); +dic_param; %% Get subject-specific grayscale limit subject_number = str2double(cell2mat(regexp(base_parameters.subject, '\d+', 'match'))); @@ -91,8 +97,8 @@ error('Error: no ref trial assigned'); end -if ~isempty(p.Results.reftrial_setmanual) - reftrial = p.Results.reftrial_setmanual; +if ~isempty(base_parameters.reftrial_setmanual) + reftrial = base_parameters.reftrial_setmanual; end %% Read and process images @@ -121,8 +127,8 @@ % Image filtering if im_filter_mode - [cam_first, gsboundaries] = filter_like_ben(cam_first_satur, 'paramfilt', p.Results.param_filt_im); - cam_second = filter_like_ben(cam_second_satur, 'gsbound', gsboundaries, 'paramfilt', p.Results.param_filt_im); + [cam_first, gsboundaries] = filter_like_ben(cam_first_satur, 'paramfilt', base_parameters.param_filt_im); + cam_second = filter_like_ben(cam_second_satur, 'gsbound', gsboundaries, 'paramfilt', base_parameters.param_filt_im); fprintf('--> STEP: filtering done\n'); else cam_first = cam_first_raw; @@ -170,17 +176,28 @@ 'cam_number', cam_1,... 'ref_data', cam_first(:,:,1),... 'cur_data', cam_first(:,:,1:end),... - 'step_number', 1 - ), + 'step_number', 1 ... + ), ... struct(... 'cam_number', cam_2,... 'ref_data', cam_second(:,:,1),... 'cur_data', cam_second(:,:,2:end),... - 'step_number', 2 + 'step_number', 2 ... ) }; %% Prepare output structure +roifile = fullfile(base_parameters.baseResultPath, base_parameters.subject, ... + base_parameters.material, sprintf("REF_MASK_%s_%s_pair%s.mat", ... + reftrial, base_parameters.phase, base_parameters.stereopair+"")); + +matchingfile = fullfile(outputPath, ... + sprintf("MATCHING2%s_pair%s.mat", reftrial, base_parameters.stereopair+"")); + +seedfile = fullfile(base_parameters.baseResultPath, base_parameters.subject, ... + base_parameters.material, sprintf("REF_SEED_%s_%s_pair%s.mat", ... + reftrial, base_parameters.phase, base_parameters.stereopair+"")); + prep_params = struct(... 'base_parameters', base_parameters,... 'step1_parameters', step1_parameters,... @@ -199,7 +216,11 @@ 'tracking_configs', tracking_configs,... 'LIMIT_GRAYSCALE', LIMIT_GRAYSCALE,... 'actual_fps_meas', actual_fps_meas,... - 'idxframe', idxframe); + 'idxframe', idxframe, ... + 'roifile', roifile, ... + 'matchingfile', matchingfile, ... + 'seedfile', seedfile ... + ); % Print summary fprintf("Trial information summary '%s' %s %s %s\n > Dir: %s\n > Force: %dN\n > Spd: %dmm/s\n > Rep: %d\n > REFtrial: '%s'\n > NbrFr: %d\n > Frame : %s\n > Actual FPS : %d\n",... diff --git a/src/lib_script/ncorr_matching2ref.m b/src/lib_script/ncorr_matching2ref.m index a4e9ec2..34d9295 100644 --- a/src/lib_script/ncorr_matching2ref.m +++ b/src/lib_script/ncorr_matching2ref.m @@ -1,12 +1,13 @@ -function ncorr_matching2ref(im2match,base_parameters,ncorr_parameters) +function ncorr_matching2ref(im2match,prep_params,ncorr_parameters) disp('Ncorr matching run'); +base_parameters = prep_params.base_parameters; %% Load images [cam_first_raw,~] = import_vid(base_parameters.baseDataPath,... 'subject',base_parameters.subject,... 'material',base_parameters.material,... - 'trial',base_parameters.reftrial,... + 'trial', base_parameters.reftrial_setmanual,... 'stereopair',base_parameters.stereopair,... 'phase',base_parameters.phase,... 'idxstart_set',base_parameters.idxstart_set,... @@ -16,14 +17,17 @@ function ncorr_matching2ref(im2match,base_parameters,ncorr_parameters) cam_first = cam_first_raw; %% REFERENCE ROI -refmask = load(base_parameters.roifile); +disp(prep_params.roifile); +% Check if the path is correct +assert(isfile(prep_params.roifile), 'File not found.'); +refmask = load(prep_params.roifile); refmask = refmask.refmask; %% Run ncorr %Choose automatic or semi automatic analysis -if exist(base_parameters.seedfile,'file') - seed_point = load(base_parameters.seedfile); +if exist(prep_params.seedfile,'file') + seed_point = load(prep_params.seedfile); seed_point = seed_point.seed_point; showGui = false; else