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 pickle and deepcopy for images #658

Closed ncullen93 closed 1 month ago

ncullen93 commented 1 month ago

It was previously not possible to pickle ants images, so things like deepcopy failed. This PR adds basic pickle support via numpy. I had some random segfaults in some early versions of this PR but I believe the current version works well... something to keep an eye on anyways.

Example:

import ants
import pickle
import numpy as np
from copy import deepcopy

img = ants.image_read( ants.get_ants_data("r16"))
img_pickled = pickle.dumps(img)
img2 = pickle.loads(img_pickled)
img3 = deepcopy(img)
img += 10
print(img.mean(), img2.mean())
print(img.mean(), img3.mean())
coveralls commented 1 month ago

Coverage Status

coverage: 81.373% (+0.02%) from 81.352% when pulling d96a99774a01dd1c328fa148519d1c16dd767261 on pickle-images into 6d99b60464e69bd17a1e5de5b901d814222da97b on master.