volumesegment has spm2 related memory issues

Jan Mathijs Schoffelen Jan.Schoffelen at FCDONDERS.RU.NL
Fri Mar 23 20:57:39 CET 2007

Dear Sameer,

To give a short answer to your question: I never noticed a problem like
this. I indeed think, that there is something not completely correct with
the input. Let have a look at the code together to get a clue what might go
wrong. You were on the good track working out the numbers, but let's pursue
it a bit further:

>Error in ==> spm_smoothto8bit>smoothto8bit at 41
>buff = zeros([V.dim(1:2) r{3}.s*2+1]);
>On printing out these numbers, I find that spm2 is attempting to create a
>Of size  (256     x    256   x    23783).

The number 23783 likely causes the problem, because it's rather big.
Apparently, r{3}.s*2+1 = 23783. So what is r{3}.s? Clearly this amounts to
11891. When we have a look into the for-loop, preceding the line which
causes the crash, we see that r{3}.s = ceil(3.5*sqrt(s(i))). So, the
variable s(i) (as an element of the 1x3-vector) is about 1.15e7. A few lines
up, it says that s = (fwhm./vx./sqrt(8*log(2)) + eps).^2
Let's forget about eps (which is the numerical round-off error), some
juggling with the numbers leads to fwhm./vx being [8000 8000 8000].
Typically fwhm = [8 8 8] (in mm), so vx in your case was something like
0.001. And this vx is derived from a variable V.mat, which is the
affine-matrix which came along with the volume the function tries to smooth.
This affine-matrix is needed to interpret the voxels in terms of a physical
coordinate system. Importantly, since the smoothing kernel is defined in mm,
the mapping which this matrix brings about, should also be defined in mm.
Because there's a factor 1000 difference here, I suspect that your matrix
has metres as a unit, instead of mm. The V.mat variable is taken from the
input-mri, and is equal to mri.transform. Apparently, implicitly it assumes
it to be defined in mm. So for now, I'd suggest to massage this
mri.transform a bit such that starts to behave nicely. I guess it should be
something like mri.transform(1:3,:) = 1000.*mri.transform(1:3,:);
Then you should have a look at mri.transform(1:3,1:3). If you have a 1mm
resolution mri, then sqrt(sum(mri.transform(1:3,1:3).^2)) should be one-ish.

Good luck,


-----Original Message-----
From: FieldTrip discussion list [mailto:FIELDTRIP at NIC.SURFNET.NL] On Behalf
Of Sameer Walawalkar
Sent: Friday, March 23, 2007 5:19 PM
Subject: [FIELDTRIP] volumesegment has spm2 related memory issues


When I run
>> [segment] = volumesegment(cfg,mri)
I get memory problems at a particular line in a spm2 matlab file.

The error message  is :

performing the segmentation on the specified volume
??? Error using ==> zeros
Out of memory. Type HELP MEMORY for your options.

Error in ==> spm_smoothto8bit>smoothto8bit at 41
buff = zeros([V.dim(1:2) r{3}.s*2+1]);

On printing out these numbers, I find that spm2 is attempting to create a
Of size  (256     x    256   x    23783).

Has anyone else has had these kind of problems with spm2?  Or is there
(this is more likely) my problem with implementation.

The information about mri is:
>> mri
mri =
           dim: [256 256 256]
       anatomy: [256x256x256 uint8]
           hdr: [1x1 struct]
     transform: [4x4 double]

Thanks a lot.


More information about the fieldtrip mailing list