python question


(wangfeng) #1

I have a C++ example,but I can not run this in Python. Help me ,please !
[C++]


typedef RegistrationType::ParametersType ParametersType;
ParametersType initialParameters( transform->GetNumberOfParameters() );

initialParameters[0] = 0.0; // Initial offset in mm along X
initialParameters[1] = 0.0; // Initial offset in mm along Y

registration->SetInitialTransformParameters( initialParameters );

[Python-codes:]
initialParameters = [0.0 for i in range(transform.GetNumberOfParameters())]
registration.SetInitialTransformParameters(initialParameters)

[Error-informations:]
—> registration.SetInitialTransformParameters(initialParameters)
TypeError: in method ‘itkImageRegistrationMethodIF2IF2_SetInitialTransformParameters’, argument 2 of type ‘itkOptimizerParametersD const &’


(Matt McCormick) #2

Hi @wangfeng,

Try,

initialParameters = itk.OptimizerParameters[itk.D](transform.GetNumberOfParameters())
initialParameters[0] = 0.0
initialParameters[1] = 0.0
# or
initialParameters.Fill(0.0)

HTH,
Matt


(wangfeng) #3

Hi,@Matt
Thank you very much.Thank you for your help.:grinning: