[ITK] [ITK-users] How to use a binary mask in a registration process ?
Bradley Lowekamp
blowekamp at mail.nih.gov
Tue Sep 15 08:32:28 EDT 2015
Hello,
So why do you think the masks are not working? What is the output with and without masks? Can you share you data? Is the metric value different with and w/o the masks?
I'd also recommend setting the SamplingStrategy to None until you have the masks working they way you expect.
Brad
On Sep 15, 2015, at 3:22 AM, neon29 <florian.nicolas at ensta-bretagne.org> wrote:
> Bradley Lowekamp wrote
>> Hello,
>>
>> First verify that you are using the correct methods for setting the masks.
>> You wrote "SetMetricMovingImage" where I think you intended
>> "SetMetricMovingMask". Mistakes are easy to make in code and things like
>> this should be double/triple checked.
>>
>> You likely need to perform a morphological erosion on the masks. With
>> smoothing and derivative computation, values outside the mask can effect
>> the metric near the boarder. You need to estimate how big the radius of
>> the erosion need to be based on your smoothing sigmas, and your scale.
>>
>> Without sample code I don't think I can help further.
>>
>> HTH,
>> Brad
>>
>>
>> On Sep 14, 2015, at 11:11 AM, neon29 <
>
>> florian.nicolas@
>
>> > wrote:
>>
>>> Hi everybody!
>>>
>>> I am currently trying to register sonar images using SimpleITK with
>>> Python.
>>> As the two images I want to register are geo-projected, I would like to
>>> restrict each image to the pixels where I have data (and get rid of the
>>> "background" which consists in '0').
>>>
>>> I have already computed my two binary masks and I have tried to use it
>>> with
>>> the SetMetricFixedMask() and SetMetricMovingImage() methods but when I
>>> look
>>> at the result, it is the same as when I do not use any mask. Indeed, it
>>> seems that the registration process tend to overlap my masks.
>>>
>>> I hope someone could help!
>>>
>>> Florian
>>>
>>>
>>>
>>> --
>>> View this message in context:
>>> http://itk-insight-users.2283740.n2.nabble.com/How-to-use-a-binary-mask-in-a-registration-process-tp7587799.html
>>> Sent from the ITK Insight Users mailing list archive at Nabble.com.
>>> _____________________________________
>>> Powered by www.kitware.com
>>>
>>> Visit other Kitware open-source projects at
>>> http://www.kitware.com/opensource/opensource.html
>>>
>>> Kitware offers ITK Training Courses, for more information visit:
>>> http://www.kitware.com/products/protraining.php
>>>
>>> Please keep messages on-topic and check the ITK FAQ at:
>>> http://www.itk.org/Wiki/ITK_FAQ
>>>
>>> Follow this link to subscribe/unsubscribe:
>>> http://public.kitware.com/mailman/listinfo/insight-users
>>
>> _____________________________________
>> Powered by www.kitware.com
>>
>> Visit other Kitware open-source projects at
>> http://www.kitware.com/opensource/opensource.html
>>
>> Kitware offers ITK Training Courses, for more information visit:
>> http://www.kitware.com/products/protraining.php
>>
>> Please keep messages on-topic and check the ITK FAQ at:
>> http://www.itk.org/Wiki/ITK_FAQ
>>
>> Follow this link to subscribe/unsubscribe:
>> http://public.kitware.com/mailman/listinfo/insight-users
>
> Thanks for your reply!
>
> Here is the piece of code:
>
> 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)
>
>
>
>
>
>
> --
> View this message in context: http://itk-insight-users.2283740.n2.nabble.com/How-to-use-a-binary-mask-in-a-registration-process-tp7587799p7587809.html
> Sent from the ITK Insight Users mailing list archive at Nabble.com.
> _____________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Kitware offers ITK Training Courses, for more information visit:
> http://www.kitware.com/products/protraining.php
>
> Please keep messages on-topic and check the ITK FAQ at:
> http://www.itk.org/Wiki/ITK_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://public.kitware.com/mailman/listinfo/insight-users
_____________________________________
Powered by www.kitware.com
Visit other Kitware open-source projects at
http://www.kitware.com/opensource/opensource.html
Kitware offers ITK Training Courses, for more information visit:
http://www.kitware.com/products/protraining.php
Please keep messages on-topic and check the ITK FAQ at:
http://www.itk.org/Wiki/ITK_FAQ
Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/insight-users
More information about the Community
mailing list