1234567891011121314151617181920212223242526272829303132333435363738394041 |
- % Input folder path containing fMRI data
- input_folder = "C:\Users\aswen\Desktop\TestingData\Aswendt_qc_data\proc_data";
- % Get all rsfMRI files in the input folder
- searchpath = fullfile(input_folder, '**', 'func', '*EPI.nii.gz');
- rsfmri_files = dir(searchpath);
- rsfmri_files = fullfile({rsfmri_files.folder}, {rsfmri_files.name});
- % Parameters for motion addition
- translation_amount_initial = 7; % Initial translation amount in pixels
- translation_amount_growth = 1; % Amount by which translation increases at each time point
- translation_amount_max = 30; % Maximum translation amount in pixels
- timepoints = size(Im, 4); % Number of time points
- % Loop through each rsfMRI file for motion addition
- for i = 1:numel(rsfmri_files)
- % Read file
- file = rsfmri_files{i};
-
- % Load the 4D rsfMRI image and its info
- Im = niftiread(file);
- info = niftiinfo(file);
- % Initialize translation amount
- translation_amount = translation_amount_initial;
-
- % Add motion by shifting each volume in the time series
- for t = 1:timepoints
- % Apply translation to simulate motion
- Im(:,:,:,t) = imtranslate(Im(:,:,:,t), [translation_amount, 0, 0]);
-
- % Update translation amount for the next time point
- translation_amount = min(translation_amount + translation_amount_growth, translation_amount_max);
- end
-
- % Save the motion-added 4D rsfMRI image
- [filepath, filename, ext] = fileparts(file);
- output_filename = [filename '_motion_added' ext]; % Appending '_motion_added' to the filename
- output_path = fullfile(filepath, output_filename);
- niftiwrite(Im, output_path, info, 'Compressed', true);
- end
|