This post describes a method using matlab and creating GIfTI files; see the next post for a method using R, wb_command functions, and creating a CIFTI file. Both methods work, but one or the other might be more convenient in particular situations.
I assume that you have a surface version of the parcellation to use as a template. For example, the MMP parcellation was released in CIFTI format as part of the HCP 1200 release, and the Gordon (2014) parcellation can be downloaded here.
I'll be using the MMP in this example; if you want to follow along, download a copy of the S1200 Group Average Data Release; I put mine at d:/Workbench/HCP_S1200_GroupAvg_v1/. The MMP template is named Q1-Q6_RelatedValidation210.CorticalAreas_dil_Final_Final_Areas_Group_Colors.32k_fs_LR.dlabel.nii. (If you're not sure how to use the files in the S1200 release, try this tutorial to get started.)
I have the values to assign to the parcels in a text file with 180 lines (one line for each MMP parcel). For this tutorial, let's do the simple example of assigning a color to parcels 1, 10, and 15 only. An easy way to do this is to make a text file with 1s on these rows and 0s on all the other rows. I prefer R, but since the GIfTI library is in matlab, here's matlab code for making the little text file:
out = repelem(0, 180); out(1) = 1; out(10) = 1; out(15) = 1; csvwrite('D:\temp\parcelNums.csv', out')
The MMP template is in CIFTI format, but we can extract GIfTI files for each hemisphere using wb_command cifti-separate:
wb_command -cifti-separate D:\Workbench\HCP_S1200_GroupAvg_v1\Q1-Q6_RelatedValidation210.CorticalAreas_dil_Final_Final_Areas_Group_Colors.32k_fs_LR.dlabel.nii COLUMN -metric CORTEX_LEFT D:\temp\mmpL.func.gii wb_command -cifti-separate D:\Workbench\HCP_S1200_GroupAvg_v1\Q1-Q6_RelatedValidation210.CorticalAreas_dil_Final_Final_Areas_Group_Colors.32k_fs_LR.dlabel.nii COLUMN -metric CORTEX_RIGHT D:\temp\mmpR.func.gii
This matlab code reads in the text file with the new parcel values and the GIfTI templates, then writes GIfTI files with the new parcel values substituted for the parcel label numbers:
addpath 'C:/Program Files/MATLAB/gifti-1.6'; % so matlab can find the library mmpL = gifti('D:\temp\mmpL.func.gii'); % load the left side gifti MMP atlas mmpR = gifti('D:\temp\mmpR.func.gii'); % and the right side MMP atlas newvals = csvread('D:\temp\parcelNums.csv'); % 180 integers; new value for each parcel Lout = mmpL; % output gifti Lout.cdata(:,1) = repelem(0, size(mmpL.cdata,1)); % replace the values with zeros Rout = mmpR; Rout.cdata(:,1) = repelem(0, size(mmpR.cdata,1)); for i=1:180 % i = 1; inds = find(mmpR.cdata == i); % find vertices for parcel i Rout.cdata(inds,1) = newvals(i); % put the new value in for this parcel's vertices inds = find(mmpL.cdata == (i+180)); % in MMP, left hemisphere vertices are 181:360 Lout.cdata(inds,1) = newvals(i); end save(Lout,'D:\temp\plotL.func.gii','Base64Binary'); % save the gifti save(Rout,'D:\temp\plotR.func.gii','Base64Binary');
You can now to plot these GIfTIs in Workbench (see this post if you're not sure how); I plotted them on the S1200 Group Average (MNI) anatomy:
UPDATE 9 November 2018: I added making this same gifti on the fly and plotting in a knitr to my gifti plotting demo.