KamitaniLab / bdpy

Python package for brain decoding analysis (BrainDecoderToolbox2 data format, machine learning analysis, functional MRI)
MIT License
32 stars 22 forks source link

Export Data object as a nifti file #9

Open scarere opened 3 years ago

scarere commented 3 years ago

I'm having trouble finding a headache free way to export bData objects or data in the bData format to nifti files such that they can be viewed with software such as fsl. I'm working with the dataset from https://github.com/KamitaniLab/GenericObjectDecoding/tree/master/data, where the preprocessed data is in BrainDecoderToolbox2 format. As far as I can tell, information about the original 3d shape of the data and the corresponding affine transformation is thrown away and not retained as attributes or metadata of the bData class. I've noticed that bdpy.mri.images has a function that exports the data as a Nifti1image object, however it relies on a template file that provides the affine transform and original 3d shape of the data. However since the dataset I'm using comes in bdpy format it's not clear to me what can be used as the template image. If you could provide any help or insight that would be appreciated. Additionally if there is a version of the dataset I mentioned that contains the 3d shape/affine information in the bdata object that would be greatly appreciated. (I'm aware the original dataset is available but would like to avoid having to do all the preprocessing over again)

ShuntaroAoki commented 3 years ago

Thanks for issuing this.

We posted the preprocessed Nifti images at OpenNeuro (https://openneuro.org/datasets/ds001246/versions/1.2.1; in derivatives/preproc-spm), which is exactly the source of the BData files. I think they may help you.

Besides, as you pointed out, it is better to add a handy method to export BData to Nifti images. Although BData doesn't include the affine matrix explicitly, we can guess or recover the transformation based on xyz coordinates in BData. We'll add such a method.

scarere commented 3 years ago

As an update, using one of the functional runs as the template for the export_brain_image function seems to be a good temporary solution. However it takes a non-trivial amount of time (3s) to export on my laptop. For higher resolution images this may be a problem. I initially tried using the anatomical image as the template (resultant exported image ended up being the same resolution hence not a good choice for the template) and it took nearly two minutes to export one image. I imagine the culprit is likely the for loop iterating over every potential coordinate.