siibra-python icon indicating copy to clipboard operation
siibra-python copied to clipboard

[bug] spatial props for bundle atlas not calculated correctly

Open xgui3783 opened this issue 3 years ago • 2 comments

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: image002

xgui3783 avatar Feb 14 '22 14:02 xgui3783

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.

dickscheid avatar Feb 14 '22 18:02 dickscheid

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)

Image

AhmetNSimsek avatar Feb 12 '25 14:02 AhmetNSimsek