Back to the main page.

Bug 1651 - inconsistent binary masks in ft_volumesegment that leads to error in ft_prepare_mesh

Status CLOSED FIXED
Reported 2012-08-13 18:03:00 +0200
Modified 2012-10-29 13:44:56 +0100
Product: FieldTrip
Component: forward
Version: unspecified
Hardware: PC
Operating System: Windows
Importance: P3 normal
Assigned to: Robert Oostenveld
URL:
Tags:
Depends on: 1652
Blocks:
See also:

Lilla Magyari - 2012-08-13 18:03:03 +0200

hi, when I specify cfg.output={'brain','skull','scalp'}, it creates a brain and a scalp field where everything inside of the brain and inside of the scalp is 1, and everything outside of them is 0. But skull is a binary mask where only skull (and no voxel inside skull!) is 1. Probably, this is causing the error in ft_prepare_mesh. When I use imfill(skull,'holes') on skull before calling ft_prepare_mesh, ft_prepare_mesh works fine. We discussed it with Robert that overlapping segmentations would be most desired, so it would be nice if skull would be also a filled volume. I think it can be solved around line 479: braindil=imdilate(brain>0,strel_bol(6)); segment.skull=braindil & ~brain; Can I change it to segment.skull=imdilate(brain>0,strel_bol(6));? Lilla


Lilla Magyari - 2012-08-13 18:05:23 +0200

Created attachment 298 seg You can find the segmented mri attached.


Robert Oostenveld - 2012-08-13 18:07:08 +0200

don't change it yet. Your suggested change relies on the image processing toolbox, whereas the present implementation (I think) does not require the image toolbox but uses spm. Better check with JM when he is back. I'll assign this issue to him for the moment.


Lilla Magyari - 2012-08-14 16:44:32 +0200

(In reply to comment #2) Hi Robert, you wrote me also in an email that I should check which segmentation options are using the image processing toolbox. I have checked it, and as it is related to this bug, I report on what I have found: The default output of ft_volumesegment are the - csf, white and gray fields (tissue prob maps): only spm functions are used Other options: - brain: only spm - skullstrip: only spm - skull: spm + functions: imdilate and strel_bol (image proc toolbox) - scalp: spm + funcitons: fill (that contains imfill) (image proc tb) So, it seems to me by looking at the script of ft_volumesegment that for the segmentation that the BEM model requires the image processing toolbox is used. But when only the brainmask is needed (e.g. for singleshell, MEG), only the spm functions are used. Lilla


Robert Oostenveld - 2012-08-14 17:01:05 +0200

in that case it does not hurt to slightly extend the use of the image processing toolbox. Note that it should only be used where it is really needed, so that for standard MEG usage the image proc toolbox is not called (since not all users have the image proc toolbox).


Jan-Mathijs Schoffelen - 2012-09-14 14:19:57 +0200

reassigning to lilla...


Robert Oostenveld - 2012-09-20 21:23:03 +0200

I can confirm the problem as in cfg = []; cfg.tissue = {'brain', 'skull', 'scalp'}; cfg.numvertices = [1000 2000 3000]; bnd = ft_prepare_mesh(cfg, seg2); not downsampling brain not downsampling scalp not downsampling skull the call to "ft_volumedownsample" took 1 seconds and required the additional allocation of an estimated 0 MB using the segmentation approach using the brain segmentation using the skull segmentation using the scalp segmentation triangulating the boundary of compartment 1 Subscript indices must either be real positive integers or logicals. Error in triangulate_seg (line 110) int = seg(sel); Error in prepare_mesh_segmentation (line 94) [pnt, tri] = triangulate_seg(seg, cfg.numvertices(i), ori); Error in ft_prepare_mesh (line 127) bnd = prepare_mesh_segmentation(cfg, mri); ---- this is after running a "normal" ft_volumesegment. I'll save the segmented structure and make a test script out of it.


Robert Oostenveld - 2012-09-20 21:51:05 +0200

added some lines to triangulate_seg to catch the case where the segmentation is empty. This does not explain why it happens. The underlying cause is that the input skull is hollow, the brain and skin are solid.Subsequently the sum has K>> unique(mri.seg(:)) ans = 0 1 2 whereas the code is trying to make a mesh for 1, 2 and 3. I have added another few lines to detect the problem in prepare_mesh_segmentation and give a more useful error. Around line 43 in prepare_mesh_segmentation I changed mri.seg = mri.seg + mri.(cfg.tissue{i}); into mri.seg = mri.seg + imfill(mri.(cfg.tissue{i}), 'holes'); This allows the test case to run through. change to the code: allow ft_plot_mesh to plot multiple meshes with the same settings. ---------- mbp> svn commit private/prepare_mesh_segmentation.m test/test_bug1651* private/triangulate_seg.m plotting/ft_plot_mesh.m Sending plotting/ft_plot_mesh.m Sending private/prepare_mesh_segmentation.m Sending private/triangulate_seg.m Adding test/test_bug1651.m Adding (bin) test/test_bug1651.mat Transmitting file data .....


Robert Oostenveld - 2012-09-20 21:54:09 +0200

Created attachment 316 screenshot of skin surface with holes After fixing the specific bug, a problem that remains is that the skin triangulation is one large mess.


Robert Oostenveld - 2012-09-20 22:34:31 +0200

(In reply to comment #8) turns out that the skin (which is hollow) is too thin and that there are holes going through it. Consequently, imfill-holes does not work because the inside and outside are connected and the mesh is made on the shin shell with holes. Hmm, difficult to catch. It turns out that the problem with the holes in the skin happen with the 128^3, but not with the original 256^3 volume. Note to Lilla: the brain should have most vertices, not the skin! I have found a trick to detect the hollow segmentation by looking along the int-line. It does not solve it, but at least gives a warning: if ishollow % this should not have hapened, especially not after filling the holes warning('the segmentation is not star-shaped, please check the surface mesh'); end --------------------------------------------- mbp> svn commit private/triangulate_seg.m test/ Sending private/triangulate_seg.m Sending test/test_bug1651.m Transmitting file data .. Committed revision 6503.


Robert Oostenveld - 2012-09-20 22:37:06 +0200

the problem with the error has been resolved. The 128^3 test case still results in an ugly skin mesh, but that is because the segmentation is too coarse. On the 256^3 test case (see attached file, not included in the test script) it works fine.


Lilla Magyari - 2012-09-21 09:49:22 +0200

(In reply to comment #10) Hi Robert, the differences between 128^3 and 256^3 are interesting. Should we say something about the suggested size of an mri volume for segmentation in the help or FAQ or tutorial? Is it possible to solve this issue if people re-slice their volume before segmentation? Lilla


Robert Oostenveld - 2012-10-29 13:44:56 +0100

changed the status of several bugs that were RESOLVED some time ago to CLOSED