-
Notifications
You must be signed in to change notification settings - Fork 297
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
[ENH] Template-based masking of EPI boldrefs #1321
Changes from 2 commits
ec5e651
3e344db
2679533
af0cd52
c088fb6
966d412
be17090
76d0f70
713132f
18fe6ca
4dc0908
30d7658
65e6fbc
8ba55fa
698e821
e52394e
2a09ae8
f86b543
9503750
ca32147
7535a08
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -479,6 +479,51 @@ def _run_interface(self, runtime): | |
return runtime | ||
|
||
|
||
class MatchHeaderInputSpec(BaseInterfaceInputSpec): | ||
reference = File(exists=True, mandatory=True, | ||
desc='NIfTI file with reference header') | ||
in_file = File(exists=True, mandatory=True, | ||
desc='NIfTI file which header will be checked') | ||
|
||
|
||
class MatchHeaderOutputSpec(TraitedSpec): | ||
out_file = File(exists=True, desc='NIfTI file with fixed header') | ||
|
||
|
||
class MatchHeader(SimpleInterface): | ||
input_spec = MatchHeaderInputSpec | ||
output_spec = MatchHeaderOutputSpec | ||
|
||
def _run_interface(self, runtime): | ||
refhdr = nb.load(self.inputs.reference).header.copy() | ||
imgnii = nb.load(self.inputs.in_file) | ||
imghdr = imgnii.header.copy() | ||
|
||
imghdr['dim_info'] = refhdr['dim_info'] # dim_info is lost sometimes | ||
|
||
# Set qform | ||
qform, qcode = refhdr.get_qform(coded=True) | ||
if not np.allclose(qform, imghdr.get_qform()): | ||
LOGGER.warning( | ||
'q-forms of reference and mask are substantially different') | ||
imghdr.set_qform(qform, int(qcode)) | ||
|
||
# Set sform | ||
sform, scode = refhdr.get_sform(coded=True) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
if not np.allclose(sform, imghdr.get_sform()): | ||
LOGGER.warning( | ||
's-forms of reference and mask are substantially different') | ||
imghdr.set_sform(sform, int(scode)) | ||
|
||
out_file = fname_presuffix(self.inputs.in_file, suffix='_hdr', | ||
newpath=runtime.cwd) | ||
|
||
imgnii.__class__(imgnii.get_data(), imgnii.affine, imghdr).to_filename( | ||
out_file) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think this will work how you want. You may want to add tests. If A better approach would be: imgnii.__class__(imgnii.get_data(), imghdr.get_best_affine(), imghdr).to_filename(
out_file) |
||
self._results['out_file'] = out_file | ||
return runtime | ||
|
||
|
||
def reorient(in_file, newpath=None): | ||
"""Reorient Nifti files to RAS""" | ||
out_file = fname_presuffix(in_file, suffix='_ras', newpath=newpath) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are all images guaranteed to have non-zero codes? If
qcode == 0
,qform == None
.https://github.com/nipy/nibabel/blob/d5494f3350967b65bd6de1abefd95ab2899044e0/nibabel/nifti1.py#L916-L917