Hi Jeffey,

regarding:

" So only two of the transforms in the transform.vox_filename = '<subjID>_MEG_anatomy_anatomical.txt' are needed by BS. I just have to figure out how to create them for my non-MEG data. "

The transformation matrix that goes into field

transform.vox07mm2spm

can be read from the processed MRI anatomical file , i.e. '175237_MEG_anatomy_anatomical.nii'
by using the function ft_read_mri from fieldtrip toolbox.

As you don't have any MEG coordinate system and only the MRI coordinate system then there is no transformation from "spm" to "bti". They are the same coordinate system in your case. In the example from BS they used the transform.txt file from a subject with MEG. In this case there was a different MEG coordinate system that is why the two transformation matrices were not identical.

the simplest way to create your own transform.txt file is by using the function hcp_write_ascii from the MEG pipeline code that you can download in ConnectomeDB("megconnectome").

transform =[];

transform.vox07mm2spm = [

-0.7 0 0 90.7

0 0.7 0 -126.7

0 0 0.7 -72.7

0 0 0 1

]; % This is the transformation matrix you read with ft_read_mri from the processed MRI file


transform.vox07mm2bti =vox07mm2spm;

transformfile=<subj>_MEG_anatomy_transform.txt
hcp_write_ascii (transformfile,'transform');


Best
Giorgos



On 2/14/2017 12:41 AM, K Jeffrey Eriksen wrote:

Georgos,

Understood about the naming.

Next question: I have found the Brainstorm code that reads the transform file:

%% ===== MRI=>MNI TRANSFORMATION =====

% Convert transformations from "Brainstorm MRI" to "FieldTrip voxel"

Tbst2ft = [diag([-1, 1, 1] ./ sMri.Voxsize), [size(sMri.Cube,1); 0; 0]; 0 0 0 1];

% Set the MNI=>SCS transformation in the MRI

Tmni = transform.vox07mm2spm * Tbst2ft;

sMri.NCS.R = Tmni(1:3,1:3);

sMri.NCS.T = Tmni(1:3,4);

% MNI coordinates for the AC/PC/IH fiducials

AC = [0, 3,  -4] ./ 1000;

PC = [0, -25,  -2] ./ 1000;

IH = [0, -10,  60] ./ 1000;

Origin = [0, 0, 0];

% Convert: MNI (meters) => MRI (millimeters)

sMri.NCS.AC = cs_convert(sMri, 'mni', 'mri', AC) .* 1000;

sMri.NCS.PC = cs_convert(sMri, 'mni', 'mri', PC) .* 1000;

sMri.NCS.IH = cs_convert(sMri, 'mni', 'mri', IH) .* 1000;

sMri.NCS.Origin = cs_convert(sMri, 'mni', 'mri', Origin) .* 1000;

%% ===== MRI=>SCS TRANSFORMATION =====

% Set the MRI=>SCS transformation in the MRI

Tscs = transform.vox07mm2bti * Tbst2ft;

sMri.SCS.R = Tscs(1:3,1:3);

sMri.SCS.T = Tscs(1:3,4);

% Standard positions for the SCS fiducials

NAS = [90, 0, 0] ./ 1000;

LPA = [ 0, 75, 0] ./ 1000;

RPA = [ 0, -75, 0] ./ 1000;

Origin = [0, 0, 0];

% Convert: SCS (meters) => MRI (millimeters)

sMri.SCS.NAS = cs_convert(sMri, 'scs', 'mri', NAS) .* 1000;

sMri.SCS.LPA = cs_convert(sMri, 'scs', 'mri', LPA) .* 1000;

sMri.SCS.RPA = cs_convert(sMri, 'scs', 'mri', RPA) .* 1000;

sMri.SCS.Origin = cs_convert(sMri, 'scs', 'mri', Origin) .* 1000;

% Save MRI structure (with fiducials)

bst_save(BstMriFile, sMri, 'v7');

and here is the relevant contents of the transform file I got with the HCP-MEG example recommended by BS:

transform.vox07mm_filename = 'T1w_acpc_dc_restore.nii.gz';

transform.vox_filename = '175237_MEG_anatomy_anatomical.nii';

transform.vox07mm2spm = [

-0.7 0 0 90.7

0 0.7 0 -126.7

0 0 0.7 -72.7

0 0 0 1

];

transform.vox07mm2bti = [

0.0242485 0.689697 -0.143363 -99.3102

0.702637 -0.0220904 0.00540799 -88.0016

-5.54434e-05 0.143686 0.684532 -77.7522

0 0 0 1

];

