import gii generated by brainvisa on matlab

Questions about BrainVisa usage and installation

Moderators: denghien, riviere

Post Reply
pdeman
Posts: 39
Joined: Thu Sep 17, 2015 4:09 pm
Location: moving sometimes

import gii generated by brainvisa on matlab

Post by pdeman »

Hello,

I am trying to import the gii files generated by brainvisa (like the head.gii, Lhemi.gii and Lwhite.gii for example).
I am trying with the gifti toolbox on matlab (http://www.artefact.tk/software/matlab/gifti/) which is provided by spm (on the link they are talking about brainvisa but they have .surf.gii which I don't. is that normal ?).

but it doesn't work.
apparently it's missing some fields.

for example it's trying to attempt "this.data{j}.space.MatrixData;" which doesn't exist, the space field is empty.
" this.data{1}
ans =
attributes: [1x1 struct]
data: [31344x3 single]
metadata: [0x0 struct]
space: []
K>> this.data{2}
ans =
attributes: [1x1 struct]
data: [62684x3 int32]
metadata: [0x0 struct]
space: []"

Did you already try to open these gii on matlab ?

Regards,
Pierre
User avatar
riviere
Site Admin
Posts: 1361
Joined: Tue Jan 06, 2004 12:21 pm
Location: CEA NeuroSpin, Saint Aubin, France
Contact:

Re: import gii generated by brainvisa on matlab

Post by riviere »

Hi,
No we have never used GIFTI with Matlab...
Well I guess that the Matlab Gifti reader expects a transformation matrix which is not in the file. Actually I don't know if such transforms are mandatory in GIFTI format. Our files seem to pass the Gifti DTD test, but I have not looked further...
Denis
pdeman
Posts: 39
Joined: Thu Sep 17, 2015 4:09 pm
Location: moving sometimes

Re: import gii generated by brainvisa on matlab

Post by pdeman »

what is the gifti dtd test ? what dtd is for ?
Pierre
User avatar
riviere
Site Admin
Posts: 1361
Joined: Tue Jan 06, 2004 12:21 pm
Location: CEA NeuroSpin, Saint Aubin, France
Contact:

Re: import gii generated by brainvisa on matlab

Post by riviere »

In short, GIFTI is a XML format. XML is a tree structure format, each element in the tree has mandatory and optional children, and cannot have alien children. The DTD specifies this structure and allows to check it. So it should normally detect files with missing mandatory elements. But I haven't read the spec for a while and I'm not 100% sure we follow it completely.
Denis
pdeman
Posts: 39
Joined: Thu Sep 17, 2015 4:09 pm
Location: moving sometimes

Re: import gii generated by brainvisa on matlab

Post by pdeman »

it seems that the gii generated by brainvisa miss the transformation matrix to be compatible with the matlab toolbox.
when saving a gii using the gifti toolbox on matlab it's generated these fields which I don't have via BrainVisa.

Code: Select all

% CoordinateSystemTransformMatrix
%----------------------------------------------------------------------
for j=1:length(this.data{i}.space)
       fprintf(fid,'%s<CoordinateSystemTransformMatrix>\n',o(2));
       fprintf(fid,'%s<DataSpace><![CDATA[%s]]></DataSpace>\n',o(3),...
          this.data{i}.space(j).DataSpace);
       fprintf(fid,'%s<TransformedSpace><![CDATA[%s]]></TransformedSpace>\n',o(3),...
          this.data{i}.space(j).TransformedSpace);
       fprintf(fid,'%s<MatrixData>%s</MatrixData>\n',o(3),...
          sprintf('%f ',this.data{i}.space(j).MatrixData'));
       fprintf(fid,'%s</CoordinateSystemTransformMatrix>\n',o(2));
 end
maybe it should be the scanner based transformation here.
(it's looking for a 4x4 matrix).
User avatar
riviere
Site Admin
Posts: 1361
Joined: Tue Jan 06, 2004 12:21 pm
Location: CEA NeuroSpin, Saint Aubin, France
Contact:

Re: import gii generated by brainvisa on matlab

Post by riviere »

Yes, that's more or less what I was trying to say :)
The question is: is this matrix mandatory ? I haven't re-read the specs of the GIFTI format, the answer is probably there. The fact is that this DTD test, which should point out missing mandatory fields, did not complain (on a few examples, but which do not have this matrix). which made me think the matrix is not mandatory, but maybe this is wrong.
Denis
pdeman
Posts: 39
Joined: Thu Sep 17, 2015 4:09 pm
Location: moving sometimes

Re: import gii generated by brainvisa on matlab

Post by pdeman »

I don't know if it's required. the most recent document that I found describing the gifti format is from 2011.
it's said: "At leas one Corrdinate System Transform Matrix is required". but it seems that it's not always in space.MatrixData. it seems that there is lot of possibility to store it ... which is not really convenient ...

apparently people using freesurfer have the same problem. the transformation matrix is not stored, or at least is not stored in space.MatrixData and can't be open correctly on matlab. and even on freesurfer when they open two gii saved using freesurfer, it lost the coregistration, stuff like that.

on brainvisa it works due to the .minf right ? without it the referential would not be found correctly.
User avatar
riviere
Site Admin
Posts: 1361
Joined: Tue Jan 06, 2004 12:21 pm
Location: CEA NeuroSpin, Saint Aubin, France
Contact:

Re: import gii generated by brainvisa on matlab

Post by riviere »

If it's required we can probably add it but I'm not completely sure of that. And anyway it will be released in brainvisa in a while...
In the meantime, is it possible to disable the test in the matlab lib ? (and probably use an identity matrix)

In Brainvisa, yes, the .minf and referential information allow to identify that a mesh is in the same coordinates space than other objects (the T1 MRI typically), which has transforms to other spaces etc. so we are not relying on format-specific information (at least not only on it). This has advantages and drawbacks.

Denis
pdeman
Posts: 39
Joined: Thu Sep 17, 2015 4:09 pm
Location: moving sometimes

Re: import gii generated by brainvisa on matlab

Post by pdeman »

I won't put the identity matrix otherwise I will have the same problem than other users on freesurfer, my positions measured on the T1 by brainvisa will be wrong on the gii. So I will change the code in matlab to look at the transfo in the .minf as brainvisa does for now.
User avatar
riviere
Site Admin
Posts: 1361
Joined: Tue Jan 06, 2004 12:21 pm
Location: CEA NeuroSpin, Saint Aubin, France
Contact:

Re: import gii generated by brainvisa on matlab

Post by riviere »

Well, transformations are not necessarily in .minf, they are more generally stored outside of data files, in .trm files (*). BrainVisa can retreive transformation paths using its database.

(*) this is done to avoid duplication of transformation information in several data which share the same coords system, which generally cause inconsistencies, and to avoid the need of re-writing data when their registration information change (which also is generally not done on all data, and thus produces inconsistencies).

Denis
Post Reply