You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm looking to save transforms in the same HDF5 file that contains my data, but in a different data group (so I can keep them together, share it as a single file, etc.).
Currently I'm building a workaround similar to that descibed in issue 318 but with nibabel in the middle
importants, h5py, nibabelreg=ants.registration( ants.image_read( ants.get_data("r16" ) ), ants.image_read( ants.get_data("r16" ) ), 'SyN')
# Saving Transformelastic_ni=nibabel.load(reg['fwdtransforms'][0])
withh5py.File("mydata.h5", "a") asmy_h5:
transform_group=my_h5.create_group("ants_transforms")
elastic_group=transform_group.create_group('elastic')
elastic_group.create_dataset("fdata", data=elastic_ni..get_fdata())
elastic_group.create_dataset("affine", data=elastic_ni.affine)
# EDIT: Some extra stuff needs to come in for the header too...## Loading Transform# instead of image_read, I can use nibabel to create a spatial image # warp=ants.image_read( reg['fwdtransforms'][0] ) # image not transformwithh5.File("mydata.h5", "r") asmy_h5:
nibabel_header=nibabel.Nifti1Header()
forkeyinnibabel_header.keys():
# ... populate header herewarp=ants.from_nibabel(
nibabel.spatialimages.SpatialImage(
dataobj=my_h5['ants_transforms']['elastic']['fdata'],
affine=my_h5['ants_transforms']['elastic']['affine'],
header=nibabel_header))
warptx=ants.transform_from_displacement_field( warp )
However,
this process is slow;
the use of nibabel seems excessive but I can't determine how to construct an ANTsTransform directly from the data in the 'fwdtransforms'][0] file; and
I'm not sure if I'm missing cases where the fdata and affine values are insufficient to describe a transform.
I also need to do a similar, but different, procedure for saving and loading the .mat affine transforms.
Would it be possible to save transforms as HDF5 file groups and load them directly? Something like,
I'm looking to save transforms in the same HDF5 file that contains my data, but in a different data group (so I can keep them together, share it as a single file, etc.).
Currently I'm building a workaround similar to that descibed in issue 318 but with nibabel in the middle
However,
ANTsTransform
directly from the data in the'fwdtransforms'][0]
file; andfdata
andaffine
values are insufficient to describe a transform.I also need to do a similar, but different, procedure for saving and loading the
.mat
affine transforms.Would it be possible to save transforms as HDF5 file groups and load them directly? Something like,
The text was updated successfully, but these errors were encountered: