Skip to content

Commit

Permalink
Fixed error reported by S.magothr. (New Segment error).
Browse files Browse the repository at this point in the history
  • Loading branch information
andreashorn committed Apr 11, 2016
1 parent f599918 commit c5bb0d5
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 16 deletions.
18 changes: 18 additions & 0 deletions ea_checkforwardinv.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
function ea_checkforwardinv(options,forwardinv)

switch forwardinv
case 'forward'
V=spm_vol([options.root,options.patientname,filesep,'y_ea_normparams.nii']);
Vmni=spm_vol([options.earoot,'templates',filesep,'mni_hires.nii']);

if ~isequal(V.dim,Vmni.dim)

ea_redo_inv([options.root,options.patientname,filesep],options,'forward');
end
case 'inverse'
V=spm_vol([options.root,options.patientname,filesep,'y_ea_inv_normparams.nii']);
Vanat=spm_vol([options.root,options.patientname,filesep,options.prefs.prenii_unnormalized]);
if ~isequal(V.dim,Vanat.dim)
ea_redo_inv([options.root,options.patientname,filesep],options,'inverse');
end
end
40 changes: 36 additions & 4 deletions ea_generate_tpm.m
Original file line number Diff line number Diff line change
@@ -1,13 +1,45 @@
function ea_generate_tpm
function ea_generate_tpm(varargin)

spmdir=[fileparts(which('spm')),filesep];
earoot=[fileparts(which('lead')),filesep];
if nargin
earoot=varargin{1}.earoot;
end

switch spm('ver')
case 'SPM8'
copyfile([spmdir,'toolbox',filesep,'Seg',filesep,'TPM.nii'],[earoot,'templates',filesep,'TPM.nii']);
copyfile([spmdir,'toolbox',filesep,'Seg',filesep,'TPM.nii'],[earoot,'templates',filesep,'TPM.nii']);
case 'SPM12'
copyfile([spmdir,'tpm',filesep,'TPM.nii'],[earoot,'templates',filesep,'TPM.nii']);
copyfile([spmdir,'tpm',filesep,'TPM.nii'],[earoot,'templates',filesep,'TPM.nii']);
end

ea_reslice_nii([earoot,'templates',filesep,'TPM.nii'],[earoot,'templates',filesep,'TPM.nii'],[0.5 0.5 0.5],0,0,3);

for tp=1:6
matlabbatch{1}.spm.util.imcalc.input = {[earoot,'templates',filesep,'mni_hires.nii']
[earoot,'templates',filesep,'TPM.nii,1']
[earoot,'templates',filesep,'TPM.nii,2']
[earoot,'templates',filesep,'TPM.nii,3']
[earoot,'templates',filesep,'TPM.nii,4']
[earoot,'templates',filesep,'TPM.nii,5']
[earoot,'templates',filesep,'TPM.nii,6']};
matlabbatch{1}.spm.util.imcalc.output = [earoot,'templates',filesep,'TPM_',num2str(tp),'.nii'];
matlabbatch{1}.spm.util.imcalc.outdir = {''};
matlabbatch{1}.spm.util.imcalc.expression = ['i',num2str(tp+1)];
matlabbatch{1}.spm.util.imcalc.var = struct('name', {}, 'value', {});
matlabbatch{1}.spm.util.imcalc.options.dmtx = 0;
matlabbatch{1}.spm.util.imcalc.options.mask = 0;
matlabbatch{1}.spm.util.imcalc.options.interp = 1;
matlabbatch{1}.spm.util.imcalc.options.dtype = 4;
cfg_util('run',{matlabbatch});
fis{tp}=[earoot,'templates',filesep,'TPM_',num2str(tp),'.nii'];
end
clear matlabbatch
matlabbatch{1}.spm.util.cat.vols = fis;
matlabbatch{1}.spm.util.cat.name = [earoot,'templates',filesep,'TPM.nii'];
matlabbatch{1}.spm.util.cat.dtype = 4;
cfg_util('run',{matlabbatch});

for fi=1:length(fis)
delete(fis{fi});
end
delete([earoot,'templates',filesep,'TPM.mat']);
1 change: 1 addition & 0 deletions ea_map_coords.m
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@
Vx=spm_vol([hdwim,',1,1']);
Vy=spm_vol([hdwim,',1,2']);
Vz=spm_vol([hdwim,',1,3']);

