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
We are trying to parallelize coregistrations of large time series of images, but we are running into an error when we pass parameter objects to the functions.
Here is a simple code example that reproduces the issue:
importosimportmultiprocessingimportnumpyasnpimportitk# Define a function that coregisters two images with a given parameter object:defcoregister(args):
fixed, moving, param_obj=argscoregistered, _=itk.elastix_registration_method(
itk.GetImageFromArray(fixed),
itk.GetImageFromArray(moving),
parameter_object=param_obj)
returnitk.GetArrayFromImage(coregistered)
if__name__=="__main__":
# Create two time seriesnt=2# Note in real-world examples this would be in the 100'sfixed=np.zeros((128,128,nt), dtype=np.float32)
moving=np.zeros((128,128,nt), dtype=np.float32)
# Generate a parameter objectparam_obj=itk.ParameterObject.New()
bspline=param_obj.GetDefaultParameterMap('bspline')
param_obj.AddParameterMap(bspline)
# Build a list of argumentsargs= [(fixed[:,:,t], moving[:,:,t], param_obj) fortinrange(nt)]
# Process them in parallel using the coregister functionpool=multiprocessing.Pool(processes=os.cpu_count())
coreg=pool.map(coregister, args)
This generates a type error:
TypeError: cannotpickle'SwigPyObject'object
A workaround is to pass the elastix parameters to the coregister() function as a dictionary, and then generate the parameter object inside the coregister() function. However, the function itk.ParameterObject.New() is so slow that this completely offsets any benefits of the parallellization.
Do you have a better solution? Many thanks for any help you are able to give..
The text was updated successfully, but these errors were encountered:
Hi,
We are trying to parallelize coregistrations of large time series of images, but we are running into an error when we pass parameter objects to the functions.
Here is a simple code example that reproduces the issue:
This generates a type error:
A workaround is to pass the elastix parameters to the
coregister()
function as a dictionary, and then generate the parameter object inside thecoregister()
function. However, the functionitk.ParameterObject.New()
is so slow that this completely offsets any benefits of the parallellization.Do you have a better solution? Many thanks for any help you are able to give..
The text was updated successfully, but these errors were encountered: