dlabel.nii

225 views
Skip to first unread message

Sara Silva

unread,
Mar 20, 2024, 7:53:54 PM3/20/24
to HCP-Users

Hello! I think this may be a bit of a reach but I am having an issue with the {subject}.aparc.32k_fs_LR.dlabel.nii files from HCP, I've looked all over the internet and found nothing. To extract the ROI mapping, this is essentially what I've done:

def load_atlas_aux(path2atlas):

try: cifti_file = nib.load(path2atlas) except Exception as e: print("Error loading CIFTI file:", e) return None data = cifti_file.get_fdata() segmentation_atlas = data.ravel() return segmentation_atlas

It works well, but it does not provide the same resaults I obtained from my matlab base file, which does something different by accessing a particular mapping like this:

subjlab = ft_read_cifti(path2atlas);
load_atlas_cmd = strcat('subjlab.x',subject,'_aparc');
segmentation_atlas = eval(load_atlas_cmd);

The problem is that cifti in matlab obviously doesn't have the same implementation as nibabel library so I don't know how to access that specific "attribute" of the atlas with this library. Maybe someone has faced something similar before or has any guidance for me, thank you!!

Tim Coalson

unread,
Mar 20, 2024, 7:59:41 PM3/20/24
to hcp-...@humanconnectome.org
ft_read_cifti is the older version derived from the fieldtrip toolbox.  We recommend moving to cifti-matlab v2 (same repo, newer release) and using the cifti_read, etc functions, which give you the contents of the file the same way it exists on disk, which is probably closer to what nibabel gives you:


I would suggest slicing the numpy array to get the desired map from, for instance, the first column, rather than flattening the whole array.  That way, your code will still work with a dlabel file that contains multiple different label maps.

Tim


--
You received this message because you are subscribed to the Google Groups "HCP-Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to hcp-users+...@humanconnectome.org.
To view this discussion on the web visit https://groups.google.com/a/humanconnectome.org/d/msgid/hcp-users/2eb1a020-0548-4020-87ab-5803dd217f60n%40humanconnectome.org.

Sara Silva

unread,
Mar 21, 2024, 12:49:00 PM3/21/24
to HCP-Users, tim.c...@gmail.com
Hi Tim, thanks for your reply, I did as you suggested and kept the first map. However, I don't get if I should be getting the same segmentation atlas from both codes. The problem at core is that I'm extracting different timeseries from the matlab version of my script and the python one, and this is the only thing that I interpret could be different between them. I'll check out the nre cifti-matlab but my whole purpose it being able to move fully to python as right now I have a mixture of languages in my scripts.

Tim Coalson

unread,
Mar 21, 2024, 5:15:47 PM3/21/24
to Sara Silva, HCP-Users
ft_read_cifti will often give a larger matrix than actually exists on disk, because it adds the excluded medial wall vertices back to the array.  If you want to emulate this in python, you will need to use the list of included vertices that is somewhere in the header-ish information of the cifti file object.  Generally, we don't do this except for one hemisphere at a time, internally in our code.

There is no such concept of an "attribute" in a cifti file, ft_read_cifti is representing the data as a field in a matlab struct (with, apparently and unfortunately, a hard to predict field name) for its own reasons, cifti-matlab v2 doesn't do that (the data is always in .cdata, and it is always the whole matrix as-is).  In a cifti file, there is only one matrix that contains data, and it contains all of the data that cifti file has.  The dimension interpretation information (what vertices are included, what the volume dims and sform are, label tables, map names, etc) is in the XML header extension, and doesn't have the semantic idea of "attribute" - the primary goal of the XML is to describe each index of the data array.

This format explanation might be helpful:


Tim

Reply all
Reply to author
Forward
0 new messages