Nilearn: vol_to_surf sample location ot of bounds

Created on 11 Jul 2019  路  7Comments  路  Source: nilearn/nilearn

Hi !

I'm trying to use vol_to_surf to project a parcellation on a surface.
I'm facing an issue when I add a mask to filter the sampling locations.

Here is the error I get:

~/anaconda3/lib/python3.6/site-packages/nilearn/surface/surface.py in vol_to_surf(img, surf_mesh, radius, interpolation, kind, n_samples, mask_img)
    509     texture = sampling(
    510         frames, mesh, img.affine, radius=radius, kind=kind,
--> 511         n_points=n_samples, mask=mask)
    512     if original_dimension == 3:
    513         texture = texture[0]

~/anaconda3/lib/python3.6/site-packages/nilearn/surface/surface.py in _interpolation_sampling(images, mesh, affine, kind, radius, n_points, mask)
    362     grid = [np.arange(size) for size in images[0].shape]
    363     interp_locations = np.vstack(sample_locations)
--> 364     masked = _masked_indices(interp_locations, images[0].shape, mask=mask)
    365     # loop over images rather than building a big array to use less memory
    366     all_samples = []

~/anaconda3/lib/python3.6/site-packages/nilearn/surface/surface.py in _masked_indices(sample_locations, img_shape, mask)
    237         indices = np.asarray(np.round(sample_locations[kept]), dtype=int)
    238         kept[kept] = mask[
--> 239             indices[:, 0], indices[:, 1], indices[:, 2]] != 0
    240     return ~kept
    241 

IndexError: index 190 is out of bounds for axis 1 with size 190

From what I saw the error pops up because one of the sample location on axis 1 happens to take for value 189.9 which is then rounded up to 190 (line 237) and is out of bound of my matrix (of size 190 on axis 1). Switching np.round to np.floor fixed the issue however I'm not sure if it's the solution or if I'm using the function somehow wrong ?

Anyway thanks for the very handy functions !
C茅line

All 7 comments

thanks for reporting this!
I think you are right about what caused the error and the solution you suggest sounds good, do you want to open a pull request?

Honestly I don't really know how the pull requests work, if you don't mind I would rather let you do it.
Thanks for your answer !

Hey @celinede Thanks for helping us. We can walk you step by step, how to do a Pull Request. It seems a little involved the first time but for a small change like this it is pretty simple.
We'll be here every step of the way.

If you do not wish to do this, for any reason, that's fine as well.

ok ! I'll follow your guidelines

  • on the nilearn repo page on github (https://github.com/nilearn/nilearn), click
    on "fork" on the top right to create your own fork of nilearn.

  • clone your fork:

  $ git clone https://github.com/celinede/nilearn.git
  • create the branch you will be working on:
  $ cd nilearn
  $ git checkout -b "fix_issue_2082"
  • edit the surface.py file as you suggested to fix the bug.
  • commit your changes:
  $ git add nilearn/surface/surface.py
  $ git commit -m "fix 2082: vol_to_surf samples out of image"
  • push this new branch to your fork of nilearn:
  $ git push --set-upstream origin fix_issue_2082
  • visit your nilearn fork on github
    (https://github.com/celinede/nilearn/tree/fix_issue_2082) and click "compare & pull request".

don't hesitate to ask or visit the git or github help if you have any questions!
also, if you don't have time to do this don't worry, we can do it as well.

Just wanted to +1 @jeromedockes 's walk-through ! I also quite like this one from the GitHub guides, if you want a few more graphics: https://guides.github.com/activities/forking/

fixed in #2089

Was this page helpful?
0 / 5 - 0 ratings

Related issues

NicolasGensollen picture NicolasGensollen  路  4Comments

JohannesWiesner picture JohannesWiesner  路  6Comments

rhodricusack picture rhodricusack  路  3Comments

tsalo picture tsalo  路  3Comments

nilover picture nilover  路  7Comments