# Recommendations with converting a surface source estimate object to nifti

**URL:** <https://mne.discourse.group/t/recommendations-with-converting-a-surface-source-estimate-object-to-nifti/3029>\
**Category:** Support & Discussions\
**Tags:** ﻿source-localization, meg, visualization\
**Created:** [April 22, 2021, 1:04pm UTC](https://mne.discourse.group/t/recommendations-with-converting-a-surface-source-estimate-object-to-nifti/3029 "2021-04-22T13:04:02Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![eman1369](https://avatars.discourse-cdn.com/v4/letter/e/a88e4f/32.png) [@eman1369](https://mne.discourse.group/u/eman1369)\
**Post date:** [April 22, 2021, 1:04pm UTC](https://mne.discourse.group/t/recommendations-with-converting-a-surface-source-estimate-object-to-nifti/3029/1 "2021-04-22T13:04:02Z")

</div>

**If you have a question or issue with MNE-Python, please include the following info:**

- MNE-Python version: 0.21.1
- operating system: Windows 10

Good afternoon I am trying to visualize with nifti our roc estimates on brains. Not so important to go into details. In the end now I have a source estimate object where i can visualize using the plot method.  
This is however a surface source estimate and I need to convert it into nifti to visualize it. I know that the VolSourceEstimate object has a save as nifti format but not the surface source estimate. How can I proceed? Any advice or opinions?

I took the approach of trying to get a morph object with the mne.compute\_source\_morph() and then modifying somehow the function \_interpolate\_data(stc, morph, mri\_resolution, mri\_space, output) to work on surface source estimates. I however am stuck because I end up getting a morph object with a list of 2 arrays under morphed\_data\_object[‘from vertices’] and not the mentioned arrays in the interpolate\_data function:  
if mri\_resolution:  
affine = morph.src\_data[‘src\_affine\_vox’]  
else:  
affine = morph.src\_data[‘src\_affine\_src’]

```
if mri_space:
    affine = np.dot(morph.src_data['src_affine_ras'], affine)

```

I am however a student and relatively new to mne so it may be far fetched my approach to solving the situation.  
I know I cant simply just feed the raw stc to the nibabels Nifti1.image function because there should be a transformation prior which I had thought to be the source morph.

Any opinions or advice?

---

<div class="post-metadata">

**Author:** ![larsoner](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/larsoner/32/3_2.png) [@larsoner](https://mne.discourse.group/u/larsoner)\
**Post date:** [April 27, 2021, 7:46pm UTC](https://mne.discourse.group/t/recommendations-with-converting-a-surface-source-estimate-object-to-nifti/3029/2 "2021-04-27T19:46:19Z")

</div>

I can think of two ways:

1. Use a combination of upsampling to the high resolution mesh using `morph = compute_source_morph(src, subject, smooth='nearest', spacing=None)`, then using `nibabel.freesurfer.io.write_morph_data`, and then FreeSurfer’s `mri_surf2vol`.

2. Read FreeSurfer’s `ribbon.mgz` for your subject, and for each voxel, take the value of the nearest point in your source space. This will involve a bit of gymnastics involving `vox_mri_t` for the source space, which is really the same thing as nibabel’s `img.header.get_vox2ras_tkr()`.

Feel free to give either or both of these a shot and if this isn’t enough information to go on, I can try to write a little example for MNE showing one or both of these.

In principle we could consider adding a `as_volume` / `save_as_volume` for surface source spaces that does the second method.
