Closed kellyhi08 closed 5 months ago
It looks like the anatomical template image and precomputed mask do not share the same affine - are the images aligned?
I am not sure exactly which files you are referring too, but it is correct that the MNIInfant_cohort-2 images do not line up with the subject specific segmentations (dseg) output from BIBSnet, but I don't think they should. There is a file that might be for registration (sub-024_ses-01_from-MNIInfant+2_to-T1w_mode-image_xfm.h5) between those two spaces.
The mask provided by the --derivatives
is expected to be aligned with your input anatomical image, so in this case either the raw T1w or T2w for your subject.
I see. Yes the mask provided by derivatives does align with my subject's raw T1w.
Ok, in that case it probably is because your affines differ enough (perhaps having different levels of precision) to exceed the threshold - first, you should verify this difference by viewing and comparing the affines, and then you can overwrite the derived image's header with the raw T1's. I see you are using BIBSnet outputs - I'm surprised this isn't already applied to the output.
how would I view the affines to compare them?
You can load each image with nibabel, which will let you check out the affines.
import nibabel as nb
import numpy as np
t1 = nb.load("/path/to/raw/T1w")
mask = nb.load("/path/to/mask")
print(t1.affine)
print(mask.affine)
print(np.allclose(t1.affine, mask.affine))
Then, if you wish to use T1w's header:
new_mask = mask.__class__(mask.dataobj, t1.affine, t1.header)
new_mask.set_data_dtype(mask.get_data_dtype())
new_mask.to_filename("/path/to/save/new/mask")
Please reopen if you are still running into issues.
What happened?
I am running nibabies after using BIBSnet for segmentation. I have used the same code for multiple subjects successfully, but I got an error I am having trouble parsing.
What command did you use?
What version of NiBabies are you using?
nibabies-23.1.0.sif: latest as of Jan 16th, 2024
Relevant log output
Add any additional information or context about the problem here.
No response