siibra-python
siibra-python copied to clipboard
[bug] spatial props for bundle atlas not calculated correctly
as of v0.3a11
the spatial props calculated for regions such as lh_PoCi-PrCu_1 can be misleading, due to the concaved geometry of the probabilistic map:

This is not suprising, since we just compute the mean. The mean is certainly not a very good choice for fibrre bundles - we might choose the closest point to the mean which is inside the structure.
Alternative suggestion: "Find the pixel with the highest closeness centrality. Closeness centrality is the inverse of the total sum of shortest distances from a node to every other node." (see https://scikit-image.org/docs/stable/auto_examples/applications/plot_pixel_graphs.html)
from time import time
import skimage as ski
import siibra
from nibabel import Nifti1Image
import numpy as np
def calculate_graph_center(img: Nifti1Image):
mask_arr = np.asanyarray(img.dataobj > 0, dtype='uint8')
skeleton = ski.morphology.skeletonize(mask_arr )
g, nodes = ski.graph.pixel_graph(skeleton, connectivity=2)
px, distances = ski.graph.central_pixel(g, nodes=nodes, shape=skeleton.shape, partition_size=100)
return np.dot(img.affine, np.concatenate((px, [1])))[:3]
img = siibra.get_region("Superficial fibre bundles", "lh_PoCi-PrCu_1").get_regional_mask("mni 152").fetch()
s = time()
center = calculate_graph_center(img)
print(time() - s)
print(center)