I need to import certain sub-BRIKs of the output from 3dDeconvolve into a Matlab toolbox. Is there a way to write the sub-BRIKs into .mat files? I saw this afni matlab library (https://sscc.nimh.nih.gov/afni/matlab/). Is that what I should be using? Just wanted to check since it’s an old page!
Mrinmayi, I have not actually used the afni_matlab toolbox. (Perhaps Gang Chen would know, if it is still current.)
BUT I can tell you that the latest version of Matlab has built-in support for NIFTI files: https://www.mathworks.com/help/images/ref/niftiread.html
Just use 3dAFNItoNIFTI to convert .BRIK to .nii and read that.
Just to add a bit to Hendrik’s useful comment:
- AFNI doesn’t actively support any matlab stuff anymore
- There used to be a brikload() function, that might still work.
- AFNI reads/writes NIFTI, as well as BRIK/HEAD files. Some programs can output NIFTI directly, depending on your “-prefix …” option or other explicit flags, but others will mainly output BRIK/HEAD, which can be converted.
- 3dAFNItoNIFTI is one way to convert, but you could also use 3copy, e.g.:
3dcopy DSET_BRIK DSET_NEW.nii.gz
3dcalc -a DSET_BRIK -expr 'a' -prefix DSET_NEW.nii.gz
… and you could use subbrick selectors in the latter, if that is useful.
- Note that AFNI programs will often make use of an “AFNI extension” in the header, whether in a BRIK/HEAD or NIFTI file. We use these to store helpful information-- like file history, labels, degree of freedom info, etc. Other software don’t propagate these, even if they are in a NIFTI file (which is fine, just their decision). It is possible/likely that the file you output from your Matlab processing will not have any of this useful information in it, just an FYI (that is, the history will not just be not added to, but it will probably not exist at all in that new file). I am not sure if this is the case, because I don’t use Matlab, but just so you know that is something that might happen.
And I hope things are good in Milwaukee!
The matlab library should still work for AFNI format, but we rarely use MATLAB ourselves anymore.
NIFTI format can work too, but be careful about orientation and template spaces if you are exporting it back to AFNI.
Getting data out of a single sub-brick volume can be accomplished with sub-brick selectors in AFNI:
3dTcat -prefix mydset_vol.nii.gz mydset+tlrc’’
This example extract sub-brick 3, the fourth volume (counting from 0) to a new dataset (here, using NIFTI for the output). You can use programs like 3dTcat, 3dcalc, 3dbucket, 3dAFNItoNIFTI to do the extraction (3dcopy doesn’t allow sub-brick selectors though).
Thank you all, for your comments! I will convert thee 3dDeconvolve output to NIFTI before importing it into Matlab, then.
Milwaukee is hanging in there, Paul! Hope you are all well amidst all this craziness!