dear SPM users
I am currently intending to analyse some supersampled data from ROI's.
because of the supersampling step i do not want to generate huge files so i
am trying to write a program that chops fM.img files into cubic ROI's prior
to parameter estimation.
firstly is there any program out there that can do this? (there doesnt
appear to be anything on the SPM toolbox website that performs this function)
if not... i need to solve the problem that i have encountered in writing my
own program. the following code works fine in chopping the img files down
to the required cube....
however the problem comes when i display these img files with SPM. the
voxel co-ordinates are (perhaps not so suprisingly) wrong.
how can i write the volumes so that the true XYZ co-ordinates are saved?
%ROI limits
x1=2
x2=8
y1=-6
y2=-34
z1=-10
z2=-36
spm_defaults
%***************
%choose filter
p = spm_get(inf,'rarf*.img','Select images to chop');
%***************
disp('Mapping images...')
v = spm_vol(p);
v2 = v(1); %v2 is the first sampled volume
%Work out coordinates index
[y,xyz] = spm_read_vols(v(1));
% Y - 4D matrix of image data, fourth dimension indexes images
% XYZ - 3xn matrix of XYZ locations returned
f =xyz(1,:)>=x1 & xyz(1,:)<=x2 & xyz(2,:)>=y1 &
xyz(2,:)<=y2 & xyz(3,:)>=z1 & xyz(3,:)<=z2;
ind=find(f~=0);
nvox=length(ind); disp(strcat('number of voxels in remaining
cube=',num2str(nvox)))
previewXYZ=xyz(:,ind)
%------------------------------------------------------------------
%voxel loop
for j = 1:length(v) %loop round for every voxel
[y,xyz] = spm_read_vols(v(j)); %read in file
%reshape and take only those voxels at y <= chopval
y = reshape(y,length(xyz),1); % reshapes into a vector
y = y(f);% chops down vector into sampled portion
%dim2 =length(y)./(v2.dim(1)*v2.dim(3));
%Put these values back into volume
maskvol = reshape(y,dim1,dim2,dim3);%voxdim +1 since this is number of
voxels across sample
%Remake file with c prefix
[pth,nm,suff] = fileparts(p(j,:));
nm = ['c',nm];
%Change structure filename and dimensions...
v2.fname = [pth,'/',nm,suff];
v2.dim(1) = dim1;
v2.dim(2) = dim2;
v2.dim(3) = dim3;
disp(['Writing image ',num2str(j),' out of ',num2str(size(p,1))])
spm_write_vol(v2,maskvol);
end
%------------------------------------------------------------------
thanks,
Ollie Hulme
Oliver Hulme
Post-doctoral research fellow
Laboratory of Neurobiology
Department of Anatomy
University College London
Gower Street
London
WC1E 6BT
tel: 0207 679 2187
mob: 07771 693 608
email: [log in to unmask]
|