Я хотел бы знать, возможно ли использовать две бинарные маски (по одной для каждого изображения) для регистрации двух изображений с помощью Simple ITK?
Действительно, мне нужно зарегистрировать 2 изображения, которые уже имеют географическую привязку (пиксели, не содержащие данных, заполнены «0»), но где ошибка проекции все еще существует.
Итак, я хочу использовать только пиксели, значения маски которых равны «1» при вычислении метрики сходства.
Вот мой фрагмент кода:
fixed = sitk.ReadImage('#######/imgRef.png', sitk.sitkFloat32);
moving = sitk.ReadImage('#######/imgRep.png', sitk.sitkFloat32)
maskFixed = sitk.ReadImage('#######/maskRef.png', sitk.sitkUInt8)
maskMoving= sitk.ReadImage('#######/maskRep.png', sitk.sitkUInt8)
# Handle optimizer
R = sitk.ImageRegistrationMethod()
# Restrict the evaluation of the similarity metric thanks to masks
R.SetMetricFixedMask(maskFixed)
R.SetMetricMovingMask(maskMoving)
# Set metric as mutual information using joint histogram
R.SetMetricAsMattesMutualInformation(numberOfHistogramBins=255)
# Gradient descent optimizer
R.SetOptimizerAsRegularStepGradientDescent(learningRate=0.01, minStep=1e-5, numberOfIterations=100, gradientMagnitudeTolerance=1e-8)
#R.SetOptimizerScalesFromPhysicalShift()
R.SetMetricSamplingStrategy(R.REGULAR) #R.RANDOM
# Define the transformation (Rigid body here)
transfo = sitk.CenteredTransformInitializer(fixed, moving, sitk.Euler2DTransform())
R.SetInitialTransform(transfo)
# Define interpolation method
R.SetInterpolator(sitk.sitkLinear)
# Add command to the registration process
R.AddCommand(sitk.sitkIterationEvent, lambda: command_iteration(R))
R.AddCommand(sitk.sitkStartEvent, lambda: start_plot())
R.AddCommand(sitk.sitkEndEvent, lambda: end_plot())
R.AddCommand(sitk.sitkIterationEvent, lambda: current_plot(R))
# Perform registration
outTx = R.Execute(fixed, moving)
print(outTx)
print("--------")
print("Optimizer stop condition: {0}".format(R.GetOptimizerStopConditionDescription()))
print("Number of iterations: {0}".format(R.GetOptimizerIteration()))
print("--------")
# Perform transformation and resample the moving image
# Save transformation as tfm file
sitk.WriteTransform(outTx, '/home/egs/f_nicolas/CODES_THESE/transfo_final.tfm')
#sitk.Show(transfo.GetDisplacementField(),"Displacement field")
# Resample moving image according to the last transformation
resampler = sitk.ResampleImageFilter()
resampler.SetReferenceImage(fixed)
resampler.SetInterpolator(sitk.sitkLinear)
#resampler.SetDefaultPixelValue(100)
resampler.SetTransform(outTx)
out = resampler.Execute(moving)
Я надеюсь, что кто-то может помочь!