MATLABcodeforreadigadwritigCIFTIfiles,v2
ThislibraryiscompatiblewiththeCIFTI-2format,withoutexterallyistalleddepedecies(exceptthatCIFTI-1filesrequirewb_commadforcoversio),returigastructurethatexposestheiformatiocotaieditheCIFTI-2XMLwithmiimaltraslatio,aswellasthedatamatrixwithoaddedpaddig.Thecifti_readfuctioistheitededstartigpoit,ciftiopeadsimilararecompatibilitywrapperssothatthelibrarycabeusedioldercode.
Additioally,thelibraryprovidesumeroushelperfuctiostomakemaycommooperatios(suchasextractigthedataforoestructure)itoasiglelieofituitivecode.
ThepreviouscodethatwasderivedfromFieldTripisithe"ft_cifti"folder.
Theciftistructurereturedbythislibraryuses0-basedidicesforvertexadvoxelidices,1-basedforciftiidices,adthehelperfuctiosretur1-basedidicesforeverythig.
UsageAllexposedfuctioshaveusageiformatioavailablethroughthehelpcommad:
>>helpcifti_readfuctiooutstruct=cifti_read(fileame,...)Readaciftifile....Thesimplestpracticalusageistoloadaciftifilewithcifti_read,takeitsdatafromthe.cdatafield,modifyit,storeitbackitothe.cdatafield,adwriteitbackouttoaewfilewithcifti_write:
mycifti=cifti_read('somethig.dscalar.ii');mycifti.cdata=sqrt(mycifti.cdata);cifti_write(mycifti,'sqrt.dscalar.ii');Theciftiope,ciftisave,adciftisaveresetfuctiosprovidebackwardcompatibilitywithapreviousciftilibrary(optioIIofHCPFAQ2),adyoucaalsousethisciftisaveresetfuctioeveifyouusecifti_read.Aalterativewaytodotheequivaletofciftisaveresetistousethecifti_write_from_templatehelperfuctio(whichalsohasoptiostosettheamesofthemapsfordscalar,adsimilarforotherciftifiletypes):
mycifti=cifti_read('somethig.dscalar.ii');cifti_write_from_template(mycifti,mycifti.cdata(:,1),'firstmap.dscalar.ii','amelist',{'map#1'});%ciftisaveresetequivalet(keepig'mycifti'umodified):mycifti=cifti_read('somethig.dscalar.ii');ewcifti=mycifti;ewcifti.cdata=mycifti.cdata(:,1);ciftisavereset(ewcifti,'firstmap.dscalar.ii');clearewcifti;Thecifti_struct_create_from_templatefuctiocacreateaciftistructwithoutwritigittoafile,withthesameoptiosascifti_write_from_templatetocotroltheotherdimifo.Thecifti_write...orcifti_struct...fuctiosshouldhadlemostcasesofworkigwithcommociftifiles,icludigextractigthedataforoecorticalsurface,doigsomecomputatiooit,adreplacigthesurfacedatawiththeewvalues:
mycifti=cifti_read('somethig.dscalar.ii');leftdata=cifti_struct_dese_extract_surface_data(mycifti,'CORTEX_LEFT');ewleftdata=1-leftdata;ewcifti=cifti_struct_dese_replace_surface_data(mycifti,ewleftdata,'CORTEX_LEFT');...Thedesepartofsomefuctioamesreferstoolybeigapplicableto"dese"filesordimifo(iciftixmlterms,a"braimodels"mappig),suchasdtseries,dscalar,dlabel,ordco.Therearemoredesehelpersmailybecausethereisamorecommoeedtomakeuseoftheiformatioiadesedimifothamostotherdimifotypes.
Thecifti_dimifo_*helpersarelower-leveladrequiremoreuderstadigofthedetailsoftheciftiformat,adofterequirewritigmorecodetousethem,soyoushouldgeerallylookatthecifti_write...adcifti_struct...fuctiosfirst.
FuctiorefereceMaifuctiosread/writeadcompatibilityoutstruct=cifti_read(fileame,...)cifti_write(cifti,fileame,...)cifti=ciftiope(fileame,...)%ote:these3dootuseoptiopairs,ciftisave(cifti,fileame,...)%thevarargihereistomakepassig'wb_commad'optioalciftisavereset(cifti,fileame,...)structcreatehelpersadwritecoveiecefuctioscifti=cifti_struct_create_from_template(ciftitemplate,data,type,...)cifti_write_from_template(ciftitemplate,data,fileame,...)cifti=cifti_struct_create_sdseries(data,...)cifti_write_sdseries(data,fileame,...)desestructextract/replacehelpers[outdata,outroi]=cifti_struct_dese_extract_surface_data(cifti,structure[,dimesio])cifti=cifti_struct_dese_replace_surface_data(cifti,data,structure[,dimesio])[outdata,outsform1,outroi]=cifti_struct_dese_extract_volume_all_data(cifti[,cropped,dimesio])cifti=cifti_struct_dese_replace_volume_all_data(cifti,data[,cropped,dimesio])[outdata,outsform1,outroi]=cifti_struct_dese_extract_volume_structure_data(cifti,structure[,cropped,dimesio])cifti=cifti_struct_dese_replace_volume_structure_data(cifti,data,structure[,cropped,dimesio])misc[surflist,vollist]=cifti_dimifo_dese_get_structures(dimifo)%returstheamesofstructuresthatexistithisdimifooutstrig=cifti_metadata_get(metadata,key)%retursemptystrigforoexistetkeymetadata=cifti_metadata_remove(metadata,key)%retursumodifiedmetadatastructforoexistetkeymetadata=cifti_metadata_set(metadata,key,value)%overwriteskeyifitexistsSpecialusageadvaceddimifohelpersoutifo=cifti_dimifo_dese_get_surface_ifo(dimifo,structure)outifo=cifti_dimifo_dese_get_volume_all_ifo(dimifo[,cropped])outifo=cifti_dimifo_dese_get_volume_structure_ifo(dimifo,structure[,cropped])outmap=cifti_dimifo_make_scalars(ummaps[,amelist,metadatalist])outmap=cifti_dimifo_make_series(ummaps[,start,step,uit])advacedmiscidices=cifti_vox2id(dims,voxlist1)%helpertoactlikesub2idforvoxelijklists
评论