[BUG] Several functions under the image
module do not carry over the header information to the output
#4393
Labels
Bug
for bug reports
Is there an existing issue for this?
Operating system
Operating system version
Mac OS Version 14.4.1 "sonoma"
Python version
nilearn version
0.10.4
Expected behavior
This issue was initially reported in #2645 for
math_img
and was fixed in #4337 with acopy_header_from
parameter. The usage is explained in detail in #4392.I have identified other functions with the same issue since then:
crop_img
mean_img
threshold_img
binarize_img
resample_img
reorder_img
remove the check for number of dimensions inmath_img
whencopy_header_from
is not None, ifnew_img_like
can handle it (explained below)The fix could be simple - all of these functions use
new_img_like
to create the output nifti object with thecopy_header
parameter set to False, which can just be changed to True.However, a common thing in all these functions is that they all somehow manipulate the data values/affine/dimensions of the input, which in turn reflects in the header info of the result image. So this makes copying the header a bit more complicated depending on what the function does.
As shown below fornew_img_like
, the header copying fromnew_img_like
does not handle these cases well and returns wrong headers. So I think it would be worthwhile to updatenew_img_like
first.EDIT: As it turns out, I wasn't passing the affine into
new_img_like
below. I have updated the code now. Once I do this, it does seem to give the correct TR and voxel dimensions.So
new_img_like
seems to handle well the changes in affine at least forresample_img
. I will go over each function and use case now.Current behavior & error messages
Steps and code to reproduce bug
The text was updated successfully, but these errors were encountered: