ANTsX / ANTsPy

A fast medical imaging analysis library in Python with algorithms for registration, segmentation, and more.
https://antspyx.readthedocs.io
Apache License 2.0
586 stars 161 forks source link

small utilities related to time-series quality assessment #594

Open stnava opened 3 months ago

stnava commented 3 months ago

These are notes about some utilities that would be useful.


time_series_slice(  img_4d ,   pythonic placeholders for axes to sweep over )

probably just a wrapper for slice_image .... more important would be the display of the slice with some relevant annotation. would be something like :

>>> img=ants.image_read("timeseries.nii.gz")
>>> img
ANTsImage
     Pixel Type : float (float32)
     Components : 1
     Dimensions : (90, 104, 72, 420)
     Spacing    : (2.0, 2.0, 2.0, 0.72)
     Origin     : (-90.4777, 30.0725, -58.2543, 0.0)
     Direction  : [ 0.9998  0.0206 -0.0087  0.      0.0219 -0.9783  0.206   0.      0.0043
  0.2061  0.9785  0.      0.      0.      0.      1.    ]

>>> sv1=ants.slice_image(img,1,50)
>>> sv2=ants.slice_image( sv1,0,40)

then add some information about similarity, distortion and/or motion. see below.


time_series_metric(  img_4d, optional img_3d , other_params )

if img_3d is present, assess similarity with next neighbor. otherwise similarity against the reference. returns a numpy array (?)

ncullen93 commented 3 months ago

For the first part - it would be nice to do that with the already supported standard numpy-like indexing (e.g. img[:, 1:50, :, :]) but then an env var or something would be needed to determine whether you want numpy-like slicing to return ants images or arrays. So a general slice function makes sense.

Second part - I can definitely see the utility in adding a ants.metrics sub-module that provides an interface to calculating all types of image similarity metrics.

It would be more pythonic and explicit to have each metric be its own function rather than as a string argument to a general function.

e.g. prefer explicit discovery of metrics:

from ants.metrics import metric1, metric2
result1 = metric1(img1, img2)
result2 = metric2(img1, img2)

instead of:

from ants.metrics import calculate_metric
result1 = calculate_metric(img1, img2, 'metric1')
result2 = calculate_metric(img1, img2, 'metric2')