ThislibraryiscompatiblewiththeCIFTI-2format,withoutexternallyinstalleddependencies(exceptthatCIFTI-1filesrequirewb_commandforconversion),returningastructurethatexposestheinformationcontainedintheCIFTI-2XMLwithminimaltranslation,aswellasthedatamatrixwithnoaddedpadding.Thecifti_readfunctionistheintendedstartingpoint,ciftiopenandsimilararecompatibilitywrapperssothatthelibrarycanbeusedinoldercode.
Additionally,thelibraryprovidesnumeroushelperfunctionstomakemanycommonoperations(suchasextractingthedataforonestructure)intoasinglelineofintuitivecode.
ThepreviouscodethatwasderivedfromFieldTripisinthe"ft_cifti"folder.
Theciftistructurereturnedbythislibraryuses0-basedindicesforvertexandvoxelindices,1-basedforciftiindices,andthehelperfunctionsreturn1-basedindicesforeverything.
UsageAllexposedfunctionshaveusageinformationavailablethroughthehelpcommand:
>>helpcifti_readfunctionoutstruct=cifti_read(filename,...)Readaciftifile....Thesimplestpracticalusageistoloadaciftifilewithcifti_read,takeitsdatafromthe.cdatafield,modifyit,storeitbackintothe.cdatafield,andwriteitbackouttoanewfilewithcifti_write:
mycifti=cifti_read('something.dscalar.nii');mycifti.cdata=sqrt(mycifti.cdata);cifti_write(mycifti,'sqrt.dscalar.nii');Theciftiopen,ciftisave,andciftisaveresetfunctionsprovidebackwardcompatibilitywithapreviousciftilibrary(optionIIofHCPFAQ2),andyoucanalsousethisciftisaveresetfunctionevenifyouusecifti_read.Analternativewaytodotheequivalentofciftisaveresetistousethecifti_write_from_templatehelperfunction(whichalsohasoptionstosetthenamesofthemapsfordscalar,andsimilarforotherciftifiletypes):
mycifti=cifti_read('something.dscalar.nii');cifti_write_from_template(mycifti,mycifti.cdata(:,1),'firstmap.dscalar.nii','namelist',{'map#1'});%ciftisaveresetequivalent(keeping'mycifti'unmodified):mycifti=cifti_read('something.dscalar.nii');newcifti=mycifti;newcifti.cdata=mycifti.cdata(:,1);ciftisavereset(newcifti,'firstmap.dscalar.nii');clearnewcifti;Thecifti_struct_create_from_templatefunctioncancreateaciftistructwithoutwritingittoafile,withthesameoptionsascifti_write_from_templatetocontroltheotherdiminfo.Thecifti_write...orcifti_struct...functionsshouldhandlemostcasesofworkingwithcommonciftifiles,includingextractingthedataforonecorticalsurface,doingsomecomputationonit,andreplacingthesurfacedatawiththenewvalues:
mycifti=cifti_read('something.dscalar.nii');leftdata=cifti_struct_dense_extract_surface_data(mycifti,'CORTEX_LEFT');newleftdata=1-leftdata;newcifti=cifti_struct_dense_replace_surface_data(mycifti,newleftdata,'CORTEX_LEFT');...Thedensepartofsomefunctionnamesreferstoonlybeingapplicableto"dense"filesordiminfo(inciftixmlterms,a"brainmodels"mapping),suchasdtseries,dscalar,dlabel,ordconn.Therearemoredensehelpersmainlybecausethereisamorecommonneedtomakeuseoftheinformationinadensediminfothanmostotherdiminfotypes.
Thecifti_diminfo_*helpersarelower-levelandrequiremoreunderstandingofthedetailsoftheciftiformat,andoftenrequirewritingmorecodetousethem,soyoushouldgenerallylookatthecifti_write...andcifti_struct...functionsfirst.
FunctionreferenceMainfunctionsread/writeandcompatibilityoutstruct=cifti_read(filename,...)cifti_write(cifti,filename,...)cifti=ciftiopen(filename,...)%note:these3donotuseoptionpairs,ciftisave(cifti,filename,...)%thevararginhereistomakepassing'wb_command'optionalciftisavereset(cifti,filename,...)structcreatehelpersandwriteconveniencefunctionscifti=cifti_struct_create_from_template(ciftitemplate,data,type,...)cifti_write_from_template(ciftitemplate,data,filename,...)cifti=cifti_struct_create_sdseries(data,...)cifti_write_sdseries(data,filename,...)densestructextract/replacehelpers[outdata,outroi]=cifti_struct_dense_extract_surface_data(cifti,structure[,dimension])cifti=cifti_struct_dense_replace_surface_data(cifti,data,structure[,dimension])[outdata,outsform1,outroi]=cifti_struct_dense_extract_volume_all_data(cifti[,cropped,dimension])cifti=cifti_struct_dense_replace_volume_all_data(cifti,data[,cropped,dimension])[outdata,outsform1,outroi]=cifti_struct_dense_extract_volume_structure_data(cifti,structure[,cropped,dimension])cifti=cifti_struct_dense_replace_volume_structure_data(cifti,data,structure[,cropped,dimension])misc[surflist,vollist]=cifti_diminfo_dense_get_structures(diminfo)%returnsthenamesofstructuresthatexistinthisdiminfooutstring=cifti_metadata_get(metadata,key)%returnsemptystringfornonexistentkeymetadata=cifti_metadata_remove(metadata,key)%returnsunmodifiedmetadatastructfornonexistentkeymetadata=cifti_metadata_set(metadata,key,value)%overwriteskeyifitexistsSpecialusageadvanceddiminfohelpersoutinfo=cifti_diminfo_dense_get_surface_info(diminfo,structure)outinfo=cifti_diminfo_dense_get_volume_all_info(diminfo[,cropped])outinfo=cifti_diminfo_dense_get_volume_structure_info(diminfo,structure[,cropped])outmap=cifti_diminfo_make_scalars(nummaps[,namelist,metadatalist])outmap=cifti_diminfo_make_series(nummaps[,start,step,unit])advancedmiscindices=cifti_vox2ind(dims,voxlist1)%helpertoactlikesub2indforvoxelijklists
评论