<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css" style="display:none;"> P {margin-top:0;margin-bottom:0;} </style>
</head>
<body dir="ltr">
<div class="elementToProof" style="text-align: justify; text-indent: 0px; margin-top: 0px; margin-bottom: 1rem; font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
Dear community,</div>
<div class="elementToProof" style="text-align: justify; text-indent: 0px; margin-top: 0px; margin-bottom: 1rem; font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
I am Saskia Wilken and I am doing my PhD at the Fernuniversität in Hagen in Germany on motor control and its neuronal correlates. I am currently analyzing data for a paper for which we recorded EEG and an anatomical MRI image per participant. We are doing source
 reconstruction via beamforming using the individual anatomies for the headmodels. </div>
<div class="elementToProof" style="text-align: justify; text-indent: 0px; margin-top: 0px; margin-bottom: 1rem; font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
My preprocessing pipeline does not work for around a third (20) of my participants' MRI images. After running the segmentation using ft_volumesegment and preparing meshes for skull, brain and scalp using ft_prepare_mesh, ft_prepare_headmodel yields a headmodel.mat
 with all NaN values. I posted the code and the cfg of all three functions below. I intended to use a Boundary Element Model and wouldn't want to use a different type of headmodel on a subset of my data.</div>
<div class="elementToProof" style="text-align: justify; text-indent: 0px; margin-top: 0px; margin-bottom: 1rem; font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
All MRIs are resliced and bias corrected. I tried out different methods and parameters - adjusting smoothing and threshold worked on a few of the other MRIs - but not on these remaining 20 MRIs. I also tried with different numbers of vertices, different methods
 for mesh preparation, and different segmentation methods I also attempted to correct the segmentation manually by filling holes and smoothing out ragged edges between the tissue types using Seg3D like suggested on the Fieldtrip website, assuming that the issue
 might be intersecting or self-intersecting meshes. But it didn't change the outcome. </div>
