You can convert from MNI coordinates to voxel indices by multiplying
with the inverse of the voxel-to-world transform matrix of the image.
Nii = nifti('filename.img');
mni_coords = [10 -20 10]; % for example
M = inv(Nii.mat);
ind = M(1:3,1:3)*mni_coords' + M(1:3,4)
Reading values from a NIfTI file can be done by:
ind = round(ind); % round to closest voxel
f = Nii.dat(ind(1), ind(2), ind(3)) % read value
If you wanted, you could use ranges of values to read, or even read
the entire volume by:
F = Nii.dat(:,:,:);
If you have a series of volumes (the same size) that you'd like to
work with, you can concatenate the data by:
P=spm_select(Inf,'nifti');
Nii = nifti(P);
X = cat(4,Nii.dat);
Then you could read a time series by:
f = squeeze(X(ind(1), ind(2), ind(3), :))
If you have lots of memory, then you could read the entire dataset by:
F = X(:,:,:,:);
Best regards,
-John
2011/3/17 黄沛钰 <[log in to unmask]>:
> Hi everybody,
> I'm trying to write a customized programme which would be used to calculate
> the specific signal changes between different designed blocks, for example,
> picking out those voxels whose BOLD signal change are between 1% & 2%.
> I've done the preprocessing by SPM. The problem is, I don't quite
> understand how images were stored in the NIfTI files. How do I get a BOLD
> value corresponding to a specific voxel interpreted by MNI coordinates?
> Or could you recommend me some existing tools that could be used in my
> purpose?
>
> Thanks!
> Peiyu, Huang
|