layerfMRI/LAYNII

Add 1st order neighbour finder program LN2_NEIGHBORS

ofgulban opened this issue · 2 comments

It seems that a voxel space based neighbor finder for irregularly spaced parcels might be a generally useful tool (suggested by @layerfMRI ). I am convinced that it might be useful especially to play along with LN2_COLUMNS, LN2_HEXBIN, and LN2_IFPOINTS programs.

I have added LN2_NEIGHBORS program (currently experimental). This programs finds the first order neighbors of each unique label. Currently the output shows:

  Unique labels: [ 1 2 3 4 5 6 7 8 9 10 ]
  Number of unique labels: 10
  Start finding neighbors (3-jump neighbourhood)...
  Label 1 neighbors: 5 6 8 9 
  Label 2 neighbors: 6 7 
  Label 3 neighbors: 5 6 10 
  Label 4 neighbors: 7 8 9 
  Label 5 neighbors: 1 3 6 
  Label 6 neighbors: 1 2 3 5 7 8 10 
  Label 7 neighbors: 2 4 6 8 
  Label 8 neighbors: 1 4 6 7 9 
  Label 9 neighbors: 1 4 8 
  Label 10 neighbors: 3 6 

Probably, it would be best to export the information to a txt or csv file. @layerfMRI do you have any preferences?

@layerfMRI , the initial implementation is done. Give it a test ride and see how it feels.

I have decided to have the default output as a CSV file. This file is very lightweight and easy to load as a table in e.g. excel:
Screenshot_2023-03-23_19-52-34
Each label can have a varying amount of neighbors and this is expected.

In addition, I have added -export_nifti flag to give users the option to export the label neighborhood information voxel-by-voxel. This nifti runs the risk of being very large if one of the labels have substantially more neighbors than others. Therefore, this option is off by default.