Back to the main page.

Bug 89 - use bwlabeln from spm8 as alternative to image processing toolbox

Status CLOSED FIXED
Reported 2010-06-09 13:37:00 +0200
Modified 2011-02-23 13:51:06 +0100
Product: FieldTrip
Component: core
Version: unspecified
Hardware: PC
Operating System: Windows
Importance: P1 enhancement
Assigned to: Arjen Stolk
URL:
Tags:
Depends on:
Blocks:
See also:

Robert Oostenveld - 2010-06-09 13:37:16 +0200

see email from Andrea on mailing list


Roemer van der Meij - 2010-06-09 16:24:13 +0200

Mail from Andrea: ************ Dear Fieldtrip team, If I understand the notes on the development page right, you have switched from SPM2 to SPM8 and are currently working on the integration with Fieldtrip. Could you perhaps add an entry in the to-do list? I believe that if you allowed for the use of spm_bwlabel instead of bwlabeln if the latter is not available, one could use some of your statistics options even without the MATLAB Statistics toolbox. (For my purposes, for example, a few modifications in findcluster and clusterstat would be sufficient.) A nice day to all of you! All the best Andrea ************


Roemer van der Meij - 2010-06-22 12:11:16 +0200

A follow up e-mail from Andrea with some helpful suggestions. ************ Dear Roemer, Thanks a lot. I discussed this topic some months ago with Robert and he suggested that he/the Fieldtrip team could modify the code along the following lines (I copy this from his e-mail because I think he will not mind this) - - - - - I suggest to modify the low level code into two helper functions (findcluster_chanlevel and findcluster_sourcelevel), which both should check like this if hastoolbox('image', 1) % using image processing toolbox my_bwlabeln = @bwlabeln; elseif hastoolbox('spm8', 1) % using spm8 version my_bwlabeln = @spm8_bwlabeln; else error(...) end - - - - I have got SPM8 on my Matlab path and whenever I download a new Fieldtrip version, I have to edit clusterstat and findcluster because it is (or was) not sufficient to simply replace bwlabeln by spm_bwlabel. What I did is probably rather inelegant but I left it that way since it works: In findcluster: Before: % [labelmat(spatdimlev, :, :), num] = bwlabeln(reshape(onoff(spatdimlev, :, :), nfreq, ntime), 4); After: input_for_spm_bwlabel = reshape(onoff(spatdimlev, :, :), nfreq, ntime); input_for_spm_bwlabel = +input_for_spm_bwlabel; %convert from logical [labelmat(spatdimlev, :, :), num] = spm_bwlabel(input_for_spm_bwlabel , 6); In clusterstat: Before: %!!!posclusobs = bwlabeln(tmp, conndef(length(cfg.dim),'min')); After: [posclusobs,L] = spm_bwlabel(tmp, 6); All the best Andrea ************


Robert Oostenveld - 2010-12-01 16:09:12 +0100

this is on the request list for a long time and a good suggestion. It requires carefull checking of the (hopefully) drop-in replacement.


Arjen Stolk - 2011-02-02 15:25:30 +0100

Private/clusterstat calls bwlabeln 4 times and private/findcluster calls it once. Clusterstat calls findcluster. to do: - split findcluster into findcluster_chanlevel and findcluster_sourcelevel - insert in these functions the following check if hastoolbox('image', 1) % using image processing toolbox my_bwlabeln = @bwlabeln; elseif hastoolbox('spm8', 1) % using spm8 version my_bwlabeln = @spm_bwlabel; else error(...) end - replace bwlabeln calls with my_bwlabeln - Additional mismatch that needs to be checked: Findcluster is supposed to return clusters with a connectivity of 6. But in the code parameter '4' is given bwlabeln.


Arjen Stolk - 2011-02-10 12:32:44 +0100

So the implementation is now as follows. The function has yet not been teared apart into two separate function for source and sensor level. Rather the calls to bwlabeln have been removed where possible (<4 dimensions) and been replaced by spm_bwlabel to reduce usage of the image toolbox. clusterstat (sourcelevel): if length(cfg.dim) == 3 [output1, output2] = spm_bwlabel(tmp, 6) else output1 = bwlabeln (tmp, something) end This used to be the lower call incl bwlabeln only. findcluster(sensorlevel): [output1, output2 = spm_bwlabel(double(input), 6); This used to be: [output1, output2 = spm_bwlabel(input, 4);


Robert Oostenveld - 2011-02-23 13:51:06 +0100

I closed all bugs that were in the RESOLVED/FIXED or otherwise RESOLVED state.