Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Saving and Loading Paramter files to reapply transfomr #251

Closed
haidermri opened this issue Oct 2, 2023 · 2 comments
Closed

Saving and Loading Paramter files to reapply transfomr #251

haidermri opened this issue Oct 2, 2023 · 2 comments

Comments

@haidermri
Copy link

I would like to save a parameter map file and then load it later to reapply a transform to other move images

I am having figuring out how to do this

Here is how the file to be saved (transfn) is created:
registered_image, params = itk.elastix_registration_method(fixed_image, moving_image,
parameter_object=parameter_object,
log_to_console=False)
parameter_map = params.GetParameterMap(0)
params.WriteParameterFile(parameter_map,transfn)

When I try to load transfn and apply it later using:

        par_obj1 = itk.ParameterObject.New()
        trparams= par_obj1.ReadParameterFile(transfn)
        registered_image = itk.transformix_filter(anothermoveingimage,par_obj1)
        finalmove = itk.GetArrayFromImage(registered_image)

I get the error
File "", line 138, in fCoregwithMask
finalmove = itk.GetArrayFromImage(registered_image)
File "", line 335, in GetArrayFromImage
return _GetArrayFromImage(
File "C:\miniconda3\envs\nnunetv2\lib\site-packages\itk\support\extras.py", line 314, in _GetArrayFromImage
raise RuntimeError("No suitable template parameter can be found.")

registered image has the following shape and type
(264, 289, 86)
<class 'itk.itkPyBufferPython.NDArrayITKBase'>

@thewtex
Copy link
Member

thewtex commented Oct 2, 2023

Hi,

Are you using the recently released itk-elastix 0.19.0? If not, please upgrade.

What is print(registered_image) and print(type(registered_image))?

@haidermri
Copy link
Author

I ma running 0.180
I will update. Thanks

This ended up working without an update
finalmove = np.asarray(registered_image)
instead of
itk.GetArrayFromImage(registered_image)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants