Washington-University / cifti-matlab

MATLAB code for reading and writing CIFTI connectivity files
Other
65 stars 19 forks source link

Saving GIFTI overlay file #10

Closed isacdaavid closed 1 month ago

isacdaavid commented 1 month ago

Hi,

I can successfully read gifti files using

outfile = gifti(PATH);

>> outfile
outfile =
   struct with fields:
        cdata: [32492x1]

However I need to write another gifti to disk after some processing. I have even tried saving the same file back:

save(outfile, NEW_PATH);

This creates a file with the wrong geometry. If I try to overlay the new gifti on the same surface using Freesurfer's freeview I get the following error:

Number of vertices in overlay data (1 or 1) does not match with surface (32492).

How can I properly save giftis?

coalsont commented 1 month ago

Check whether the matrix needs to be transposed. Also, try using it in wb_view instead of freeview, and see if it works there.

Note, this repository is for cifti files, and does not support gifti files. The gifti matlab toolbox you are probably using is here:

https://github.com/gllmflndn/gifti

isacdaavid commented 1 month ago

I am in fact using these files in your repository, which I now figure you probably imported from that other project.

Transposing didn't help. In fact, reading and saving the same file unmodified is enough to corrupt it. This is also evident if I try to load it back in matlab:

gifti(PATH);

Error using read_gifti_file_standalone
[GIFTI] Loading of XML file myfile.gii failed.Error in gifti (line 71)
                this = read_gifti_file_standalone(varargin{1},giftistruct);
coalsont commented 1 month ago

Ah. The ft_cifti directory is for legacy purposes, it is not recommended to use it, and I don't plan to update it - basically it seemed unfriendly to just delete the previous code from the repository when I released the v2 library. That copy of the gifti toolbox was probably only used for loading .surf.gii files (which the old library tried to guess filenames for and load without asking, while the new library is much more "only the file you asked for, without modifications"). Please use the current version of the gifti toolbox for loading gifti files instead.