-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjpa_writeThresholdTmap.m
More file actions
60 lines (57 loc) · 1.75 KB
/
jpa_writeThresholdTmap.m
File metadata and controls
60 lines (57 loc) · 1.75 KB
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
function jpa_writeThresholdTmap(pathInputMap, pathOutputMap, threshold)
% Function that reads an Input map containing t or f-values from a
% statistical contrast and writes out a thresholded version of these Input
% in subfolder
%
% Syntax:
% jpa_writeThresholdTmap(pathInputMap, pathOutputMap, threshold)
%
% Inputs:
% pathInputMap - file with complete path where the T/F-Map is located
% pathOutputMap - file with complete path to write output
% threshold - threshold for filtering data
%
% Outputs:
% map_supathresh - T/F-Map with filtered values
%
% Example:
% jpa_writeThresholdTmap('C:\example\con_0001.nii',
% 'C:\example\thresholded\con_0001.nii', 1.5)
%
% Other m-files required: none
% Subfunctions: none
% MAT-files required: none
%
% See also:
% Author: Jan Albrecht, Alexander Genauck
% Work address:
% email: jan-philipp.albrecht@charite.de, j.p.albrecht@fu-berlin.de
% Website:
% Sep 2015; Last revision: 29-Sep-2015
%------------- BEGIN CODE --------------
% Step 1: Load spmT*.img which is a map containing t-values from a
% statistical contrast
try
V = spm_vol(pathInputMap);
Map = spm_read_vols(V);
catch ME
disp(['Failed to load ' pathInputMap ' Reason:']);
error(ME.identifier);
end
% Step 2: Extract all voxels in TMap that are greater than tthresh
Map_suprathresh = Map;
Map_suprathresh(Map <= threshold) = 0;
% Step 3: Write out TMap_suprathresh as its own image.
% seperate File from Path
[outPath,outFile,ext] = fileparts(pathOutputMap);
outFile = strcat(outFile,ext);
if ~exist(outPath,'dir'); mkdir(outPath); end
% set name
V.fname = outFile;
V.private.dat.fname = outFile;
% write
cd(outPath)
spm_write_vol(V,Map_suprathresh);
cd(fileparts(pathInputMap));
end
%------------- END CODE --------------