# registration fixed_image = sitk.VectorIndexSelectionCast(fixed_rgb, 1) moving_image = sitk.VectorIndexSelectionCast(moving_rgb, 1) fixed_image = sitk.Cast(fixed_image, sitk.sitkFloat32) moving_image = sitk.Cast(moving_image, sitk.sitkFloat32) def command_iteration(method): if (method.GetOptimizerIteration() == 0): print("Estimated Scales: ", method.GetOptimizerScales()) print(f"{method.GetOptimizerIteration():3} = {method.GetMetricValue():7.5f} : {method.GetOptimizerPosition()}") pixelType = sitk.sitkFloat32 R = sitk.ImageRegistrationMethod() R.SetMetricAsCorrelation()#Use negative normalized cross correlation image metric. R.SetOptimizerAsRegularStepGradientDescent(learningRate=4.0, minStep=0.1, numberOfIterations=5000, gradientMagnitudeTolerance=1e-8)#Regular Step Gradient descent optimizer. R.SetOptimizerScalesFromIndexShift()#Estimate scales from maximum voxel shift in index space cause by parameter change. tx = sitk.CenteredTransformInitializer(fixed_image, moving_image, sitk.Similarity2DTransform()) R.SetInitialTransform(tx) R.SetInterpolator(sitk.sitkLinear) R.AddCommand(sitk.sitkIterationEvent, lambda: command_iteration(R)) outTx = R.Execute(fixed_image, moving_image) print("-------") print(outTx) print(f"Optimizer stop condition: {R.GetOptimizerStopConditionDescription()}") print(f" Iteration: {R.GetOptimizerIteration()}") print(f" Metric value: {R.GetMetricValue()}") resampler = sitk.ResampleImageFilter() resampler.SetReferenceImage(fixed_image) resampler.SetInterpolator(sitk.sitkLinear) resampler.SetDefaultPixelValue(1) resampler.SetTransform(outTx) out = resampler.Execute(moving_image) simg1 = sitk.Cast(sitk.RescaleIntensity(fixed_image), sitk.sitkUInt8) simg2 = sitk.Cast(sitk.RescaleIntensity(out), sitk.sitkUInt8) cimg = sitk.Compose(simg1, simg2, simg1 // 2. + simg2 // 2.) myshow(cimg)在这段代码中找到调整步长的地方
时间: 2024-03-22 14:37:25 浏览: 261
在这段代码中,调整步长的地方是在设置优化器时,使用了`SetOptimizerAsRegularStepGradientDescent`函数,并设置了`learningRate`参数为4.0,`minStep`参数为0.1。可以看出,这里使用的是固定步长的梯度下降优化器。具体代码如下:
```
R.SetOptimizerAsRegularStepGradientDescent(learningRate=4.0, minStep=0.1, numberOfIterations=5000, gradientMagnitudeTolerance=1e-8)
```
阅读全文