how to re-load a previously computed affine transform?

I'm computing affine transforms for co-registering anatomical MRI scans. Sometimes I would like to re-use those transforms, so in a case similar to the example here https://dipy.org/documentation/1.2.0./examples_built/affine_registration_3d/... my final transform is the result of this command: rigid = affreg.optimize ( static, moving, transform, params0, static_affine, moving_affine, starting_affine = translation.affine ); final = rigid; after first having aligned the centres of gravity. After this command I can call resampled = final.transform ( moving ); and then I get the desired result. What I don't understand is how to store the transform and re-use it later. I have tried to just save the object 'final' with np.savez ( 'transformation.npz', final ); and then load it later with with np.load ( 'transformation.npz', allow_pickle = True ) as npzfile: final = npzfile [ 'arr_0' ]; and then re-run resampled = final.transform ( moving ); but that returns the following error: resampled = final.transform ( moving ); AttributeError: 'numpy.ndarray' object has no attribute 'transform' So what I understand from this is that the output 'rigid' from the affreg.optimize() command has an attribute 'transform', but when I save it and then load it again it does not any more. Is there a(nother) way to save and (re)load transforms? Many thanks Alle Meije

This is probably the problem! Before saving: IPdb [8]: type(final) <class 'dipy.align.imaffine.AffineMap'> After saving and loading: IPdb [9]: with np.load ( tf_filename, allow_pickle = True ) as npzfile: ...: final = npzfile [ 'arr_0' ]; IPdb [10]: type(final) <class 'numpy.ndarray'> So if I use numpy to save the 'final', it only stores the affine matrix (by the look of it), where the original 'final' is an object with members: -- affine -- affine_inv -- codomain_grid2world -- codomain_shape -- domain_grid2world -- domain_shape -- get_affine -- set_affine -- transform -- transform_inverse Is there a way to save and retrieve those?

This is probably the problem! Before saving: IPdb [8]: type(final) <class 'dipy.align.imaffine.AffineMap'> After saving and loading: IPdb [9]: with np.load ( tf_filename, allow_pickle = True ) as npzfile: ...: final = npzfile [ 'arr_0' ]; IPdb [10]: type(final) <class 'numpy.ndarray'> So if I use numpy to save the 'final', it only stores the affine matrix (by the look of it), where the original 'final' is an object with members: -- affine -- affine_inv -- codomain_grid2world -- codomain_shape -- domain_grid2world -- domain_shape -- get_affine -- set_affine -- transform -- transform_inverse Is there a way to save and retrieve those?
participants (1)
-
a.m.wink@gmail.com