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

ENH: support resampling multi-channel images #609

Closed ncullen93 closed 2 months ago

ncullen93 commented 2 months ago

This PR adds support for multi-channel images in resample_image. The docstring says it's supported and there has pretty much always been an exception raised for multi-channel, so I think I just never got around to implementing it.

This implementation is the simplest - it just splits the channels and resamples on each of them individually. I think the ants function ResampleImage supports vector images natively, so that may be preferred in the future.

coveralls commented 2 months ago

Coverage Status

coverage: 55.357% (+0.1%) from 55.245% when pulling 6f4fa76f2d5d9168106b234ad7a25d00532f487c on resample-channels into 54ec16ef994273b409207628b56ba7ab3c825383 on master.

cookpa commented 2 months ago

ANTs ResampleImage is templated over dimension so it will work for 3D images or 4D time series. Your approach of resampling each channel separately makes more sense for actual multi-channel images, and things like DWI data that are sometimes stored on disk as time series, but where it does not really make sense to interpolate along the fourth dimension.

I don't know how best to harmonize these things, in antsApplyTransforms we have different codes for 4D (time series) or 5D (vectors / tensors / generic multi-channel with 3 spatial dimensions and single time value).

cookpa commented 2 months ago

Looking at the function I think it might actually be good, becuase antspy will recognize components in a 5D image, and if components is >1 then it calls the new code, and if components is 1 it will call ResampleImage which already works for time series.

ncullen93 commented 2 months ago

OK - thanks for the input. I will merge but feel free to open an issue in the future if needed and I will change it.