Hi,

I am trying to convert my ROIs in standard space to native space because I need to fit my GLM to pre-processed functional images in native space for subsequent Representational Similarity Analysis. Given that I used DARTEL to normalise my images, I think that the function **y_WarpBackByDARTEL** is what I am looking for.

From what I understood there are three different steps: conversion frm MNI space to Template Space, which is performed by setting the voxel-to-world matrix of the ROI using spm_get_space through

M1*inv(M2)*M3 where M1 = is the voxel-to world mapping of Template_6.nii, M2 is the affine transformation in "Template_6_2_mni.nii", and M3 is the voxel-to world mapping of my ROI.

The second step requires to warp the ROI from Template 6 to the original T1 space using the deformation utility and the previously saved flowfield, e.g., "u_.nii".

The third step entials to reslice the ROI in structural space to functional space. I have seen that the function in the toolbox follows these steps here after reading the reference functional image, e.g., the median/mean.

[SourceData SourceHead]=y_Read(InputFile);

[x1,x2,x3] = ndgrid(1:dim(1),1:dim(2),1:dim(3));

d = [hld*[1 1 1]' [1 1 0]'];

C = spm_bsplinc(SourceHead, d);

v = zeros(dim);

M = inv(SourceHead.mat)*mat; % M = inv(mat\SourceHead.mat) in spm_reslice.m

y1 = M(1,1)*x1+M(1,2)*x2+(M(1,3)*x3+M(1,4));

y2 = M(2,1)*x1+M(2,2)*x2+(M(2,3)*x3+M(2,4));

y3 = M(3,1)*x1+M(3,2)*x2+(M(3,3)*x3+M(3,4));

OutVolume = spm_bsplins(C, y1,y2,y3, d);

tiny = 5e-2; % From spm_vol_utils.c

Mask = true(size(y1));

Mask = Mask & (y1 >= (1-tiny) & y1 <= (SourceHead.dim(1)+tiny));

Mask = Mask & (y2 >= (1-tiny) & y2 <= (SourceHead.dim(2)+tiny));

Mask = Mask & (y3 >= (1-tiny) & y3 <= (SourceHead.dim(3)+tiny));

OutVolume(~Mask) = 0;

OutHead=SourceHead;

OutHead.mat = mat;

OutHead.dim(1:3) = dim;

Can anyone tell me what is happening theoretically in the parts that are highlighted in yellow as it is not clear to me?

Thank you very much

best wishes

Loris Naspi

YAN Chao-Gan

Wed, 11/20/2019 - 02:59

Permalink

## This part comes from spm

This part comes from spm_reslice.m. If you are intersted in, you can refer to spm's manual and maillist.