On 21/02/06, Woo Suk, Tae <[log in to unmask]> wrote:
> Can I get the matlab script for the standard deviation (SD) calculation of image file?
If you want the standard deviation of the voxels of a single image,
then simply use
std(im(:))
where im contains the voxel data (which you can get into Matlab in
various ways depending on the format, e.g. spm_vol and spm_read_vols),
and the colon simply stacks the voxels into a column vector.
If you want the standard deviation at each voxel across multuple
images, then you could use Matlab's std() again, noting that when
given a matrix it will calculate st devs down the columns, so
something like
x=[im1(:) im2(:) ... imN(:)]'; % note transpose!
y = std(x);
y= reshape(y,size(im1));
should give a standard deviation image.
However, you might find that you don't have enough memory to hold all
your images in a large matrix x and then use std(), instead, you might
need to loop over the images computing sums and sums of squares, and
then compute the standard deviation at the end from the usual formula.
(One thing to watch out for here, due to finite precision effects the
subtraction in the variance formula might give negative values where
it should give zero, so take care to clip these to zero before taking
the square root).
There might be a better way of doing this already built into spm...
Hope that helps,
Ged.
|