Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

method to load .img without .hdr #673

Closed
mrjeffs opened this issue Oct 3, 2018 · 2 comments
Closed

method to load .img without .hdr #673

mrjeffs opened this issue Oct 3, 2018 · 2 comments

Comments

@mrjeffs
Copy link

mrjeffs commented Oct 3, 2018

a clunky use case has arisen where only the .img portion of an analyze file is available.
i want to load the .img into nibabel and then fill in the missing parts of the header, eg affine, zooms, etc
reorient and save as nifti.
nib.load('file.img') gives 'cannot work out file type' error. what is a work around to avoid the missing .hdr

@effigies
Copy link
Member

effigies commented Oct 3, 2018

If you know the type, shape and affine of the data, you should just be able to create a numpy.memmap object:

import nibabel as nb
import numpy as np
dataobj = np.memmap('file.img', dtype=<dtype>, mode='r', shape=<shape>, order='F')
img = nb.Nifti1Image(dataobj, <affine>)

You can now fiddle with img.header.

@mrjeffs
Copy link
Author

mrjeffs commented Oct 3, 2018

that worked great. thanks. issue closed. :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants