1

我想知道是否可以使用两个二进制掩码(每个图像一个)使用 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)

我希望有人能帮忙!

4

2 回答 2

0

是的。您可以通过此代码 Newfixed=fixed fixedmask; newmoving=移动移动蒙版

并使用 newfixed 和 d newmoving 进行注册

于 2017-03-26T17:39:07.460 回答
-1

我知道你可以在 ITK 中做到这一点,但我不确定在 Simple ITK 中是否可行。它可能不具备 ITK 的所有功能。

在 C++ 实现中,您可以执行以下操作:

int Dimension = 3;
typedef itk::ImageMaskSpatialObject< Dimension > MaskObjectType;

itk::NormalizedMutualInformationHistogramImageToImageMetric<ImageType, ImageType> NMIMetricType;

NMIMetricType::Pointer nmiMetric = NMIMetricType::New();

// fixedImageMask is a pointer to a binary ITK image
// ITK ignores pixels that are 0 and only uses non-zero pixels
fixedMaskObject->SetImage( fixedImageMask ); 

nmiMetric->SetFixedImageMask(fixedMaskObject.GetPointer()); //fixedMaskObject is a MaskObjectType
于 2015-09-15T00:42:16.013 回答