SPM Volume Extraction Script HELP!

7 views (last 30 days)
Catherine
Catherine on 5 Feb 2013
Hello experts:
The script I will post works for SPM5 (running from MATLAB -nojvm). Now on SPM8 that is not supported with -nojvm and possibly other changes to the new version... the script does not work!
Any suggestions would be greatly appreciated.
The volume extractoin script:
1
clear all;
option=input('What volume do you want to get for grey only enter 1 for grey+white enter 2 for grey+white+csf enter 3: ')
scan_list=spm_select(1, 'any','Select scan list file');
scans = load(scan_list);
reg = spm_select(inf,'image','Select Region Mask Images');
V_regs = spm_vol(reg);
m_len=length(V_regs);
if (option == 1 || option == 2 || option == 3)
for i=1:m_len
[Y,XYZ]=spm_read_vols(V_regs(i));
NZ=find(Y);
[prth,nam,ext]=fileparts(V_regs(i).fname);
fid1=fopen(nam,'a');
fprintf(fid1,'%s\n','scans type volume');
for j=1:length(scans)
scanid = num2str(scans(j));
if (5 - length(scanid))==1
prefix = 'mwc10';
elseif (5 - length(scanid))==2
prefix = 'mwc100';
elseif (5 - length(scanid))==3
prefix = 'mwc1000';
else
prefix = 'mwc1';
end
V=spm_vol(fullfile(pwd,[prefix scanid '.img,1']));
M=inv(V.mat);
volume=0;
%lnam=length(V_regs(i).fname);
%nam=V_regs(i).fname(53:lnam-4);
for k=1:length(NZ)
arr=XYZ(:,NZ(k));
vox=M(1:3,:)*[arr;ones(1,size(arr,2))];
intensity=spm_sample_vol(V,vox(1),vox(2),vox(3),1);
if (isnan(intensity) == 1)
intensity = 0;
end
volume=volume+(intensity*8);
end
fprintf(fid1,'%d %s %f\n',scans(j),'gray',volume);
end
fclose(fid1);
end
end
if (option == 2 || option == 3)
for i=1:m_len
[Y,XYZ]=spm_read_vols(V_regs(i));
NZ=find(Y);
[prth,nam,ext]=fileparts(V_regs(i).fname);
fid1=fopen(nam,'a');
%fprintf(fid1,'%s\n','scans type volume');
for j=1:length(scans)
scanid = num2str(scans(j));
if (5 - length(scanid))==1
prefix = 'mwc20';
elseif (5 - length(scanid))==2
prefix = 'mwc200';
elseif (5 - length(scanid))==3
prefix = 'mwc2000';
else
prefix = 'mwc2';
end
V=spm_vol(fullfile(pwd,[prefix scanid '.img,1']));
M=inv(V.mat);
volume=0;
%lnam=length(V_regs(i).fname);
%nam=V_regs(i).fname(53:lnam-4);
for k=1:length(NZ)
arr=XYZ(:,NZ(k));
vox=M(1:3,:)*[arr;ones(1,size(arr,2))];
intensity=spm_sample_vol(V,vox(1),vox(2),vox(3),1);
if (isnan(intensity) == 1)
intensity = 0;
end
volume=volume+(intensity*8);
end
fprintf(fid1,'%d %s %f\n',scans(j),'white',volume);
end
fclose(fid1);
end
end
if (option == 3)
for i=1:m_len
[Y,XYZ]=spm_read_vols(V_regs(i));
NZ=find(Y);
[prth,nam,ext]=fileparts(V_regs(i).fname);
fid1=fopen(nam,'a');
%fprintf(fid1,'%s\n','scans type volume');
for j=1:length(scans)
scanid = num2str(scans(j));
if (5 - length(scanid))==1
prefix = 'mwc30';
elseif (5 - length(scanid))==2
prefix = 'mwc300';
elseif (5 - length(scanid))==3
prefix = 'mwc3000';
else
prefix = 'mwc3';
end
V=spm_vol(fullfile(pwd,[prefix scanid '.img,1']));
M=inv(V.mat);
volume=0;
%lnam=length(V_regs(i).fname);
%nam=V_regs(i).fname(53:lnam-4);
for k=1:length(NZ)
arr=XYZ(:,NZ(k));
vox=M(1:3,:)*[arr;ones(1,size(arr,2))];
intensity=spm_sample_vol(V,vox(1),vox(2),vox(3),1);
if (isnan(intensity) == 1)
intensity = 0;
end
volume=volume+(intensity*8);
end
fprintf(fid1,'%d %s %f\n',scans(j),'csf',volume);
end
fclose(fid1);
end
end
Thank you in advance, Catherine
  1 Comment
Sean de Wolski
Sean de Wolski on 5 Feb 2013
What does "not work mean"? What isn't working? Have you tried using:
dbstop if error
To stop with the debugger at the point of the error?

Sign in to comment.

Answers (0)

Categories

Find more on Medical Physics in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!