Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 20 additions & 3 deletions src/dic_analysis.m
Original file line number Diff line number Diff line change
@@ -1,12 +1,29 @@
function dic_analysis(data_path, dic_path, subject_id, phase_id, material, num_pair, nfcond_set, spddxlcond_set, calib_folder_set, ref_trial_id, idx_frame_start, idx_frame_end, frame_jump, showvisu, debug_mode, automatic_process)
function dic_analysis(data_path, dic_path)
% DIC_ANALYSIS Main entry point for Digital Image Correlation analysis
% This function orchestrates the complete DIC analysis pipeline including
% 2D-DIC, 3D reconstruction, and deformation analysis.
%
% Parameters:
% data_path: Path to the data directory
% dic_path: Path to save DIC results
%
% All other parameters are loaded from:
% - global_param.m: Global configuration
% - dic_param.m: DIC-specific parameters
% - plot_param.m: Visualization settings

% Load parameter files
run('global_param.m');
run('dic_param.m');
run('plot_param.m');
%trial_target = search_trial2target(data_path, subject_id, phase_id, material, nfcond_set, spddxlcond_set);
trial_target = [5, 6];
fprintf('Trial target set: [%s]\n', num2str(trial_target));

% STEP D: 2D-DIC
% 2D-DIC analysis
tic;
output = dic_2d_analysis(trial_target, data_path, dic_path, subject_id, phase_id, material, num_pair, nfcond_set, spddxlcond_set, calib_folder_set, ref_trial_id, idx_frame_start, idx_frame_end, frame_jump, showvisu, debug_mode, automatic_process);
output = dic_2d_analysis(trial_target, data_path, dic_path);
elapsed_time = toc;
fprintf("Dic 2D Analysis done in %lf s\n", elapsed_time);

Expand All @@ -23,7 +40,7 @@ function dic_analysis(data_path, dic_path, subject_id, phase_id, material, num_p
% STEP E: 3D Reconstruction
% 3D reconstruction
tic;
file_reconstruction = dic_3d_reconstruction(output_2d, trial_target, data_path, dic_path, subject_id, phase_id, material, num_pair, nfcond_set, spddxlcond_set, calib_folder_set, ref_trial_id, idx_frame_start, idx_frame_end, frame_jump, showvisu, debug_mode, automatic_process);
file_reconstruction = dic_3d_reconstruction(output_2d, trial_target, data_path, dic_path);
elapsed_time = toc;
disp(file_reconstruction);
fprintf("DIC 3D Reconstruction done in %1.1fs\n", elapsed_time);
Expand Down
48 changes: 42 additions & 6 deletions src/dic_param.m
Original file line number Diff line number Diff line change
@@ -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
)
);
11 changes: 10 additions & 1 deletion src/lib/dic_2d_analysis.m
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
function output = dic_2d_analysis(trial_target, data_path, dic_path, subject_id, phase_id, material, num_pair, nfcond_set, spddxlcond_set, calib_folder_set, ref_trial_id, idx_frame_start, idx_frame_end, frame_jump, showvisu, debug_mode, automatic_process)
function output = dic_2d_analysis(trial_target, data_path, dic_path)
% DIC_2D_ANALYSIS Perform 2D Digital Image Correlation analysis
% This function performs the 2D DIC analysis for the given trials.
%
% Parameters:
% trial_target: Target trials to analyze
% data_path: Path to the data directory
% dic_path: Path to save DIC results
%
% All other parameters are loaded from parameter files
fprintf('Begin of %s\n', mfilename);
% Flatten all combinations (trial_jj, stereopair_kk)
pairs_trials = combvec( 1:num_pair, trial_target)';
Expand Down
105 changes: 105 additions & 0 deletions src/lib/dic_matching.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
function [matching_results] = dic_matching(prep_params)
% DIC_MATCHING Perform matching between image pairs
% This function handles the matching process between image pairs,
% including ROI and seed initialization.
%
% Parameters:
% prep_params: Structure containing prepared data and parameters
%
% Returns:
% matching_results: Structure containing matching analysis results

% 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
Loading