<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">
Dear John and Stefania,
<div class=""><br class="">
</div>
<div class="">I am not sure whether I understand what the problem is, and whether there is a problem to begin with.</div>
<div class=""><br class="">
</div>
<div class="">I tried to simulate (part of) your use case with the below snippet of code, and to me, it seems to behave as expected.</div>
<div class=""><br class="">
</div>
<div class="">From what I read (both on, and between the lines) in your message (not backed up by example data from your specific use case) your issue seems to be that the interpolation of the boolean inside field of the tetra mesh onto the regular volumetric
(hexahedral) grid does not behave as expected. Indeed, this could be due to the fact that the interpolation from less well-structured point clouds (i.e. the tetrahedral mesh) is done using the ’nearest’ method, which is an all-or-none phenomenon when the functional
values are either 0 or 1. </div>
<div class=""><br class="">
</div>
<div class="">What happens if you'd, rather than relying on the ’inside’ definition of the mesh, explicitly define the ‘inside’ compartment in the mri volume (as I did just before the second call to ft_sourceinterpolate)? It seems that this results in a volume
with functional values that do not ‘bleed into’ the outside compartment.</div>
<div class=""><br class="">
</div>
<div class="">Best wishes,</div>
<div class="">Jan-Mathijs</div>
<div class=""><br class="">
</div>
<div class=""><br class="">
</div>
<div class=""><br class="">
</div>
<div class=""><br class="">
</div>
<div class=""><br class="">
</div>
<div class="">
<div style="margin: 0px; font-stretch: normal; font-size: 10px; line-height: normal; font-family: Courier; color: rgb(34, 139, 34);" class="">
% create a volumetric sphere, at '1 mm'</div>
<div style="margin: 0px; font-stretch: normal; font-size: 10px; line-height: normal; font-family: Courier;" class="">
mri = [];</div>
<div style="margin: 0px; font-stretch: normal; font-size: 10px; line-height: normal; font-family: Courier;" class="">
mri.dim = [75 75 75];</div>
<div style="margin: 0px; font-stretch: normal; font-size: 10px; line-height: normal; font-family: Courier;" class="">
mri.transform = [eye(3) ones(3,1).*-38; 0 0 0 1];</div>
<p style="margin: 0px; font-stretch: normal; font-size: 10px; line-height: normal; font-family: Courier; min-height: 12px;" class="">
<br class="webkit-block-placeholder">
</p>
<div style="margin: 0px; font-stretch: normal; font-size: 10px; line-height: normal; font-family: Courier;" class="">
[x,y,z] = ndgrid(-37:37,-37:37,-37:37);</div>
<p style="margin: 0px; font-stretch: normal; font-size: 10px; line-height: normal; font-family: Courier; min-height: 12px;" class="">
<br class="webkit-block-placeholder">
</p>
<div style="margin: 0px; font-stretch: normal; font-size: 10px; line-height: normal; font-family: Courier;" class="">
pos = [x(:) y(:) z(:)];</div>
<div style="margin: 0px; font-stretch: normal; font-size: 10px; line-height: normal; font-family: Courier;" class="">
mri.brain = (x./37).^2 + (y./37).^2 + (z./37).^2 < 1;</div>
<p style="margin: 0px; font-stretch: normal; font-size: 10px; line-height: normal; font-family: Courier; min-height: 12px;" class="">
<br class="webkit-block-placeholder">
</p>
<div style="margin: 0px; font-stretch: normal; font-size: 10px; line-height: normal; font-family: Courier; color: rgb(34, 139, 34);" class="">
% downsample the sphere to '3 mm'</div>
<div style="margin: 0px; font-stretch: normal; font-size: 10px; line-height: normal; font-family: Courier;" class="">
cfg = [];</div>
<div style="margin: 0px; font-stretch: normal; font-size: 10px; line-height: normal; font-family: Courier;" class="">
cfg.downsample = 3;</div>
<div style="margin: 0px; font-stretch: normal; font-size: 10px; line-height: normal; font-family: Courier;" class="">
mri2 = ft_volumedownsample(cfg, mri);</div>
<p style="margin: 0px; font-stretch: normal; font-size: 10px; line-height: normal; font-family: Courier; min-height: 12px;" class="">
<br class="webkit-block-placeholder">
</p>
<div style="margin: 0px; font-stretch: normal; font-size: 10px; line-height: normal; font-family: Courier; color: rgb(34, 139, 34);" class="">
% create a 'low res' tetrahedral mesh from the sphere</div>
<div style="margin: 0px; font-stretch: normal; font-size: 10px; line-height: normal; font-family: Courier;" class="">
cfg = [];</div>
<div style="margin: 0px; font-stretch: normal; font-size: 10px; line-height: normal; font-family: Courier;" class="">
cfg.method = <span style="color: #a020f0" class="">'tetrahedral'</span>;</div>
<div style="margin: 0px; font-stretch: normal; font-size: 10px; line-height: normal; font-family: Courier;" class="">
mesh = ft_prepare_mesh(cfg, mri2);</div>
<p style="margin: 0px; font-stretch: normal; font-size: 10px; line-height: normal; font-family: Courier; min-height: 12px;" class="">
<br class="webkit-block-placeholder">
</p>
<div style="margin: 0px; font-stretch: normal; font-size: 10px; line-height: normal; font-family: Courier; color: rgb(34, 139, 34);" class="">
% add some 'functional' data to the mesh, this should be approximately</div>
<div style="margin: 0px; font-stretch: normal; font-size: 10px; line-height: normal; font-family: Courier; color: rgb(34, 139, 34);" class="">
% equal to reflect the distance to the origin.</div>
<div style="margin: 0px; font-stretch: normal; font-size: 10px; line-height: normal; font-family: Courier;" class="">
mesh.pow = sqrt(mesh.pos(:,1).^2+mesh.pos(:,2).^2+mesh.pos(:,3).^2); </div>
<p style="margin: 0px; font-stretch: normal; font-size: 10px; line-height: normal; font-family: Courier; min-height: 12px;" class="">
<br class="webkit-block-placeholder">
</p>
<div style="margin: 0px; font-stretch: normal; font-size: 10px; line-height: normal; font-family: Courier; color: rgb(34, 139, 34);" class="">
% what happens now if we try to interpolate?</div>
<div style="margin: 0px; font-stretch: normal; font-size: 10px; line-height: normal; font-family: Courier;" class="">
mri.anatomy = double(mri.brain);</div>
<p style="margin: 0px; font-stretch: normal; font-size: 10px; line-height: normal; font-family: Courier; min-height: 12px;" class="">
<br class="webkit-block-placeholder">
</p>
<div style="margin: 0px; font-stretch: normal; font-size: 10px; line-height: normal; font-family: Courier;" class="">
cfg = [];</div>
<div style="margin: 0px; font-stretch: normal; font-size: 10px; line-height: normal; font-family: Courier;" class="">
cfg.parameter = <span style="color: #a020f0" class="">'pow'</span>;</div>
<div style="margin: 0px; font-stretch: normal; font-size: 10px; line-height: normal; font-family: Courier;" class="">
mesh_int = ft_sourceinterpolate(cfg, mesh, mri);</div>
<p style="margin: 0px; font-stretch: normal; font-size: 10px; line-height: normal; font-family: Courier; min-height: 12px;" class="">
<br class="webkit-block-placeholder">
</p>
<div style="margin: 0px; font-stretch: normal; font-size: 10px; line-height: normal; font-family: Courier;" class="">
cfg = [];</div>
<div style="margin: 0px; font-stretch: normal; font-size: 10px; line-height: normal; font-family: Courier;" class="">
cfg.funparameter = <span style="color: #a020f0" class="">'pow'</span>;</div>
<div style="margin: 0px; font-stretch: normal; font-size: 10px; line-height: normal; font-family: Courier;" class="">
ft_sourceplot(cfg, mesh_int);</div>
<div style="margin: 0px; font-stretch: normal; font-size: 10px; line-height: normal; font-family: Courier; color: rgb(34, 139, 34);" class="">
% conclusion: without an explicitly defined 'inside' compartment the </div>
<div style="margin: 0px; font-stretch: normal; font-size: 10px; line-height: normal; font-family: Courier; color: rgb(34, 139, 34);" class="">
% interpolated mesh also obtains values in 'voxels' that were not in the </div>
<div style="margin: 0px; font-stretch: normal; font-size: 10px; line-height: normal; font-family: Courier; color: rgb(34, 139, 34);" class="">
% boolean input volume: this makes sense, because the sourcemodel (i.e. the</div>
<div style="margin: 0px; font-stretch: normal; font-size: 10px; line-height: normal; font-family: Courier; color: rgb(34, 139, 34);" class="">
% tetra mesh cannot make a distinction between inside/outside, because it</div>
<div style="margin: 0px; font-stretch: normal; font-size: 10px; line-height: normal; font-family: Courier; color: rgb(34, 139, 34);" class="">
% cannot be defined similarly to a 3D (or hex) grid, which is regular, and</div>
<div style="margin: 0px; font-stretch: normal; font-size: 10px; line-height: normal; font-family: Courier; color: rgb(34, 139, 34);" class="">
% has a dim (to define the reshaping)</div>
<p style="margin: 0px; font-stretch: normal; font-size: 10px; line-height: normal; font-family: Courier; color: rgb(34, 139, 34); min-height: 12px;" class="">
<br class="webkit-block-placeholder">
</p>
<div style="margin: 0px; font-stretch: normal; font-size: 10px; line-height: normal; font-family: Courier; color: rgb(34, 139, 34);" class="">
% what happens now if we try to interpolate while adding an inside to the </div>
<div style="margin: 0px; font-stretch: normal; font-size: 10px; line-height: normal; font-family: Courier; color: rgb(34, 139, 34);" class="">
% mri?</div>
<div style="margin: 0px; font-stretch: normal; font-size: 10px; line-height: normal; font-family: Courier;" class="">
mri.inside = mri.brain;</div>
<p style="margin: 0px; font-stretch: normal; font-size: 10px; line-height: normal; font-family: Courier; min-height: 12px;" class="">
<br class="webkit-block-placeholder">
</p>
<div style="margin: 0px; font-stretch: normal; font-size: 10px; line-height: normal; font-family: Courier;" class="">
cfg = [];</div>
<div style="margin: 0px; font-stretch: normal; font-size: 10px; line-height: normal; font-family: Courier;" class="">
cfg.parameter = <span style="color: #a020f0" class="">'pow'</span>;</div>
<div style="margin: 0px; font-stretch: normal; font-size: 10px; line-height: normal; font-family: Courier;" class="">
mesh_int2 = ft_sourceinterpolate(cfg, mesh, mri);</div>
<p style="margin: 0px; font-stretch: normal; font-size: 10px; line-height: normal; font-family: Courier; min-height: 12px;" class="">
<br class="webkit-block-placeholder">
</p>
<div style="margin: 0px; font-stretch: normal; font-size: 10px; line-height: normal; font-family: Courier;" class="">
cfg = [];</div>
<div style="margin: 0px; font-stretch: normal; font-size: 10px; line-height: normal; font-family: Courier;" class="">
cfg.funparameter = <span style="color: #a020f0" class="">'pow'</span>;</div>
<div style="margin: 0px; font-stretch: normal; font-size: 10px; line-height: normal; font-family: Courier;" class="">
ft_sourceplot(cfg, mesh_int2);</div>
<div style="margin: 0px; font-stretch: normal; font-size: 12px; line-height: normal; font-family: Courier; min-height: 14px;" class="">
<br class="">
</div>
</div>
<div class=""><br class="">
<div><br class="">
<blockquote type="cite" class="">
<div class="">On 6 Mar 2021, at 17:45, RICHARDS, JOHN <<a href="mailto:RICHARDS@mailbox.sc.edu" class="">RICHARDS@mailbox.sc.edu</a>> wrote:</div>
<br class="Apple-interchange-newline">
<div class="">
<div class="">I figured part of it out.<br class="">
<br class="">
The functional data, computed from a tetra source, is not on a regular grid and so is "unstructured". We had a dim member in the source structure which defined it in ft_sourceinterpolate as regular grid. The anatomical 1mm data was structured hex. <br class="">
<br class="">
However, its still not exactly correct. The output MRI volume based on the interpout data seems to be on discrete voxels. Perhaps it’s the "nearest" interp method which is the only interp allowed for non-grid functional? The 3mm regular hex sources allow
"spline" interp, that might be it?<br class="">
<br class="">
John<br class="">
<br class="">
<br class="">
<br class="">
<br class="">
***********************************************<br class="">
John E. Richards<br class="">
Carolina Distinguished Professor<br class="">
Department of Psychology<br class="">
University of South Carolina<br class="">
Columbia, SC 29208<br class="">
Dept Phone: 803 777 2079<br class="">
Fax: 803 777 9558<br class="">
<a href="mailto:richards-john@sc.edu" class="">Email: richards-john@sc.edu</a><br class="">
https://jerlab.sc.edu<br class="">
*************************************************<br class="">
<br class="">
-----Original Message-----<br class="">
From: RICHARDS, JOHN <br class="">
Sent: Saturday, March 6, 2021 10:50 AM<br class="">
To: fieldtrip@science.ru.nl<br class="">
Cc: CONTE, STEFANIA <CONTES@mailbox.sc.edu><br class="">
Subject: ft_sourceinterpolate<br class="">
<br class="">
We are trying to use ft_sourceinterpolate.<br class="">
<br class="">
1--We have a tetra source model, do source analysis with eLORETA, ERP data, etc. The source model is based on a tetrahedral mesh on gm rather than a hex mesh.<br class="">
<br class="">
2--We have a 1mm hex mesh on gm<br class="">
<br class="">
3--The goal is to interpolate the "sparse" tetra mesh with the functional data, onto the 1 mm hex mesh, in order to create MRI volumes with the activation.<br class="">
<br class="">
4--The ft_sourceinterpolate(cfg,sourcewithtetrameash,hex1mmmesh) does not work. It does not result in the same no of "inside" voxels as the 1mm hex mesh<br class="">
<br class="">
e.g., like 25K voxels in the tetra, 855K in the 1 mm grid, but only 15K voxels in the interpout.inside(:).<br class="">
<br class="">
Alternatively<br class="">
1--using a 3 mm hex mesh, source analysis, the source model is based on a 3 mm hex mesh on gm.<br class="">
2--1mm hex<br class="">
3--same goal<br class="">
4--ft_sourceinterpolate(cfg,sourcewith3mmhexmesh,hex1mmmesh) works. It has 855K voxels in the interpout.inside(:). It also correctly saves to the gm of the MRI volume.<br class="">
<br class="">
<br class="">
Any ideas on this?<br class="">
We have tried int32(pos) on both tetra3mm ahd hex1mm; used only overlapping tetra3mm and hex1mm voxels; etc<br class="">
<br class="">
John<br class="">
<br class="">
<br class="">
***********************************************<br class="">
John E. Richards<br class="">
Carolina Distinguished Professor<br class="">
Department of Psychology<br class="">
University of South Carolina<br class="">
Columbia, SC 29208<br class="">
Dept Phone: 803 777 2079<br class="">
Fax: 803 777 9558<br class="">
Email: richards-john@sc.edu<br class="">
https://jerlab.sc.edu<br class="">
*************************************************<br class="">
<br class="">
<br class="">
_______________________________________________<br class="">
fieldtrip mailing list<br class="">
https://mailman.science.ru.nl/mailman/listinfo/fieldtrip<br class="">
https://doi.org/10.1371/journal.pcbi.1002202<br class="">
</div>
</div>
</blockquote>
</div>
<br class="">
</div>
</body>
</html>