Hi Marko!
I modified spm_smoothto8bit.m a while ago, so that you could pass the image-matrix you wanted to smooth instead of the mapping. That is, you can do the smoothing in memory without having to save anything to disk.
Note, that the attached script creates 64 bit (double) version of your data.
Hope this helps
Simon
-----------------------------------------
Simon Eickhoff
Institut for Medicine (IME); Research Center Jülich
Leo-Brandt-Str. 5; 52425 Juelich, Germany
Phone + 49 2461-61-5219 / Fax + 49 2461-61-2820
e-mail: [log in to unmask] / [log in to unmask]
----- Original Message -----
From: Marko Wilke <[log in to unmask]>
Date: Wednesday, November 15, 2006 11:02 pm
Subject: [SPM] Smooth images in Memory
> Dear All,
> I would like to run some analyses for which it would be very handy
> to
> smooth image volumes in memory. In other words, I do not want to
> smooth
> the images and load them but load them and smooth them without
> writing
> them to disk. I have looked into spm_smooth_ui but it calls
> spm_conv_vol
> which is a compiled function.
>
> Has anyone done this before and could guide me into the right
> direction?
> I know matlab comes with convn but I am not sure how to specify
> the
> Gaussian filter I would be interested in...
>
> Thanks,
> Marko
> --
> =====================================================================
> Marko Wilke (Dr.med./M.D.)
> [log in to unmask]
>
> Universitäts-Kinderklinik University Children's Hospital
> Abt. III (Neuropädiatrie) Dept. III (Pediatric neurology)
> Hoppe-Seyler-Str. 1, D - 72076 Tübingen
> Tel.: (+49) 07071 29-83416 Fax: (+49) 07071 29-5473
> =====================================================================
>
>
function sdata = MemSmooth64bit(data,fwhm,Vo)
% FORMAT sdata = MemSmooth64bit(data,fwhm,Vo)
% Vo - mapped image describing the volume loaded in data
% fwhm - FWHM of Guassian filter width in mm
% data - unsmoothed 3D matrix
%
%_______________________________________________________________________
%
%_______________________________________________________________________
% Copyright (C) 2005 Wellcome Department of Imaging Neuroscience
% John Ashburner
% $Id: spm_smoothto8bit.m 112 2005-05-04 18:20:52Z john $
vx = sqrt(sum(V.mat(1:3,1:3).^2));
s = (fwhm./vx./sqrt(8*log(2)) + eps).^2;
r = cell(1,3);
for i=1:3,
r{i}.s = ceil(3.5*sqrt(s(i)));
x = -r{i}.s:r{i}.s;
r{i}.k = exp(-0.5 * (x.*x)/s(i))/sqrt(2*pi*s(i));
r{i}.k = r{i}.k/sum(r{i}.k);
end;
buff = zeros([V.dim(1:2) r{3}.s*2+1]);
sdata = double(0);
sdata(V.dim(1),V.dim(2),V.dim(3)) = double(0);
for i=1:V.dim(3)+r{3}.s,
if i<=V.dim(3),
img = data(:,:,i);
msk = find(~finite(img));
img(msk) = 0;
buff(:,:,rem(i-1,r{3}.s*2+1)+1) = ...
conv2(conv2(img,r{1}.k,'same'),r{2}.k','same');
else,
buff(:,:,rem(i-1,r{3}.s*2+1)+1) = 0;
end;
if i>r{3}.s,
kern = zeros(size(r{3}.k'));
kern(rem((i:(i+r{3}.s*2))',r{3}.s*2+1)+1) = r{3}.k';
img = reshape(buff,[prod(V.dim(1:2)) r{3}.s*2+1])*kern;
img = reshape(img,V.dim(1:2));
ii = i-r{3}.s;
mx = max(img(:));
mn = min(img(:));
if mx==mn, mx=mn+eps; end;
sdata(:,:,ii) = img;
end;
end;
|