ofgulban / bvbabel

A lightweight Python library for reading & writing BrainVoyager file formats.
MIT License
19 stars 11 forks source link

Detect bogus BrainVoyager NIfTI headers #36

Open neurolabusc opened 1 year ago

neurolabusc commented 1 year ago

The NIfTI specification defines cal_min and cal_max as follows:

float cal_max;       /*!< Max display intensity */  /* float cal_max;       */
float cal_min;       /*!< Min display intensity */  /* float cal_min;       */

It is standard convention to set both to zero if they are to be ignored. Unfortunately, BrainVoyager seems to set these to 0 and 255 respectively when creating NIfTI data.

The BIDS format BrainVoyager Getting Started Guide (GSG) files exhibit this, e.g. GSGData.zip. Consider the fMRI image that has a mean intensity of 4022 (with a range of 0..49183). Here the cal_min and cal_max of 0..255 is inappropriate, with even dark air voxels having values ~700.

$ fslinfo sub-01_ses-04_task-blocked_run-1_bold.nii.gz   
data_type   FLOAT32
dim1        100
dim2        100
dim3        64
dim4        291
datatype    16
pixdim1     2.000000
pixdim2     2.000000
pixdim3     2.000000
pixdim4     2.000000
cal_max     255.000000
cal_min     0.000000
file_type   NIFTI-1+
$ fslstats sub-01_ses-04_task-blocked_run-1_bold.nii.gz -m -R
4021.941837 0.000000 49183.000000 

It would be great if BrainVoyager could fix this, but bvlabel could also provide a mechanism for detecting and fixing existing bogus values.

ofgulban commented 1 year ago

@neurolabusc thanks a lot for opening this issue and informing us. I will submit this as a bug to brainvoyager.

Just to double check if I understand correctly, here you are talking about a file (probably a .fmr) that is exported from BrainVoyager as nifti (using the GUI export nifti option), right?

ofgulban commented 1 year ago

Tagging @ju-ec and @nausikaa8 , because this might be something to consider while updating the docs and example data.

nausikaa8 commented 1 year ago

Thanks @ofgulban, we have updated the tests.