Elastix registration with Masking

Dear experts,
I would like to register 2 images, CT and CT. Actually, my final goal is to register SPECT and SPECT with different timepoint.

Firstly, I used rigid registration followed by elastix between CT1 and CT2 at different timepoint. Then I use these transformation matrices to SPECT2. The result looked well for organ but not tumor. I would like to use masking in elastix. I apply segmented tumor. The result showed error.

Failed to compute results.

Command ‘elastix’ returned non-zero exit status 1.

Traceback (most recent call last):
File “D:\slicer\Slicer 5.6.2\bin\Python\slicer\util.py”, line 3255, in tryWithErrorDisplay
yield
File “D:/slicer/Slicer 5.6.2/slicer.org/Extensions-32448/SlicerElastix/lib/Slicer-5.6/qt-scripted-modules/Elastix.py”, line 314, in onApplyButton
self.logic.registerVolumesUsingParameterNode(self._parameterNode)
File “D:/slicer/Slicer 5.6.2/slicer.org/Extensions-32448/SlicerElastix/lib/Slicer-5.6/qt-scripted-modules/Elastix.py”, line 591, in registerVolumesUsingParameterNode
self.registerVolumes(
File “D:/slicer/Slicer 5.6.2/slicer.org/Extensions-32448/SlicerElastix/lib/Slicer-5.6/qt-scripted-modules/Elastix.py”, line 637, in registerVolumes
self.logProcessOutput(elastixProcess)
File “D:/slicer/Slicer 5.6.2/slicer.org/Extensions-32448/SlicerElastix/lib/Slicer-5.6/qt-scripted-modules/Elastix.py”, line 572, in logProcessOutput
raise subprocess.CalledProcessError(return_code, “elastix”)
subprocess.CalledProcessError: Command ‘elastix’ returned non-zero exit status 1.

This means that the error is inside elastix
To get a better understanding of the error, you need to read the elastix log.
To do that, tick the “keep temporary files” box, launch your regisrtration then click on “show temp folder”
There’s a text file called elastix, if you go to the bottom of the file, you should get a more helpfull error

Thank you for your reply.

The text file showed

itk::ExceptionObject (0000003B772FC9B0)
Location: “ElastixTemplate - Run()”
File: D:\D\S\S-0-E-b\SlicerElastix-build\elastix\Common\CostFunctions\itkAdvancedImageToImageMetric.hxx
Line: 916
Description: ITK ERROR: AdvancedMattesMutualInformationMetric(0000020314FC7190): Too many samples map outside moving image buffer: 510 / 2048

Error occurred during actual registration.

Errors occurred!

It’s hard to help you without example, but you can try these:

  • Center both of your volume (giving them the same origin)
  • Make sure that your volumes are of similar sizes