So only two of the transforms in the transform.vox_filename = '<subjID>_MEG_anatomy_anatomical.txt' are needed by BS. I just have to figure out how to create them for my non-MEG data. One disconnect I am having is that below (from your earlier email) you say these two are identical, but BS obviously does not think so as they are obviously different in the above snippet:

>>transform.vox07mm2spm = vox07mm2spm; %This is the transformation matrix from voxel to "spm" coordinates mentioned earlier retrieved from the 0.7mm structural MRI.

>>transform.vox07mm2bti = transform.vox07mm2spm ; % As spm and bti are identical coordinate system this is just the transformation from voxels to "spm" coordinates already created;

I do not process MRI data myself, concentrating on the EEG analysis) so do not know how to setup and run the HCP pipeline or the special HCP_MEG pipeline. I did try searching all the HCP_MEG pipeline M-files and found no occurrence of the transforms above, so they must be embedded in the shell scripts or compiled C code somewhere, presumably.

Can you comment on the above and perhaps point me in the right direction? One idea I have is to try to run the HCP-MEG pipeline minus the actual MEG portions. Another is to find out if the standard HCP pipeline produces the transforms I need.

Thanks,

-Jeff

*From:*Michalareas, Giorgos [mailto:giorgos.michalar...@esi-frankfurt.de]
*Sent:* Friday, February 10, 2017 4:50 PM
*To:* K Jeffrey Eriksen
*Subject:* RE: [HCP-Users] MEG_anatomy_transform.txt

I think this should not be a problem.

Just use the T1 you have but make sure the fields names of the "transform" structure remain the same as in the description I sent you because I am pretty confident that Brainstorm is expecting to find these exact filenames,

Give it a try snd let me know how it goes

Best

Giorgos

------------------------------------------------------------------------

*From:*K Jeffrey Eriksen [eriks...@ohsu.edu]
*Sent:* Saturday, February 11, 2017 1:02 AM
*To:* Michalareas, Giorgos
*Subject:* RE: [HCP-Users] MEG_anatomy_transform.txt

Georgios,

I have read through this now, and have one follow-up question. While we are using the HCP pipeline, our original T1s are 1.0 mm cubic voxels. Could you please comment on this, or possibly modify what you have written to accommodate this fact?

Thanks,

-Jeff

*From:*hcp-users-boun...@humanconnectome.org <mailto:hcp-users-boun...@humanconnectome.org> [mailto:hcp-users-boun...@humanconnectome.org] *On Behalf Of *Georgios Michalareas
*Sent:* Friday, February 10, 2017 3:05 PM
*To:* hcp-users@humanconnectome.org <mailto:hcp-users@humanconnectome.org>
*Subject:* Re: [HCP-Users] MEG_anatomy_transform.txt

Dear Jeff,

if I have understood correctly you want to import a structural MRI scan for a given HCP subject into Brainstorm for creating the EEG source model.

I guess you follow a procedure similar to

http://neuroimage.usc.edu/brainstorm/Tutorials/HCP-MEG

