|
1 | | -function matlabbatch = setBatchSegmentation(matlabbatch, opt, imageToSegment) |
| 1 | +function [matlabbatch, opt] = setBatchSegmentation(matlabbatch, opt, imageToSegment) |
2 | 2 | % |
3 | 3 | % Creates a batch to segment the anatomical image |
4 | 4 | % |
|
16 | 16 | % |
17 | 17 | % (C) Copyright 2020 CPP_SPM developers |
18 | 18 |
|
| 19 | + if ~opt.segment.do |
| 20 | + opt.orderBatches.segment = 0; |
| 21 | + return |
| 22 | + else |
| 23 | + opt.orderBatches.segment = numel(matlabbatch) + 1; |
| 24 | + end |
| 25 | + |
19 | 26 | printBatchName('Segmentation anatomical image', opt); |
20 | 27 |
|
21 | 28 | % define SPM folder |
22 | 29 | spmLocation = spm('dir'); |
23 | 30 |
|
24 | 31 | % save bias correction field = false |
25 | 32 | % save bias corrected image = true |
26 | | - matlabbatch{end + 1}.spm.spatial.preproc.channel.write = [false true]; |
| 33 | + preproc.channel.write = [false true]; |
27 | 34 |
|
| 35 | + % firts part assumes we are in the bidsSpatialPreproc workflow |
28 | 36 | if isfield(opt, 'orderBatches') && isfield(opt.orderBatches, 'selectAnat') |
29 | 37 |
|
30 | 38 | % SAVE BIAS CORRECTED IMAGE |
31 | | - matlabbatch{end}.spm.spatial.preproc.channel.vols(1) = ... |
32 | | - cfg_dep('Named File Selector: Anatomical(1) - Files', ... |
33 | | - returnDependency(opt, 'selectAnat'), ... |
34 | | - substruct('.', 'files', '{}', {1})); |
| 39 | + preproc.channel.vols(1) = cfg_dep('Named File Selector: Anatomical(1) - Files', ... |
| 40 | + returnDependency(opt, 'selectAnat'), ... |
| 41 | + substruct('.', 'files', '{}', {1})); |
35 | 42 | else |
36 | 43 |
|
| 44 | + % TODO |
| 45 | + % implement the opt.segment.do and opt.segment.force |
| 46 | + % with segmentationAlreadyDone ? |
| 47 | + |
37 | 48 | % in case a cell was given as input |
38 | 49 | if iscell(imageToSegment) |
39 | 50 | imageToSegment = char(imageToSegment); |
|
42 | 53 | % add all the images to segment |
43 | 54 | for iImg = 1:size(imageToSegment, 1) |
44 | 55 | file = validationInputFile([], deblank(imageToSegment(iImg, :))); |
45 | | - matlabbatch{end}.spm.spatial.preproc.channel.vols{iImg, 1} = file; |
| 56 | + preproc.channel.vols{iImg, 1} = file; |
46 | 57 | end |
47 | 58 |
|
48 | 59 | end |
49 | 60 |
|
50 | | - matlabbatch{end}.spm.spatial.preproc.channel.biasreg = 0.001; |
51 | | - matlabbatch{end}.spm.spatial.preproc.channel.biasfwhm = opt.segment.biasfwhm; |
| 61 | + preproc.channel.biasreg = 0.001; |
| 62 | + preproc.channel.biasfwhm = opt.segment.biasfwhm; |
52 | 63 |
|
53 | 64 | % CREATE SEGMENTS IN NATIVE SPACE OF GM, WM AND CSF |
54 | 65 | nativeSpace = 1; |
55 | 66 | dartelSpace = 0; |
56 | 67 | native = [nativeSpace dartelSpace]; |
57 | | - matlabbatch{end}.spm.spatial.preproc.tissue(1).tpm = ... |
58 | | - {[fullfile(spmLocation, 'tpm', 'TPM.nii') ',1']}; |
59 | | - matlabbatch{end}.spm.spatial.preproc.tissue(1).ngaus = 1; |
60 | | - matlabbatch{end}.spm.spatial.preproc.tissue(1).native = native; |
61 | | - matlabbatch{end}.spm.spatial.preproc.tissue(1).warped = [0 0]; |
62 | | - |
63 | | - matlabbatch{end}.spm.spatial.preproc.tissue(2).tpm = ... |
64 | | - {[fullfile(spmLocation, 'tpm', 'TPM.nii') ',2']}; |
65 | | - matlabbatch{end}.spm.spatial.preproc.tissue(2).ngaus = 1; |
66 | | - matlabbatch{end}.spm.spatial.preproc.tissue(2).native = native; |
67 | | - matlabbatch{end}.spm.spatial.preproc.tissue(2).warped = [0 0]; |
68 | | - |
69 | | - matlabbatch{end}.spm.spatial.preproc.tissue(3).tpm = ... |
70 | | - {[fullfile(spmLocation, 'tpm', 'TPM.nii') ',3']}; |
71 | | - matlabbatch{end}.spm.spatial.preproc.tissue(3).ngaus = 2; |
72 | | - matlabbatch{end}.spm.spatial.preproc.tissue(3).native = native; |
73 | | - matlabbatch{end}.spm.spatial.preproc.tissue(3).warped = [0 0]; |
74 | | - |
75 | | - matlabbatch{end}.spm.spatial.preproc.tissue(4).tpm = ... |
76 | | - {[fullfile(spmLocation, 'tpm', 'TPM.nii') ',4']}; |
77 | | - matlabbatch{end}.spm.spatial.preproc.tissue(4).ngaus = 3; |
78 | | - matlabbatch{end}.spm.spatial.preproc.tissue(4).native = [0 0]; |
79 | | - matlabbatch{end}.spm.spatial.preproc.tissue(4).warped = [0 0]; |
80 | | - |
81 | | - matlabbatch{end}.spm.spatial.preproc.tissue(5).tpm = ... |
82 | | - {[fullfile(spmLocation, 'tpm', 'TPM.nii') ',5']}; |
83 | | - matlabbatch{end}.spm.spatial.preproc.tissue(5).ngaus = 4; |
84 | | - matlabbatch{end}.spm.spatial.preproc.tissue(5).native = [0 0]; |
85 | | - matlabbatch{end}.spm.spatial.preproc.tissue(5).warped = [0 0]; |
86 | | - |
87 | | - matlabbatch{end}.spm.spatial.preproc.tissue(6).tpm = ... |
88 | | - {[fullfile(spmLocation, 'tpm', 'TPM.nii') ',6']}; |
89 | | - matlabbatch{end}.spm.spatial.preproc.tissue(6).ngaus = 2; |
90 | | - matlabbatch{end}.spm.spatial.preproc.tissue(6).native = [0 0]; |
91 | | - matlabbatch{end}.spm.spatial.preproc.tissue(6).warped = [0 0]; |
| 68 | + preproc.tissue(1).tpm = {[fullfile(spmLocation, 'tpm', 'TPM.nii') ',1']}; |
| 69 | + preproc.tissue(1).ngaus = 1; |
| 70 | + preproc.tissue(1).native = native; |
| 71 | + preproc.tissue(1).warped = [0 0]; |
| 72 | + |
| 73 | + preproc.tissue(2).tpm = {[fullfile(spmLocation, 'tpm', 'TPM.nii') ',2']}; |
| 74 | + preproc.tissue(2).ngaus = 1; |
| 75 | + preproc.tissue(2).native = native; |
| 76 | + preproc.tissue(2).warped = [0 0]; |
| 77 | + |
| 78 | + preproc.tissue(3).tpm = {[fullfile(spmLocation, 'tpm', 'TPM.nii') ',3']}; |
| 79 | + preproc.tissue(3).ngaus = 2; |
| 80 | + preproc.tissue(3).native = native; |
| 81 | + preproc.tissue(3).warped = [0 0]; |
| 82 | + |
| 83 | + preproc.tissue(4).tpm = {[fullfile(spmLocation, 'tpm', 'TPM.nii') ',4']}; |
| 84 | + preproc.tissue(4).ngaus = 3; |
| 85 | + preproc.tissue(4).native = [0 0]; |
| 86 | + preproc.tissue(4).warped = [0 0]; |
| 87 | + |
| 88 | + preproc.tissue(5).tpm = {[fullfile(spmLocation, 'tpm', 'TPM.nii') ',5']}; |
| 89 | + preproc.tissue(5).ngaus = 4; |
| 90 | + preproc.tissue(5).native = [0 0]; |
| 91 | + preproc.tissue(5).warped = [0 0]; |
| 92 | + |
| 93 | + preproc.tissue(6).tpm = {[fullfile(spmLocation, 'tpm', 'TPM.nii') ',6']}; |
| 94 | + preproc.tissue(6).ngaus = 2; |
| 95 | + preproc.tissue(6).native = [0 0]; |
| 96 | + preproc.tissue(6).warped = [0 0]; |
92 | 97 |
|
93 | 98 | % SAVE FORWARD DEFORMATION FIELD FOR NORMALISATION |
94 | | - matlabbatch{end}.spm.spatial.preproc.warp.mrf = 1; |
95 | | - matlabbatch{end}.spm.spatial.preproc.warp.cleanup = 1; |
96 | | - matlabbatch{end}.spm.spatial.preproc.warp.reg = [0 0.001 0.5 0.05 0.2]; |
97 | | - matlabbatch{end}.spm.spatial.preproc.warp.affreg = 'mni'; |
98 | | - matlabbatch{end}.spm.spatial.preproc.warp.fwhm = 0; |
99 | | - matlabbatch{end}.spm.spatial.preproc.warp.samp = opt.segment.samplingDistance; |
100 | | - matlabbatch{end}.spm.spatial.preproc.warp.write = [1 1]; |
| 99 | + preproc.warp.mrf = 1; |
| 100 | + preproc.warp.cleanup = 1; |
| 101 | + preproc.warp.reg = [0 0.001 0.5 0.05 0.2]; |
| 102 | + preproc.warp.affreg = 'mni'; |
| 103 | + preproc.warp.fwhm = 0; |
| 104 | + preproc.warp.samp = opt.segment.samplingDistance; |
| 105 | + preproc.warp.write = [1 1]; |
| 106 | + |
| 107 | + matlabbatch{end + 1}.spm.spatial.preproc = preproc; |
101 | 108 | end |
0 commit comments