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: initialize ANTsImage with pointer only #634

Closed ncullen93 closed 1 month ago

ncullen93 commented 1 month ago

Currently, you have to manually input a bunch of extra information when creating an ANTsImage internally from an ITK pointer, e.g.:

img = iio.ANTsImage(pixeltype='float', dimension=2, components=1, pointer=itk_image)

Information such as pixeltype, dimension, components, is_rgb, etc is not only redundant to what is contained in the pointer, it is also vulnerable to bugs because it is not coupled to the one source of truth (the pointer to the actual image). If someone input the wrong dimension.. it would not be caught.

This PR makes it so ANTsImage instances are created from only the pointer and all that extra info is extracted from the pointer. It is more robust and also makes it eventually easier to refactor the internal import system. The above line would be replaced with this:

img = iio2.from_pointer(itk_image)

All of the info is still available as usual - no changes there.

coveralls commented 1 month ago

Coverage Status

coverage: 80.907% (+0.07%) from 80.836% when pulling 264c0ef2881d75bd00115d8b23f6dd1b55461316 on image-from-pointer into 75f73923702aed09bcc07a328c10f66ad0ed3e01 on master.