-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDataFixHeader.m
37 lines (30 loc) · 1.23 KB
/
DataFixHeader.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
function DataFixHeader( BASEdir )
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Wrote by David André Barrière 09th September 2022
% This function permit to fix header of corrected data for SPM running.
% Usage : set BASEdir variable with your current working directory
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Variables
% Template image for Registration
Template = [ BASEdir,...
'/Turone_Equine_Brain_Atlas_and_Templates',...
'/template.nii' ] ;
Ref_Header = spm_vol_nifti( Template ) ;
Ref_Matrix = spm_read_vols( Ref_Header ) ;
% Filtered Data Directory
DataDir = [ BASEdir,...
'/00-data/' ] ;
% Filtered Data List
NiiFiles = dir( fullfile(DataDir,...
'sub*.nii' ) ) ;
NiiFiles = { NiiFiles(:).name } ;
for i = 1 : 1 : length( NiiFiles )
Nifti_Header = spm_vol_nifti( [ DataDir,...
NiiFiles{i} ] ) ;
Nifti_Matrix = spm_read_vols( Nifti_Header ) ;
%Nifti_Matrix = flip( Nifti_Matrix,3 ) ;
%Nifti_Matrix = flip( Nifti_Matrix,2 ) ;
Ref_Header.fname = Nifti_Header.fname ;
spm_write_vol( Ref_Header,...
Nifti_Matrix ) ;
end