If you copy and paste this into MATLAB, I think it might do what you want. It hasn't been extensively tested though, and is not the approved way of spatially normalising in SPM. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% P = spm_select(2,'image','Select images.'); % Select the files to align. VG = spm_vol(P(1,:)); % Get old-style handles for images VF = spm_vol(P(2,:)); eoptions = struct('cost_fun','nmi',... 'sep', [4 2],... 'tol', [0.02 0.02 0.02 0.001 0.001 0.001 0.01 0.01 0.01 0.001 0.001 0.001],... 'fwhm', [7 7],... 'params', [0 0 0 0 0 0]); % Settings for rigid alignment params = spm_coreg(VG,VF,eoptions); % Run a rigid alignment sep = 2; % Just work at the finer scale eoptions.params = [params 1 1 1 0 0 0]; % Add the extra parameters: 3 zooms and 3 shears params = spm_coreg(VG,VF,eoptions); % Run the full affine alignment R = inv(spm_matrix(params)) % Generate the matrix to premultiply the moved image by %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Best regards, -John On 27 October 2017 at 02:19, Chao Suo <[log in to unmask]> wrote: > Thanks for your explanation, John. > Firstly, I agree with you that the coreg in SPM (6dof) is a bit rough. It > is one of the steps to find a TMS stimulating point from MNI space to > individual space. > That is actually one of the reason we use flirt, which did 12 dof affine > transform. So, svd(Xfm(1:3,1:3)) showed a scaling factor. > > I think there is a good point in the part your cited in fsl website. It > seems the centre of mass of the volume was used as the centre. So I might > need to find the additional transform matrix to make the shift, which could > be the last puzzle. > > At the meantime, could you suggest how to do a 12dof affine "coreg" in > spm? I'm thinking to re-do this step on SPM, if possible. > > Thanks, > > Chao > > > On 26 October 2017 at 21:03, John Ashburner <[log in to unmask]> wrote: > >> My first point is that you won't get very good alignment if you just use >> Coreg to get to MNI space, as it only does rigid alignment and doesn't >> handle the different sized and differently shaped brains. >> >> I'm not quite sure what Mark J and the guys in FMRIB use for encoding >> their transforms, so I can't say much here. What I do notice though is >> that the Xfm does not encode a rigid body transform. Ignoring the >> translations, the transform is decomposed into a rigid body rotation, some >> isotropic zooms and another rigid body transform, which can be computed via >> SVD. The zooms are: >> >> > svd(Xfm(1:3,1:3)) >> >> ans = >> >> 1.0730 >> 1.0291 >> 0.9739 >> >> This suggests that the matrix does not encode a rigid transform. If you >> called FLIRT with 6 dof, then I really have no idea what the matrix encodes. >> >> I seems that FLIRT ignores things like the origin in the images, which >> may account for the very different translations. According to >> https://fsl.fmrib.ox.ac.uk/fsl/fslwiki/FLIRT/FAQ : >> >> The FSL convention for transformation matrices uses an implicit centre of >> transformation - that is, a point that will be unmoved by that >> transformation, which is an arbitrary choice in general. This arbitrary >> centre of the transformation for FSL is at the mm origin (0,0,0) which is >> at the centre of the corner voxel of the image. >> >> When using the transformation parameters from FLIRT, there is an >> additional complication in that the parameters are calculated in a way that >> uses a different centre convention: the centre of mass of the volume. The >> effect of this is that each of the three matrices above end up with an >> adjustment in the fourth column (top three elements only) that represents a >> shift between the corner origin and the centre of mass, while the rest of >> the matrix (first three columns) is unaffected. Once that is done the >> matrices are multiplied together, as indicated above, and you get your >> final matrix. >> >> >> Best regards, >> -John >> >> >> >> >> >> >> >> On 26 October 2017 at 01:37, Chao Suo <0000171bf1c6344d-dmarc-reques >> [log in to unmask]> wrote: >> >>> Dear SPM/FSL users, >>> >>> I have a question about the inconsistent transform matrix during linear >>> corregister using SPM and FSL. >>> For example, I have one image (Qform is A) coregistered to an MNI space >>> using a standard MNI template using "Coregister: Estimate" function. >>> The new image’s Qform is A’. The transform matrix (TE_spm) my understand >>> is equal to A’*inv(A). >>> I can use this matrix (TE_spm) to reorient the Image to the MNI space >>> using the function Batch-> SPM-> Util -> reorient images >>> >>> When I use “flirt” in FSL toolbox, the output image is also aligned to >>> MNI space. However, the output matrix (xfm) is way different with the >>> TE_spm I generate. >>> And it doesn’t work with the “reorient images” function in SPM. Further, >>> as the function “flirt” will reslice (resample) the image by default, the >>> Qform of A’ generated by flirt is re-set to the centre of the image matrix. >>> >>> My question is how to apply the xfm to reorient the input image A to MNI >>> space? Also, is it possible to convert the xfm in FSL to the matrix that >>> can be used in reorient image function? >>> I have attached the matrix below, for more information. >>> >>> >>> A=[ -0.9992 -0.0244 0.0314 97.7589 >>> -0.0244 0.9997 0.0008 -133.7938 >>> 0.0314 -0.0000 0.9995 -149.3965 >>> 0 0 0 1.0000] >>> >>> A’=[ -0.9995 -0.0092 0.0317 93.3496 >>> 0.0067 0.8845 0.4665 -176.7222 >>> 0.0323 -0.4665 0.8839 -58.0182 >>> 0 0 0 1.0000] >>> >>> TE_spm= [ 0.9999 0.0152 0.0003 -2.3183 >>> -0.0136 0.8844 0.4665 12.6318 >>> 0.0069 -0.4665 0.8845 11.0441 >>> 0 0 0 1.0000 ] >>> >>> Xfm = [1.015110314 0.001403876797 -0.03273563415 -2.95397524 >>> -0.0340642576 0.881267329 0.4458567806 -42.9856035 >>> 0.03133599993 -0.4915636726 0.9529941246 7.78935539 >>> 0 0 0 1 ] >>> >>> >>> Thanks, >>> >>> Chao >> >> >> >> >> -- >> Prof John Ashburner >> Professor of Imaging Science >> UCL Institute of Neurology >> Queen Square >> Wellcome Trust Centre for Neuroimaging >> University College London >> <https://maps.google.com/?q=London+12+Queen+Square,+London,+WC1N+3BG&entry=gmail&source=g> >> 12 Queen Square, London, WC1N 3BG >> <https://maps.google.com/?q=London+12+Queen+Square,+London,+WC1N+3BG&entry=gmail&source=g> >> E: [log in to unmask] T: +44 (0)20 3448 4365 <+44%2020%203448%204365> >> http://www.fil.ion.ucl.ac.uk/ >> > > -- Prof John Ashburner Professor of Imaging Science UCL Institute of Neurology Queen Square Wellcome Trust Centre for Neuroimaging University College London 12 Queen Square, London, WC1N 3BG E: [log in to unmask] T: +44 (0)20 3448 4365 http://www.fil.ion.ucl.ac.uk/