function [DTItracts] = MuscleParameters_Deterministic(muscle_path,order,apo_line) % ----------------- INPUT ----------------- % muscle_path: string of pathway directory for muscle of interest (EX: 'FCU') % order: order of polynomial fitting (EX: 2) % apo_line: vector (2x3 matrix of 3D coordinates) of aponeurosis in that muscle (EX: [3 4 5; 6 7 8]) % ----------------- OUTPUT ----------------- % DTItracts: structure with the fields: % - M: the generated number of tracts % - nan_rows: logical array for rows (samples) that were eliminated due to non-tracking or low intensity % - overall_anat_length: Mx2 vector of actual lengths of each m-th fiber (2nd col) (1st col = fiber index) % - max_intensity: Mx2 vector of actual lengths of each m-th fiber (2nd col) (1st col = fiber index) % - anat_coord: Mx1 vector of anatomical space coordinates for each m-th fiber % - tracts_xyz: 3x(n*M) array of all points of all fibers (anatomical space) % - fibindex: Mx2 array of start index and end index (in tracts_xyz) of each m-th fiber % - tracts_xyz_dti: 3x(n*M) array of all points of all fibers (DTI space) % - fibindex_dti: Mx2 array of start index and end index (in tracts_xyz) of each m-th fiber (DTI space) % - est_anat_length: Mx2 vector of polynomial-estimated lengths of each m-th fiber (2nd col) (1st col = fiber index) % - num_pts: Mx2 vector of number of points used in fitting (2nd col) (1st col = fiber index) % - PolyCoeff: has substructures x,y,z,t0,t1 --> polynomial fit coefficients % - RSQ: Mx3 array, col 1 = x R^2 value, col 2 = y R^2 value, col 3 = z R^2 value % - RSQ_adj: Mx3 array, col 1 = x adjusted R^2 value, col 2 = y adjusted R^2 value, col 3 = z adjusted R^2 value % - RMSE: Mx1 array, RMSE value of m-th fiber % - curvature: Mx1 vector with curvature for each m-th fiber % - penangle: Mx1 vector with pennation angles for each m-th fiber % - FA,AD,MD,RD: each is Mx1 vector of average diffusivity for each m-th fiber % - inflection_loc = Mx1 cell with t location of inflection points of each m-th fibers % - inflection_pts = Mx1 cell with number of inflection points of each of m-th fibers % ----------------- NOTE ----------------- % run in pathway describing the limb that contains the directory of muscle being analyzed (EX. run this in 'DominantLower' folder) %% Set Up Structure % Define structure and save each parameter used DTItracts = struct; % Define variables using inputs DTItracts.order = order; % polynomial order for fitting tracts_path = strcat(muscle_path); % tracts_path: string of pathway directory of where the tracked files are located (EX: 'FCU') %% Extrapolate Coordinates and Make Arrays with Points fprintf('Finding coordinates and making structures for tracts in: %s...\n',tracts_path); [DTItracts,M,nan_rows] = FindCoordinates_Deterministic(DTItracts,tracts_path); % Extract coordinates from raw tracts, save valid tracts to structures disp('Coordinates saved.'); %% Find Diffusivity Values fprintf('Reading Diffusivity Values for tracts in: %s...\n',tracts_path); [DTItracts] = ReadDiffusivity_Deterministic(DTItracts,tracts_path,nan_rows); % Calculate diffusivity metrics for each tract disp('Diffusivity values saved.'); %% Perform Polynomial Fitting fprintf('Performing polynomial fit for tracts in: %s...\n',tracts_path); [DTItracts] = LSQ_Polynomial(DTItracts,order,M); % Fit polynomial curve of given order to each tract disp('Polynomial fitting complete.'); %% Find Pennation Angles pointA = apo_line(1,:); % Save starting point of aponeurosis pointB = apo_line(2,:); % Save ending point of aponeurosis fprintf('Finding pennation angles for tracts in: %s...\n',tracts_path); [DTItracts] = FindPennation_Deterministic(DTItracts,M,pointA,pointB); % Find pennation angle of each tract using the points from the aponeurosis vector disp('Pennation angles calculated.'); %% Find Curvature fprintf('Finding curvature values for tracts in: %s...\n',tracts_path); [DTItracts] = FindCurvature(DTItracts,M); % Find curvature of each tract disp('Curvature calculated.'); %% Find Inflection Points fprintf('Finding inflection points for tracts in: %s...\n',tracts_path); [DTItracts] = FindInflection(DTItracts,M); % Find "inflection points" (S-shapes, concave to convex) of each tract disp('Inflection points calculated.'); %% Muscle Parameters Calculated disp('Muscle Parameter Calculations DONE!'); end