2015-09-14 34 views
0

我想知道是否可以使用兩個二進制蒙版(每個圖像一個)使用Simple ITK註冊兩個圖像?是否可以在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) 

我希望有人能夠幫助!

+0

爲什麼你認爲它不工作?你能分享你的數據嗎?什麼是輸出? – blowekamp

回答

-1

我知道你可以在ITK中做到這一點,但我不確定在簡單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 
+0

SimpleITK中也提供SetFixedImageMask()和SetMovingImageMask(),我在我的問題中添加了當前的Ode。 – neon29

+0

在ITK的C++實現中,在將其添加到註冊之前,您需要從蒙版圖像構造一個MaskSpatialObject。我沒有看到你在Python包裝器中這樣做,但可能是在底層處理。 現在,在你目前的實施中,你怎麼知道面具沒有被設置? 此外,我不知道爲什麼我得到了我的答案downvote! – siavashk

+0

SetFixedImageMask()和SetMovingImageMask()直接使用二進制圖像而不構建MaskSpatialObject。 – neon29

0

是。您可以通過此代碼來實現 Newfixed = fixed fixedmask; Newmoving =正在移動 movingmask;

並使用新的固定和移動新註冊

+1

請編輯您的文章,以便代碼格式化。 –

相關問題