Lukas,
Here is a very simple script that calls imcalc (spm99) to multiply an image
by a
binary mask image and write the results. I haven't tested it in spm2.
Andy Saykin
At 07:38 PM 9/24/2003, you wrote:
>Hi!
>
>It is probably a very simple issue, but I wonder if there is an easy
>solution for that in SPM2.
>The problem I am struggeling with is:
>1) I one mask
>2) I have a large number of images
>I want to multiply each image with the mask and write out the masked images.
>
>I know how to do it with ImCalc for a single image: i1 .* i2
>But as far as I know ImCalc writes out only one output file and therefore
>I would like to repeat
>this operation for a large picture set....
>
>If anyone has a batch script for SPM2 or knows, how to do that with
>ImCalc, please let me
>know...
>
>Thanks,
>
>Lukas
========================================================
Andrew J. Saykin, PsyD, ABPP
Professor of Psychiatry and Radiology
Director, Neuropsychology Program and Brain Imaging Laboratory
Department of Psychiatry - DHMC
Dartmouth Medical School
Lebanon, NH 03756
Tel. (603) 650-5824
Fax (603) 650-5842
email:[log in to unmask]
http://synapse.hitchcock.org
========================================================
IMPORTANT NOTICE REGARDING THIS ELECTRONIC MESSAGE
This message is intended for the use of the person to whom it is addressed
and may contain information that is privileged, confidential, and protected
from disclosure under applicable law. If you are not the intended
recipient, your use of this message for any purpose is strictly
prohibited. If you have received this communication in error, please
delete the message and notify the sender so that we may correct our records.
% =========================================================================
% mask_files.m ajs 10-09-02
% =========================================================================
curr_dir = pwd ;
% choose files to mask
FILE_LIST = spm_get(Inf,'.img','Select Analyze Images to Multiply by a Mask:', curr_dir);
n = size(FILE_LIST,1);
MASK = spm_get(1,'*.img','Select Analyze Binary Mask Image:', curr_dir);
% ===================================================================
% [pth filnam xt temp ]= fileparts(P) ;
% Perform algebraic functions on images
% FORMAT Q = spm_imcalc_ui(P,Q,f,flags,Xtra_vars...)
% P - matrix of input image filenames
% [user prompted to select files if arg missing or empty]
% Q - name of output image
% [user prompted to enter filename if arg missing or empty]
% f - expression to be evaluated
% [user prompted to enter expression if arg missing or empty]
% flags - cell vector of flags: {dmtx,mask,type,hold}
% dmtx - Read images into data matrix?
% [defaults (missing or empty) to 0 - no]
% mask - implicit zero mask?
% [defaults (missing or empty) to 0]
% type - data type for output image (see spm_type)
% [defaults (missing or empty) to 4 - 16 bit signed shorts]
% hold - interpolation hold (see spm_slice_vol)
% [defaults (missing or empty) to 0 - nearest neighbour]
% Xtra_vars... - additional variables which can be used in expression
% Q (output) - full pathname of image written
% Vo - structure containing information on output image (see spm_vol)
%
% original model --- spm_imcalc_ui(P,'GM_048','i1./(i1+i2+eps).*i3')
% newer model for cleaning up grey matter: i1.*i4./(i1+i2+eps)
% str = ['spm_imcalc_ui(P,''',fn3,'''',','' i1.*i4./(i1+i2+eps)''',')' ]
% eval(str)
for file_num = 1:n
FILE = deblank(FILE_LIST(file_num,:));
FILE_new = [FILE(1:end-4), '_msk']
FILES = cell(2,1)
FILES{1} = FILE ;
FILES{2} = MASK ;
P= char(FILES);
% FORMAT Q = spm_imcalc_ui(P,Q,f,flags,Xtra_vars...)
str = ['spm_imcalc_ui(P,''',FILE_new,'''',','' i1.*i2''',')' ]
eval(str)
disp(['Masking ',FILE, ' ', num2str(file_num), ' of ' num2str(n)]);
end
|