<pre style="margin-top: 0px; margin-bottom: 0px; padding-right: 0.8em; padding-left: 0.8em; display: block;"><div style="padding: 30px;"><div class="elementToProof" style="white-space: normal; font-family: SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace; font-size: 12pt; color: rgb(0, 0, 0);">subject_id = '3313';</div><div class="elementToProof" style="white-space: normal; font-family: SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace; font-size: 12pt; color: rgb(0, 0, 0);">mri_resliced = ft_read_mri([subject_id + "_resliced.mat"])</div><div class="elementToProof" style="white-space: normal; font-family: SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace; font-size: 12pt; color: rgb(0, 0, 0);"><br></div><div class="elementToProof" style="white-space: normal; font-family: SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace; font-size: 12pt; color: rgb(0, 0, 0);">%% Segmentation of Brain, Skull and Scalp</div><div style="white-space: normal; font-family: SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace; font-size: 12pt; color: rgb(0, 0, 0);">cfg           = [];</div><div class="elementToProof" style="white-space: normal; font-family: SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace; font-size: 12pt; color: rgb(0, 0, 0);">cfg.output    = {'brain', 'skull', 'scalp'};</div><div class="elementToProof" style="white-space: normal; font-family: SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace; font-size: 12pt; color: rgb(0, 0, 0);">% I tried out a wide array of different value combinations already</div><div class="elementToProof" style="white-space: normal; font-family: SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace; font-size: 12pt; color: rgb(0, 0, 0);">cfg.brainsmooth      = 5; % default = 5;</div><div style="white-space: normal; font-family: SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace; font-size: 12pt; color: rgb(0, 0, 0);">cfg.scalpsmooth      = 5; % default = 5;</div><div style="white-space: normal; font-family: SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace; font-size: 12pt; color: rgb(0, 0, 0);">cfg.skullsmooth      = 5; % default = 5;</div><div class="elementToProof" style="white-space: normal; font-family: SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace; font-size: 12pt; color: rgb(0, 0, 0);">cfg.brainthreshold   = 0.5; % default = 0.5;</div><div class="elementToProof" style="white-space: normal; font-family: SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace; font-size: 12pt; color: rgb(0, 0, 0);">cfg.scalpthreshold   = 0.1; % default = 0.1;</div><div class="elementToProof" style="white-space: normal; font-family: SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace; font-size: 12pt; color: rgb(0, 0, 0);">cfg.skullthreshold   = 0.5; % default = 0.5;</div><div class="elementToProof" style="white-space: normal; font-family: SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace; font-size: 12pt; color: rgb(0, 0, 0);"><br></div><div class="elementToProof" style="white-space: normal; font-family: SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace; font-size: 12pt; color: rgb(0, 0, 0);">segmentedmri  = ft_volumesegment(cfg, mri_resliced);</div><div class="elementToProof" style="white-space: normal; font-family: SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace; font-size: 12pt; color: rgb(0, 0, 0);">ft_checkdata(segmentedmri, 'feedback', 'yes');</div><div style="white-space: normal; font-family: SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace; font-size: 12pt; color: rgb(0, 0, 0);"><br></div><div class="elementToProof" style="white-space: normal; font-family: SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace; font-size: 12pt; color: rgb(0, 0, 0);">%% Create Mesh</div><div style="white-space: normal; font-family: SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace; font-size: 12pt; color: rgb(0, 0, 0);">cfg = [];</div><div style="white-space: normal; font-family: SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace; font-size: 12pt; color: rgb(0, 0, 0);">cfg.tissue      = {'brain', 'skull', 'scalp'};</div><div style="white-space: normal; font-family: SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace; font-size: 12pt; color: rgb(0, 0, 0);">cfg.method      = 'projectmesh';</div><div class="elementToProof" style="white-space: normal; font-family: SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace; font-size: 12pt; color: rgb(0, 0, 0);">cfg.numvertices = [3000 2000 1000] %[6000 4000 4000];</div><div class="elementToProof" style="white-space: normal; font-family: SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace; font-size: 12pt; color: rgb(0, 0, 0);"><br></div><div style="white-space: normal; font-family: SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace; font-size: 12pt; color: rgb(0, 0, 0);">mesh = ft_prepare_mesh(cfg, segmentedmri);</div><div style="white-space: normal; font-family: SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace; font-size: 12pt; color: rgb(0, 0, 0);">mesh = ft_convert_units(mesh, 'mm'); % Use SI Units</div><div style="white-space: normal; font-family: SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace; font-size: 12pt; color: rgb(0, 0, 0);"><br></div><div class="elementToProof" style="white-space: normal; font-family: SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace; font-size: 12pt; color: rgb(0, 0, 0);">%% Create a volume conduction model</div><div style="white-space: normal; font-family: SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace; font-size: 12pt; color: rgb(0, 0, 0);">cfg        = [];</div><div class="elementToProof" style="white-space: normal; font-family: SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace; font-size: 12pt; color: rgb(0, 0, 0);">cfg.method = 'bemcp'; % only BEM method that works on my machine</div><div class="elementToProof" style="white-space: normal; font-family: SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace; font-size: 12pt; color: rgb(0, 0, 0);">headmodel = ft_prepare_headmodel(cfg, mesh);</div><div class="elementToProof" style="white-space: normal; font-family: SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace; font-size: 12pt; color: rgb(0, 0, 0);">headmodel = ft_convert_units(headmodel, 'mm'); % Use SI Units</div><div class="elementToProof" style="white-space: normal; font-family: SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace; font-size: 12pt; color: rgb(0, 0, 0);">headmodel.coordsys = 'ctf';</div></div><div class="elementToProof" style="white-space: normal; font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">I uploaded an example of a not-working MRI, you can download it from <span style="color: rgb(176, 37, 44);"><a href="https://fernuni-hagen.sciebo.de/s/fFAYa0CopBAz2qY" id="LPlnk481084" class="OWAAutoLink">https://fernuni-hagen.sciebo.de/s/fFAYa0CopBAz2qY</a></span></div><div class="elementToProof" style="white-space: normal; font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">When I run fr_prepare_headmodel, I get the following warnings: </div><div class="elementToProof" style="white-space: normal; font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);"><br></div><div class="elementToProof" style="white-space: normal; font-family: SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace; font-size: 12pt; color: rgb(0, 0, 0);">% Appears 8 times:</div><div class="elementToProof" style="white-space: normal; font-family: SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace; font-size: 12pt; color: rgb(0, 0, 0);">Warning: Matrix is singular, close to singular or badly scaled. Results may be inaccurate. RCOND = NaN.</div><div class="elementToProof" style="white-space: normal; font-family: SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace; font-size: 12pt; color: rgb(0, 0, 0);">% Appears only once respectively:</div><div style="white-space: normal; font-family: SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace; font-size: 12pt; color: rgb(0, 0, 0);">Warning: NaN detected, trying once more with slightly different vertex positions</div><div class="elementToProof" style="white-space: normal; font-family: SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace; font-size: 12pt; color: rgb(0, 0, 0);">Warning: flipping mesh 1</div><div class="elementToProof" style="white-space: normal; font-family: SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace; font-size: 12pt; color: rgb(0, 0, 0);">Warning: flipping mesh 2<br>Warning: flipping mesh 3  </div><div class="elementToProof" style="white-space: normal; font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);"><br></div></pre>
<div class="elementToProof" style="text-align: justify; text-indent: 0px; margin-top: 0px; margin-bottom: 1rem; font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
I appreciate any help that can point me towards another solution attempt I haven't tried yet that can help me create a BEM headmodel for the subjects in question. </div>
<div class="elementToProof" style="text-align: justify; text-indent: 0px; margin-top: 0px; margin-bottom: 1rem; font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
Best,</div>
<div id="Signature">
<div style="background-color: rgb(255, 255, 255); margin: 0px;">
<div style="text-align: left; text-indent: 0px; margin: 0px; font-family: wf_segoe-ui_normal, "Segoe UI", "Segoe WP", Tahoma, Arial, sans-serif, serif, EmojiFont; font-size: 15px; color: black;">
<span style="font-family: Arial, sans-serif, serif, EmojiFont; font-size: 10pt;"><b>Saskia Wilken</b></span><span style="font-family: Calibri, sans-serif, serif, EmojiFont; font-size: 11pt;"><br>
</span><span style="font-family: Arial, sans-serif, serif, EmojiFont; font-size: 10pt;">Doktorandin</span></div>
<div style="text-align: left; text-indent: 0px; margin: 0px; font-family: Arial, sans-serif, serif, EmojiFont; font-size: 11pt; color: black;">
-----------------------------------------------</div>
<div style="text-align: left; text-indent: 0px; margin: 0px; font-family: wf_segoe-ui_normal, "Segoe UI", "Segoe WP", Tahoma, Arial, sans-serif, serif, EmojiFont; font-size: 15px; color: black;">
<span style="font-family: Arial, sans-serif, serif, EmojiFont; font-size: 10pt;"><b>FernUniversität in Hagen</b></span><span style="font-family: Calibri, sans-serif, serif, EmojiFont; font-size: 11pt;"><br>
</span><span style="font-family: Arial, sans-serif, serif, EmojiFont; font-size: 10pt;">Fakultät für Psychologie</span></div>
<div style="text-align: left; text-indent: 0px; margin: 0px; font-family: Arial, sans-serif, serif, EmojiFont; font-size: 10pt; color: black;">
Allgemeine Psychologie: Urteilen, Entscheiden, Handeln  </div>
<div style="text-align: left; text-indent: 0px; margin: 0px; font-family: Arial, sans-serif, serif, EmojiFont; font-size: 10pt; color: black;">
Gebäude 11 (Psychologie)</div>
<div style="text-align: left; text-indent: 0px; margin: 0px; font-family: Arial, sans-serif, serif, EmojiFont; font-size: 10pt; color: black;">
Universitätsstraße 37</div>
<div style="text-align: left; text-indent: 0px; margin: 0px; font-family: Arial, sans-serif, serif, EmojiFont; font-size: 10pt; color: black;">
58097 Hagen</div>
<div style="text-align: left; text-indent: 0px; margin: 0px; font-family: Arial, sans-serif, serif, EmojiFont; font-size: 10pt; color: black;">
Telefon: (02331) 987 -4124</div>
<div style="text-align: left; text-indent: 0px; margin: 0px;"><span style="font-family: Arial, sans-serif, serif, EmojiFont; font-size: 13.3333px; color: rgb(0, 112, 192);">saskia.wilken@fernuni-hagen.de</span><span style="font-family: Calibri, Helvetica, sans-serif, EmojiFont, "Apple Color Emoji", "Segoe UI Emoji", NotoColorEmoji, "Segoe UI Symbol", "Android Emoji", EmojiSymbols; font-size: 16px; color: rgb(0, 0, 0);"><br>
</span><span style="font-family: Arial, sans-serif, serif, EmojiFont; font-size: 13px; color: rgb(0, 112, 192);"><a href="https://www.fernuni-hagen.de/psychologie-urteilen-entscheiden/" id="OWAd5d0ee89-62f9-74b9-f2d6-2a354dcac62f" class="OWAAutoLink" data-auth="NotApplicable">https://www.fernuni-hagen.de/psychologie-urteilen-entscheiden/</a></span></div>
</div>
</div>
</body>
</html>