ins-amu / scripts

prepare data for TVB
MIT License
23 stars 12 forks source link

"Matrix dimenions must agree" in split_volume #41

Closed maedoc closed 5 years ago

maedoc commented 9 years ago
Starting recursion for region 27
Error using -
Matrix dimensions must agree.

Error in split_volume (line 57)
dist(:,2)=((repmat(coor(ind2,:),length(ind),1)-coor).^2)*[1;1;1];

Error in recursive_split (line 8)
    [a,b]=split_volume(vol);

Error in recursive_split (line 9)
    cell_ind1=recursive_split(a,cell_ind,k,K);

Error in subparcel (line 123)
    [cell_ind]=recursive_split(data_curr,cell_ind,k,K);

Error in run (line 63)
evalin('caller', [script ';']);
maedoc commented 9 years ago
57  dist(:,2)=((repmat(coor(ind2,:),length(ind),1)-coor).^2)*[1;1;1];
K>> whos
  Name            Size                  Bytes  Class     Attributes

  a1              1x1                       8  double              
  b1              1x1                       8  double              
  c1              1x1                       8  double              
  coor            1x3                      24  double              
  curr_max        1x1                       8  double              
  dist            1x2                      16  double              
  i               1x1                       8  double              
  ind             1x1                       8  double              
  ind1            1x1                       8  double              
  ind2            0x0                       0  double              
  ind_max         1x1                       8  double              
  ind_surf        1x2                      16  double              
  max_val         1x1                       8  double              
  pair            1x2                      16  double              
  sz              1x3                      24  double              
  vol           126x114x69            7928928  double 

ind2 is 0x0..

maedoc commented 9 years ago
K>> pair

pair =

      667111      681475

K>> ind

ind =

      667111

K>> ind2=find(pair(2)==ind)

ind2 =

     []
maedoc commented 9 years ago

ah, the problem appears to begin with vol,

K>> find(vol)

ans =

      667111
      681475
maedoc commented 9 years ago

When I move up the callstack (in the recursive algorithm) back to subparcel, I finally see length(find(vol))==13428, but below that vol only has 1 or 2 non-zeros, which seems to be the source of the problem.

timpx commented 9 years ago

I hate this one. I already got it several times, it seems to be related to the fact the brain is not entirely in the MRI volume, as it is sometimes the case in Marseille DTI data. A temporary fix I tried that worked sometimes was to put 0 everywhere on the border line ( 8f0bafbf085 in subparcel.m). The problem is that it goes into the subdivision algorithm that I didn't wrote, so I would have to go into that.

maedoc commented 9 years ago

I have the commit that add zeros.. we can discuss the algo this afternoon?

timpx commented 9 years ago

yep

maedoc commented 9 years ago

After understanding the algorithm a little better, I am wondering if the single voxel split is due to non-contiguous region?

In any case, I'd prefer using a k-means with k depending on preferring subdivision size, if that would be reasonable. An advantage would be no recursion and in the config, one could specify a target subparcel area instead of a number of subdivisions.

What do you think?

maedoc commented 9 years ago

I realized that a simple k-means on voxel positions won't work because the subparcels should reflect the cortical folding. Any chance we could form the subparcels on the surface parcellation instead of the volumetric? Otherwise we can use a clustering method like affinity propagation or DBSCAN which would follow the folds in the volume.

timpx commented 5 years ago

New volumetric subparcellation scheme.