Repository: nilearn/nilearn

Issue:
`resample_img` forces input image to be NIfTI
<!--Provide a brief description of the bug.-->
Originally popped up in https://github.com/nipreps/smriprep/issues/316 - while plotting `MGHImage`s, sometimes the image needs to be resampled, which is failing with:

```python
  File "/opt/conda/lib/python3.9/site-packages/niworkflows/viz/utils.py", line 377, in plot_registration
	  display = plot_anat(anat_nii, **plot_params)
  File "/opt/conda/lib/python3.9/site-packages/nilearn/plotting/img_plotting.py", line 472, in plot_anat
	  display = plot_img(anat_img, cut_coords=cut_coords,
  File "/opt/conda/lib/python3.9/site-packages/nilearn/plotting/img_plotting.py", line 264, in plot_img
	  display = _plot_img_with_bg(
  File "/opt/conda/lib/python3.9/site-packages/nilearn/plotting/img_plotting.py", line 201, in _plot_img_with_bg
	  display.add_overlay(new_img_like(img, data, affine),
  File "/opt/conda/lib/python3.9/site-packages/nilearn/plotting/displays/_slicers.py", line 273, in add_overlay
	  ims = self._map_show(img, type='imshow', threshold=threshold, **kwargs)
  File "/opt/conda/lib/python3.9/site-packages/nilearn/plotting/displays/_slicers.py", line 349, in _map_show
	  img = reorder_img(img, resample=resampling_interpolation)
  File "/opt/conda/lib/python3.9/site-packages/nilearn/image/resampling.py", line 740, in reorder_img
	  return resample_img(img, target_affine=target_affine,
  File "/opt/conda/lib/python3.9/site-packages/nilearn/image/resampling.py", line 451, in resample_img
	  sform, sform_code = img.get_sform(coded=True)
  AttributeError: 'MGHImage' object has no attribute 'get_sform'
```

`MGHImage` is still a [niimg-like object](https://nilearn.github.io/stable/manipulating_images/input_output.html#niimg-like-objects), so the check should be loosened.

<!--Please fill in the following information, to the best of your ability.-->
Nilearn version: 0.10.0

### Expected behavior
Resamples the image

### Actual behavior
Assumes the image is 

I'll open a PR to loosen this restriction.



Discussion:

Resolving patch:
diff --git a/nilearn/image/resampling.py b/nilearn/image/resampling.py
--- a/nilearn/image/resampling.py
+++ b/nilearn/image/resampling.py
@@ -448,11 +448,12 @@ def resample_img(img, target_affine=None, target_shape=None,
 
     # If later on we want to impute sform using qform add this condition
     # see : https://github.com/nilearn/nilearn/issues/3168#issuecomment-1159447771 # noqa:E501
-    sform, sform_code = img.get_sform(coded=True)
-    if not sform_code:
-        warnings.warn("The provided image has no sform in its header. "
-                      "Please check the provided file. "
-                      "Results may not be as expected.")
+    if hasattr(img, 'get_sform'):  # NIfTI images only
+        _, sform_code = img.get_sform(coded=True)
+        if not sform_code:
+            warnings.warn("The provided image has no sform in its header. "
+                        "Please check the provided file. "
+                        "Results may not be as expected.")
 
     # noop cases
     if target_affine is None and target_shape is None:


Test patch:
diff --git a/nilearn/image/tests/test_resampling.py b/nilearn/image/tests/test_resampling.py
--- a/nilearn/image/tests/test_resampling.py
+++ b/nilearn/image/tests/test_resampling.py
@@ -13,6 +13,7 @@
 import pytest
 
 from nibabel import Nifti1Image, Nifti1Header
+from nibabel.freesurfer import MGHImage
 
 from nilearn import _utils
 from nilearn.image.resampling import resample_img, resample_to_img, reorder_img
@@ -859,3 +860,14 @@ def test_resample_input():
     with testing.write_tmp_imgs(img, create_files=True) as filename:
         filename = Path(filename)
         resample_img(filename, target_affine=affine, interpolation='nearest')
+
+
+def test_smoke_resampling_non_nifti():
+    rng = np.random.RandomState(42)
+    shape = (3, 2, 5, 2)
+    affine = np.eye(4)
+    target_affine = 2 * affine
+    data = rng.randint(0, 10, shape, dtype="int32")
+    img = MGHImage(data, affine)
+
+    resample_img(img, target_affine=target_affine, interpolation='nearest')