DevelopmentalImagingMCRI / mantis

Morphologically adaptive neonate tissue segmentation. A toolbox for SPM8/12
Other
6 stars 2 forks source link

Changing template #15

Open anurudhya opened 3 years ago

anurudhya commented 3 years ago

Hi, If I would like to change a new template, do I have to give the FirstNorm as well. If so, how do I generate FirstNorm. Also, is it mandatory to provide BrainEdge file separately.

Thank you in advance.

Anu

richardbeare commented 3 years ago

Hi, I don't think BrainEdge is used anymore - it now forms the last component of FirstNorm.

FirstNorm is a modification of NeonateTPM as follows, which you can clarify further by examining side by side.

NeonateTPM was broken into components (i.e. with fslsplit) which are renamed in the code below:

brain edge:

fslmaths cortex -add wm -add csf -add deepgreymatter -add hippocampus -add amygdala -add cerebellum -add brainstem -thresh 0.2 brainmask
fsmaths brainmask -ero -ero -ero -ero bmero
fslmaths brainmask -sub bmero brain_edge

A set of normed components created as follows:

fslmerge -t nocsf cortex wm background  deepgreymatter hippocampus amygdala cerebellum brainstem
fslmaths nocsf -Tmean -mul 8 sum

for i in cortex wm  background  deepgreymatter hippocampus amygdala cerebellum brainstem ; do
fslmaths $i -div sum ${i}_norm
done

Finally stick them back together to make firstnorm, brainedge last, no csf (because that is derived from the stage 1 segmentation

# check to see if this order is correct
fslmerge -t Firstnorm cortex wm deepgreymatter hippocampus amygdala brainstem cerebellum background brainedge
anurudhya commented 3 years ago

Hi, Thank you very much. It did work properly.

I am trying to use another Atlas which doesn't have 8 tissue types like the one you have configured in the tool. For example, if I use the atlas from brain development that belong to 35 week neonate, the number of tissues available are just 6 (without amygdala and hippocampus). I would like to know if it is possible to modify the tool such that it considers only 6 tissues.

I changed the template which similar to the one that's already been used but with only 6 tissue components and also created firstnorm and brain edge. However, the pipeline breaks at "template deformation". The exact error message is in function "apply_def". I do not know how to debug this either.

Could you please help me on this issue and also could you please let me know if it is possible to debug like how it is normally done in MATLAB.

Thank you in advance.

Anu

richardbeare commented 3 years ago

Debugging the spm batch mechanisms is quite difficult, unfortunately. You sort of need to know which functions eventually get called by the batch infrastructure. In most cases in mantis the work is happening in files ending in _run.m, so you can load them into the matlab editor and place break points. I recall that it is fussy about whether you do that before or after running spm - you may need to experiment.

apply_def is in cg_mantis_deformations_run.m (find by grepping for names in the mantis folder), so you can stick a breakpoint there.

Places to start looking: cg_mantis_defaults.m - contains names of template images and the number of components in each - so if you update the templates, make sure you update the number of components too. i.e. reduce to 6.

We've tried to be very careful to avoid using hard coded entries anywhere, but something may have crept in - watch out for that and let us know.

It is important that the csf component in NeonateTPM stays and number 3, and the brain edge component remains the last in firstnorm, but I can't think of anywhere where the content actually matters.

Keep an eye out for more informative errors on the matlab console if none of these ideas help.

richardbeare commented 3 years ago

I remembered a couple of other places where the number of components is used, although perhaps you've already fixed these if you got as far as you described. The batch file that drives the process is mantis_complete_segmentation12.m, and it includes references to explicit channel numbers, so you will need to remove those

anurudhya commented 3 years ago

Hi, Thank you very much for the reply. I tried it and it did work. I am use fetal template and I have changed the number of tissue types. But this time, it fails in Phase 1 tissue classification. The error message says "Error using sqrtm (line 44) Matrix elements must be finite. In file "/Applications/MATLAB_R2020b.app/toolbox/matlab/matfun/sqrtm.m" (???), function "sqrtm" at line 44. In file "/Users/anu/spm12/spm_maff8.m" (v7377), function "M2P" at line 290. In file "/Users/anu/spm12/spm_maff8.m" (v7377), function "affreg" at line 118. In file "/Users/anu/spm12/spm_maff8.m" (v7377), function "spm_maff8" at line 27. In file "/Users/anu/spm12/spm_preproc_run.m" (v7670), function "run_job" at line 132. In file "/Users/anu/spm12/spm_preproc_run.m" (v7670), function "spm_preproc_run" at line 41. In file "/Users/anu/spm12/config/spm_cfg_preproc8.m" (v7629), function "spm_local_preproc_run" at line 474. "

I tried tracing the error. It looks like for some reason alpha becomes "NaN". I suppose that it is a problem with the template but I am not able to figure out exactly where and what is going wrong.

Could you please help me on this? Thank you in advance.

Anu

richardbeare commented 3 years ago

I'm not sure why the error doesn't include any references to mantis files. However this appears to be potential problem with the template. Perhaps there are "missing" voxels, either set to NA or NaN. That would be the first thing to check. fslmaths has an option to set NaN value to zero. Did you also modify mantis_complete_segmentation12, so that the number of output channels matches the template?