for i = 1:size(coord, 2)
ind = inds(:, i);
coord(1,i)=spm_sample_vol(Vx,ind(1),ind(2),ind(3),1);
Expand Down
10 changes: 5 additions & 5 deletions ea_reconstruction2native.m
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,19 @@ function ea_reconstruction2native(options)
[~,tempfile]=ea_whichnormmethod(directory);
nii=ea_load_nii(tempfile);


ea_checkforwardinv(options,'forward')

for side=options.sides


reco.native.coords_mm{side}=ea_warpcoord(reco.mni.coords_mm{side},nii,options);
reco.native.markers(side).head=ea_warpcoord(reco.mni.markers(side).head,nii,options);
reco.native.markers(side).tail=ea_warpcoord(reco.mni.markers(side).tail,nii,options);
reco.native.trajectory{side}=ea_warpcoord(reco.mni.trajectory{side},nii,options);

normtrajvector{side}=mean(diff(reco.native.trajectory{side}))/norm(mean(diff(reco.native.trajectory{side})));
try
orth=null(normtrajvector{side})*(options.elspec.lead_diameter/2);
catch
keyboard
end


reco.native.markers(side).x=reco.native.markers(side).head+orth(:,1)';
reco.native.markers(side).y=reco.native.markers(side).head+orth(:,2)'; % corresponding points in reality
Expand Down
33 changes: 27 additions & 6 deletions ea_redo_inv.m
Original file line number Diff line number Diff line change
@@ -1,6 +1,27 @@
function ea_redo_inv(directory,options)
matlabbatch{1}.spm.util.defs.comp{1}.inv.comp{1}.def = {[directory,'y_ea_normparams.nii']};
matlabbatch{1}.spm.util.defs.comp{1}.inv.space = {[directory,options.prefs.prenii_unnormalized]};
matlabbatch{1}.spm.util.defs.out{1}.savedef.ofname = 'ea_inv_normparams.nii';
matlabbatch{1}.spm.util.defs.out{1}.savedef.savedir.saveusr = {directory};
spm_jobman('run',{matlabbatch});
function ea_redo_inv(varargin)
directory=varargin{1};
options=varargin{2};
if nargin>2
forinv=varargin{3};
else
forinv='inverse';
end
switch forinv
case 'inverse'
matlabbatch{1}.spm.util.defs.comp{1}.inv.comp{1}.def = {[directory,'y_ea_normparams.nii']};
matlabbatch{1}.spm.util.defs.comp{1}.inv.space = {[directory,options.prefs.prenii_unnormalized]};
matlabbatch{1}.spm.util.defs.out{1}.savedef.ofname = 'ea_inv_normparams.nii';
matlabbatch{1}.spm.util.defs.out{1}.savedef.savedir.saveusr = {directory};
spm_jobman('run',{matlabbatch});

case 'forward'


matlabbatch{1}.spm.util.defs.comp{1}.id.space = {[options.earoot,'templates',filesep,'mni_hires.nii']};
matlabbatch{1}.spm.util.defs.comp{1}.def = {[directory,'y_ea_normparams.nii']};
matlabbatch{1}.spm.util.defs.out{1}.savedef.ofname = 'ea_normparams.nii';
matlabbatch{1}.spm.util.defs.out{1}.savedef.savedir.saveusr = {directory};
spm_jobman('run',{matlabbatch});


end
5 changes: 4 additions & 1 deletion ext_libs/segment/ea_newseg.m
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
function ea_newseg(directory,file,dartel,options)

if ~exist([options.earoot,'templates',filesep,'TPM.nii'],'file')
ea_generate_tpm(options);
end

disp('Segmentation...');
switch spm('ver')
Expand Down Expand Up @@ -38,7 +41,7 @@ function ea_newseg(directory,file,dartel,options)
clear matlabbatch
case 'SPM12'
load([options.earoot,'ext_libs',filesep,'segment',filesep,'segjob12']);
tpminf=fullfile(fileparts(which('spm')),'tpm',['TPM.nii']);
tpminf=[options.earoot,'templates',filesep,'TPM.nii'];
job.channel.vols{1}=[directory,file,',1'];
for tpm=1:6
job.tissue(tpm).tpm=[tpminf,',',num2str(tpm)];
Expand Down

0 comments on commit c5bb0d5

Please sign in to comment.