Try changing from:
   VF.mat = VF.mat * M;
   VF.mat = M * VF.mat;

I think that should work.

Best regards,

-----Original Message-----
From: SPM (Statistical Parametric Mapping) [mailto:[log in to unmask]] On Behalf Of Marko Wilke
Sent: Tuesday, April 24, 2007 3:27 PM
To: [log in to unmask]
Subject: [SPM] Apply coregistration parameters to seg_sn.mat, 2nd attempt

Dear All,

I sent an email last week regarding the application of updated 
positional information to the sn_seg-file (see

I mentioned that my problem was that if I segment an image, then move it 
by coregistering it to another image, I may not be able to still use the 
information gathered during the initial segmentation (as I have moved 
the image in the meantime).

I had asked for help in applying the coreg parameters to the sn_seg.mat 
file. I thought that I solved this with

   epi = spm_select;
   ana = spm_select;
   [p nm e v] = fileparts(ana);
   g = fullfile(p,['c1' nm '.img']);
   w = fullfile(p,['c2' nm '.img']);

% coregister gm to EPI
   x = spm_coreg(epi,g);

% apply parameters; take along T1, wm and
   M  = inv(spm_matrix(x));
   all_images = char(ana, g, w);
   MM = zeros(4,4,size(all_images,1));
   for iii = 1:size(all_images,1)
	MM(:,:,iii) = spm_get_space(deblank(all_images(iii,:)));
	spm_get_space(deblank(all_images(iii,:)), M*MM(:,:,iii));

% update positional information of original image, coded
% as VF.mat in seg_sn-file
   [p nm e v] = fileparts(ana);
   sn_file = fullfile(p, [nm '_seg_sn.mat']);
   VF.mat = VF.mat * M;

% store updated position
   if spm_matlab_version_chk('7') >= 0,

This changes the positional information in the original files and the 
seg_sn-file as requested.

However, when I then write out the segmentations again (using Christian 
Gaser's toolbox) the segmented images are similar but, using i1-i2, not 
exactly identical: for testing purposes, I tilted the image a little and 
now get a rim of negative values on one side and a rim of positive 
values on the opposite side. This hints towards there being more to it 
then adjusting the positional information as contained in VF.mat when 
wanting to apply the parameters again. I also fiddled with combining M 
and Affine but to no avail (it either over- or undercorrects the problem).

So bottomline, I am somewhat further but not quite there yet, so if 
anyone has an idea on how to modify the seg_sn.mat using the 
coregistration parameters, I would be truly grateful :)

Any hints will be appreciated. Thanks in advance,

PS: I know, the obvious solution is to not move the GM but the EPI, but 
for the heck of it...
Marko Wilke                                            (
                 [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