# Source Morphing (and reverting to original) Question

**URL:** <https://mne.discourse.group/t/source-morphing-and-reverting-to-original-question/9300>\
**Category:** Support & Discussions\
**Tags:** ﻿source-localization\
**Created:** [September 10, 2024, 4:25pm UTC](https://mne.discourse.group/t/source-morphing-and-reverting-to-original-question/9300 "2024-09-10T16:25:36Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kosnoff](https://avatars.discourse-cdn.com/v4/letter/k/898d66/32.png) [@Kosnoff](https://mne.discourse.group/u/Kosnoff)\
**Post date:** [September 10, 2024, 4:25pm UTC](https://mne.discourse.group/t/source-morphing-and-reverting-to-original-question/9300/1 "2024-09-10T16:25:36Z")

</div>

Hello,

I’ve got a question regarding the [source morphing process](https://mne.tools/stable/generated/mne.compute_source_morph.html) (MNE 1.7.0). Namely, the shape and use of the `.morph_mat`. My understanding is that the matrix is such that the .\_data of `subject_from` source space could be matrix multiplied to convert to `subject_to` as done in [this tutorial](https://mne.tools/stable/auto_tutorials/stats-source-space/60_cluster_rmANOVA_spatiotemporal.html). If I print the shape of the morph mat, I get, what I assume to be, (N voxels `subject_to` = 20484, N voxels `subject_from`). However, if I then create a source morph for the reverse (i.e., `subject_from` = ‘fsaverage’, `subject_to` = subj\_id), then the source morph for that has shape (N voxels `subject_from` = 20484, N voxels `subject_to`).

1. Why do both matrices put the FSAverage dimensions, regardless of if that is the `subject_from` or `subject_to`?
2. Ultimately, I am hoping to convert all subjects’ data to the brain shape of the same size (hence FSAverage), perform some computations, and then convert each one to the subject-specific space. Is taking the `morph_rev.morph_mat.T` (Subject Voxels, 20484) @ `morphed data` (20484, Time) the proper way to convert back? I know there is a is a [.to\_original\_src](https://mne.tools/stable/generated/mne.SourceEstimate.html#mne.SourceEstimate.to_original_src), but for this particular use case I would greatly prefer to just have to keep track of arrays than source estimate objects.

I should point out that I am making the assumption in both bases 20484 are the voxels for FSAverage, as those are the vertex numbers associated with in the various tutorials [such as this one](https://mne.tools/stable/auto_tutorials/forward/35_eeg_no_mri.html).

# Forward Morph: Subj ID → FSAverage

> src = mne.setup\_source\_space(subject=subj\_id,  
> surface = ‘pial’,  
> add\_dist=‘patch’,  
> spacing = ‘all’,  
> subjects\_dir=path\_to\_MRIs);
> 
> morph = mne.compute\_source\_morph(src=src,  
> subject\_from=subj\_id,  
> subject\_to=‘fsaverage’,  
> subjects\_dir=path\_to\_MRIs)
> 
> print("Morph matrix shape: ", morph.morph\_mat.shape) # (20484, 249578)

# Do the reverse: FSAverage → Subj ID

> src\_reverse = mne.setup\_source\_space(subject=‘fsaverage’,  
> surface = ‘pial’,  
> add\_dist=‘patch’,  
> spacing = ‘all’, # ‘oct6’, # ‘all’  
> subjects\_dir=path\_to\_MRIs);
> 
> morph\_rev = mne.compute\_source\_morph(src=src\_reverse,  
> subject\_from=‘fsaverage’,  
> subject\_to=subj\_id,  
> smooth=‘nearest’,  
> subjects\_dir=path\_to\_MRIs)
> 
> print("Morph matrix shape: ", morph\_rev.morph\_mat.shape) # (20484, 327684)

Also, the voxels corresponding to Subj\_ID have different shapes, but after digging around I think it is acceptable to just extract the vertices from the source morph matrices corresponding to the vertices in the forward src? Can someone confirm this?

> fwd\_vertices = [fwd\_fixed[‘src’][0][‘vertno’], fwd\_fixed[‘src’][1][‘vertno’]] # List of active vertices  
> fwd\_vertices = np.hstack(fwd\_vertices)  
> reduced\_morph\_matrix\_rev = morph\_rev.morph\_mat[:, fwd\_vertices]

Any insight you have is appreciated. Thank you!

**Edit:** Further testing indicates that my assumption that the 20484 voxels belonged to FSAverage was a bad assumption. Playing around a bit more (adding a specific src\_to = argument) and things are behaving as I expected them to. Case closed 🙂
