Comments (3)
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](https://private-user-images.githubusercontent.com/4668327/322198991-36e22fb0-af43-4900-a8ce-f47e55415b66.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjEzMjI0MTYsIm5iZiI6MTcyMTMyMjExNiwicGF0aCI6Ii80NjY4MzI3LzMyMjE5ODk5MS0zNmUyMmZiMC1hZjQzLTQ5MDAtYThjZS1mNDdlNTU0MTViNjYucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI0MDcxOCUyRnVzLWVhc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BvX2lkPTAifQ.wsGS_yje22keQenESzRAjGB0S4-iUsyET1dojy99uCU)
Let me know if trying the script above works for you or not.
from bvbabel.
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.
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)
- PRT data type issue HOT 1
- PRT to BIDS style TSV conversion
- Add diffusion weighted imaging (DWI) formats HOT 7
- Create SDM files HOT 1
- Cannot read PRT files with tab-separated timings HOT 1
- Add ROI read write support HOT 1
- Add rountrip tests HOT 1
- Add read nifti write VMR example
- Add GLM read write support HOT 3
- Add example for working with SRF and POI files HOT 1
- Add an example for censoring and interpolating volumes in FMR data based on motion estimates
- Detect bogus BrainVoyager NIfTI headers HOT 3
- Add TBV .roi support
- VTC reader returns 0 for all voxel activations HOT 3
- Potentional Better Matrix Reader? HOT 1
- Add read both lag and correlation value from linear correlation vmp HOT 2
- An issue in read_fmr HOT 2
- Propose Addtion of Turbo Brainvoyager file
- Add read and write support of Diffusion Files
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from bvbabel.