Git Product home page Git Product logo

Comments (3)

ofgulban avatar ofgulban commented on July 19, 2024

Hi Kenshu,

Thanks for opening this issue and writing clearly about the problem you are facing. I have used the following changes in the read_fmr_export_nifti.py (see under 'carry over header information section'):

"""Read BrainVoyager FMR file format and exxport it as Nifti."""

import os
import numpy as np
import nibabel as nb
import bvbabel

FILE = "/Users/faruk/data/temp-kenshu/S05_ses1_run01_SCSA_3DMCTS_THPGLMF6c_ref.fmr"

# =============================================================================
# Load fmr
header, data = bvbabel.fmr.read_fmr(FILE)

# Save nifti for testing
basename = FILE.split(os.extsep, 1)[0]
outname = "{}_bvbabel.nii.gz".format(basename)

# Generate Nifti
img = nb.Nifti1Image(data, affine=np.eye(4))

# Carry over equivalent header information
img.header["pixdim"][1] = header['InplaneResolutionX']
img.header["pixdim"][2] = header['InplaneResolutionY']
img.header["pixdim"][3] = header['SliceThickness']
img.header["pixdim"][4] = float(header['TR']) / 1000  # ms to s
img.affine[0, 0] *= img.header["pixdim"][1]
img.affine[1, 1] *= img.header["pixdim"][2]
img.affine[2, 2] *= img.header["pixdim"][3]

# Save
nb.save(img, outname)

print("Finished.")

Upon exporting the nifti with this script, nifti header looks good. Checked with niimath and itksnap:

Screenshot 2024-04-13 at 12 23 59 Screenshot 2024-04-13 at 12 26 46

Let me know if trying the script above works for you or not.

from bvbabel.

ofgulban avatar ofgulban commented on July 19, 2024

Also, another note:

  nii.header["pixdim"][4] = header['NrOfVolumes']

line of your code is incorrect in the way that pixdim 4 is the size of "time" that is TR in seconds. You were putting number of measurements there.

from bvbabel.

kenshukoiso avatar kenshukoiso commented on July 19, 2024

Thank you so much for taking care of my issue immediately!
It works well for my circumstances as well!
Also, thanks for telling me my error, I learnt it.
Thank you so much :)

from bvbabel.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.