and Brainstorm cannot find the MEG/anatomy/*_MEG_anatomy_transform.txt file.

Although I am not sure whar Brainstorm reads exactly from the transform file , I can tell you what the transorm file contains. It contains a matlab structure with some fields, which I think you could easily create for subject that have no MEG data.


First a quick word on coordinate systems:

spm: This is the MNI coordinate system. This is the coordinate system that you 0.7 mm processed structural MRI is defined.

bti: This is the coordinate system of the MEG . Of course in your case where there was no MEG recorded , this will be the same as the "spm" coordinate system of the structural MRI. If for your EEG you have digitised the location of the EEG sensors relative to the fiducials then of course you ll need to figure out the transformation matrix between the structural MRI and you EEG reference system. But if this is not the case then your "bti" coordinate system should be the same as the "spm" coordinate system. In this case the identity transformation matrices between this coordinate systems would be

spm2bti= [
  1 0 0 0
  0 1 0 0
  0 0 1 0
  0 0 0 1
];

bti2spm= spm2bti;


vox: This is the voxel coordinate system of the structural MRI . The MRI file contains in itself the transformation matrix from voxels to actual coordinates in the "spm". To get this transformation matric in matlab you can use the fieldtrip function "ft_read_mri"

Let's assume you have done so and you have found that the transformation matrix from voxel to coordinates is

vox07mm2spm= [
 0.0296775 0.00303441 -0.996087 92.0035
 -0.965804 -0.245889 -0.0309473 159.445
 0.253714 -0.970409 0.00438009 90.3328
 0 0 0 1
];


Important remark: The HCP processed structural MRI has a resolution of 0.7mm. For the MEG processing we use a lower resolution version of the structural MRI . So in the description below whenever you see the notation "vox07" refers to the 0.7mm scan and just "vox" to the lower resolution one. In your case of course these should be the same as you only have the 0.7 mm one.


The structure matlab variable is called "transform". I have put the description of the fields in form of code , so potentially you could run it and create the structure for the transform file.

Its fields are:
*%==============================================================*

*transform.vox07mm_filename *= 'T1w_acpc_dc_restore.nii.gz'; % This is the name of the HCP processed stuctural MRI with 0.7mm resolution *transform.vox_filename* = transform.vox07mm_filename ; % This is supposed to be the lower resolution version used for MEG but here you assign it also to the 0.7mm *transform.vox07mm2spm* = vox07mm2spm; %This is the transformation matrix from voxel to "spm" coordinates mentioned earlier retrieved from the 0.7mm structural MRI. *transform.spm2vox07mm* = inv(transform.vox2spm); % This is the inverse transformation of the above from "spm" coordinates to voxels.

*transform.vox2spm *=transform.vox07mm2spm; %This is the transformation matrix from voxel to "spm" coordinates mentioned earlier . As you only have the 0.7mm structural here is the same also for the lower resolution case. *transform.spm2vox* = inv(transform.vox2spm); % This is the inverse transformation of the above from "spm" coordinates to voxels.

*transform.spm2bti* = spm2bti; % This is the transformation between spm and bti coordinate systems. In this case it is assumed they are the same so it the identity matrix created earlier.
*transform.bti2spm* =  bti2spm; %Same case here

*transform.vox07mm2bti* = transform.vox07mm2spm ; % As spm and bti are identical coordinate system this is just the transformation from voxels to "spm" coordinates already created; *transform.bti2vox07mm *= transform.spm2vox07mm; % The same is true for the inverse transformation. *transform.vox2bti* = transform.vox2spm; % Same for the lower resolution case used for MEG, which of course yo dont have, as yo uonly have the 0.7 mm so this is the same as for the 0.7mm case


*transform.bti2vox *= transform.spm2vox; % Same for the inverse transform of the lower resolution case


*transform.vox2bti_registered* = transform.vox2bti; % This is an intermediate transformation from voxel to bti used only for MEG purposed but for your case should be exactly the same as the voxel to bti transformation which of course is the same as the voxel to spm transformation as these coordinate systems are the same in your case.
*%==============================================================*


Once you have created the "transform" variable you have to write it in an ascii file, which is not as strightforward as writing a numberical array in an ascii in matlab. The easiest way is to download the MEG pipeline code from ConnectomeDB and use the function from the "analysis_functions" subfolder called
"hcp_write_ascii.m"

simply as
transformfile=<subj>_MEG_anatomy_transform.txt
hcp_write_ascii (transformfile,'transform');

and
I believe that should do it.

Give it a try and let me know if it worked or not .
It might be of interest to other users too.
Have a nice day
Best
Giorgos


On 2/10/2017 10:41 PM, K Jeffrey Eriksen wrote:

    Hi,

    I am trying to import HCP processed data into Brainstorm, a
    Matlab-based package for EEG/MEG source analysis, in order to
    build an EEG source model. I do not work with MEG.

    Unfortunately I am failing since I do not have the
    <subj>_MEG_anatomy_transform.txt file that is created during the
    HCP-MEG pipeline processing. Can someone help me figure out a way
    to create this transform for non-MEG HCP processed subjects? In
    our lab we use the WUSTL HCP pipeline with some local modifications.

    Thanks,

    -Jeff

    _______________________________________________
    HCP-Users mailing list
    HCP-Users@humanconnectome.org <mailto:HCP-Users@humanconnectome.org>
    http://lists.humanconnectome.org/mailman/listinfo/hcp-users

_______________________________________________
HCP-Users mailing list
HCP-Users@humanconnectome.org <mailto:HCP-Users@humanconnectome.org>
http://lists.humanconnectome.org/mailman/listinfo/hcp-users



_______________________________________________
HCP-Users mailing list
HCP-Users@humanconnectome.org
http://lists.humanconnectome.org/mailman/listinfo/hcp-users

Reply via email to