Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Elbau_et_al_PNAS_2018/create_latency_corrected_amplitude_maps.m
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
60 lines (41 sloc)
1.9 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function create_latency_corrected_amplitude_maps(Canonical, Derivative, Conditions) | |
% Creates latency corrected amplitude maps according to Calhoun et al., | |
% 2004. | |
% Requires Matlab 2017b or later for niftiread function. Otherwise | |
% change function for reading and writing in volumes. | |
% | |
% Input: | |
% Canonical -- file name of beta_????.img of canonical term | |
% Derivative -- file name of beta_????.img of derivative term | |
% Conditions -- cell with condition/ session name as needed for output | |
% name, e.g.: Conditions = {'PreStress', 'Stress', 'PostStress'} | |
% | |
% ---------------------------------------------------------------------- | |
% | |
% Authors: Immanuel Elbau and Philipp Sämann, MPI of Psychiatry- 2017 | |
% | |
% Email: immanuel_elbau@psych.mpg.de or saemann@psych.mpg.de | |
% ------------------------------------------------------------------- | |
% Define Output name | |
Output = ['LatencyCorrectedAmplitudeMap_',Conditions,'.nii']; | |
% Load in Beta of canonical term | |
Info = niftiinfo(Canonical); | |
V1 = niftiread(Info); | |
V1 = reshape(V1, [1 size(V1,1).*size(V1,2).*size(V1,3)]); | |
% Load in Beta of derivative term | |
Info = niftiinfo(Derivative); | |
V2 = niftiread(Info); | |
V2 = reshape(V2, [1 size(V2,1).*size(V2,2).*size(V2,3)]); | |
% Index all voxel with beta1 > beta2 and leave the other ones out of | |
% amplitude corrected amplitude computation. The beta1 < beta2 voxels get | |
% simply beta1 value asssigned | |
Indi = abs(V1) > abs(V2); | |
% Perform claculation according to Formula by Calhoun et al. 2004 | |
LatencyCorrectedAmplitudes(Indi) = sign(V1(Indi)) .* sqrt(V1(Indi).^2 + V2(Indi).^2); | |
LatencyCorrectedAmplitudes(~Indi) = V1(~Indi); | |
% Save output image | |
LatencyCorrectedAmplitudes = reshape(LatencyCorrectedAmplitudes, [Info.ImageSize]); | |
niftiwrite(LatencyCorrectedAmplitudes, Output, Info); | |
% The resulting images were smoothed as described in the SI Appendix (p.7) | |
% with a 6 mm (FWHM) kernel | |
end |