Registration CT MRI

I want to reg CT (moving) to MRI (fixed):

  • I have cropped the volume to the ROI in both volumes
  • I have resampled both images to the same voxel size
  • I have initially transformed the CT to MRI and provided this transform as initialization transform

I tried Rigid, affine it does not matter cause I get this error:

General Registration (BRAINS) standard error:

ExceptionObject caught !

itk::ExceptionObject (0x7ffcf263ec00)

Location: “unknown”

File: /Volumes/Dashboards/Preview/Slicer-0-build/ITK/Modules/Registration/Metricsv4/include/itkMattesMutualInformationImageToImageMetricv4.hxx

Line: 312

Description: itk::ERROR: MattesMutualInformationImageToImageMetricv4(0x7ffcf263ddd0): Joint PDF summed to zero

Any idea?

This error message means that the volumes don’t overlap enough in space.

Can you attach a screenshot of your initial state?

You may need to harden the transform after applying, otherwise it does not affect the registration.

You may also try “General registration (Elastix)” module (provided by SlicerElastix extension), as it tend to be less sensitive to initialization and optimization parameters.

MRI and CT were resampled to bspline 0.2mm, however image dimensions were not the same
I did harden the initial transf of the ct.
as one can see there is a mismatch between ct and mri. the registration proc. could not optmize my initial transformation or provided the aforementioned error msg.
elastix sometimes reported the same error msg or did not improve the results. the pity is, I already managed once a perfect registration however fail to repeat it now (same data).

Interestingly, fixed (ct) and moving (mri) works faster and better than the other way round. However I am looking for reg. ct (moving) on mri (fixed)

Volume registration is started in working directory: /var/folders/lv/f_t6f0ys1x34xd03xcdprbym0000gq/T/Slicer/Elastix/20200420_194355_170
Register volumes…

elastix is started at Mon Apr 20 19:43:55 2020.

which elastix: /Applications/Slicer.app/Contents/Extensions-28989/SlicerElastix/lib/Slicer-4.11/elastix
elastix runs at: Fs-MacBook-Pro.local
Mac OS X 10.14.6 (x64), 18G3020
with 8192 MB memory, and 2 cores @ 2900 MHz.

Running elastix with parameter file 0: “/Applications/Slicer.app/Contents/Extensions-28989/SlicerElastix/lib/Slicer-4.11/qt-scripted-modules/Resources/RegistrationParameters/Parameters_Rigid.txt”.

Current time: Mon Apr 20 19:43:55 2020.
Reading the elastix parameters from file …

Installing all components.
InstallingComponents was successful.

ELASTIX version: 5.000
Command line options from ElastixBase:
-f /var/folders/lv/f_t6f0ys1x34xd03xcdprbym0000gq/T/Slicer/Elastix/20200420_194355_170/input/fixed.mha
-m /var/folders/lv/f_t6f0ys1x34xd03xcdprbym0000gq/T/Slicer/Elastix/20200420_194355_170/input/moving.mha
-fMask unspecified, so no fixed mask used
-mMask unspecified, so no moving mask used
-out /var/folders/lv/f_t6f0ys1x34xd03xcdprbym0000gq/T/Slicer/Elastix/20200420_194355_170/result-transform/
-p /Applications/Slicer.app/Contents/Extensions-28989/SlicerElastix/lib/Slicer-4.11/qt-scripted-modules/Resources/RegistrationParameters/Parameters_Rigid.txt
-p /Applications/Slicer.app/Contents/Extensions-28989/SlicerElastix/lib/Slicer-4.11/qt-scripted-modules/Resources/RegistrationParameters/Parameters_BSpline.txt
-threads unspecified, so all available threads are used
WARNING: The parameter “UseDirectionCosines”, requested at entry number 0, does not exist at all.
The default value “true” is used instead.

WARNING: The option “UseDirectionCosines” was not found in your parameter file.
From elastix 4.8 it defaults to true!
This may change the behavior of your registrations considerably.

Command line options from TransformBase:
-t0 unspecified, so no initial transform used

Reading images…
Reading images took 150 ms.

WARNING: the fixed pyramid schedule is not fully specified!
A default pyramid schedule is used.
WARNING: the moving pyramid schedule is not fully specified!
A default pyramid schedule is used.
WARNING: The parameter “AutomaticTransformInitializationMethod”, requested at entry number 0, does not exist at all.
The default value “GeometricalCenter” is used instead.
Transform parameters are initialized as: [0, 0, 0, -1.5244374302985904, -24.311078731531566, -14.602596841435947]
Scales are estimated automatically.
Scales for transform parameters are: [3772.2559831259255, 3825.3517771192674, 5551.213166583119, 1, 1, 1]
Initialization of all components (before registration) took: 19 ms.
Preparation of the image pyramids took: 1777 ms.

Resolution: 0
WARNING: The parameter “ShowExactMetricValue”, requested at entry number 0, does not exist at all.
The default value “false” is used instead.
WARNING: The parameter “CheckNumberOfSamples”, requested at entry number 0, does not exist at all.
The default value “true” is used instead.
WARNING: The parameter “UseMultiThreadingForMetrics”, requested at entry number 0, does not exist at all.
The default value “true” is used instead.
Setting the fixed masks took: 0 ms.
Setting the moving masks took: 0 ms.
WARNING: The parameter “NumberOfFixedHistogramBins”, requested at entry number 0, does not exist at all.
The default value “32” is used instead.
WARNING: The parameter “NumberOfMovingHistogramBins”, requested at entry number 0, does not exist at all.
The default value “32” is used instead.
WARNING: The parameter “FixedLimitRangeRatio”, requested at entry number 0, does not exist at all.
The default value “0.01” is used instead.
WARNING: The parameter “MovingLimitRangeRatio”, requested at entry number 0, does not exist at all.
The default value “0.01” is used instead.
WARNING: The parameter “FixedKernelBSplineOrder”, requested at entry number 0, does not exist at all.
The default value “0” is used instead.
WARNING: The parameter “MovingKernelBSplineOrder”, requested at entry number 0, does not exist at all.
The default value “3” is used instead.
WARNING: The parameter “UseFastAndLowMemoryVersion”, requested at entry number 0, does not exist at all.
The default value “true” is used instead.
WARNING: The parameter “UseJacobianPreconditioning”, requested at entry number 0, does not exist at all.
The default value “false” is used instead.
WARNING: The parameter “FiniteDifferenceDerivative”, requested at entry number 0, does not exist at all.
The default value “false” is used instead.
WARNING: The parameter “SP_A”, requested at entry number 0, does not exist at all.
The default value “20” is used instead.
WARNING: The parameter “MaximumNumberOfSamplingAttempts”, requested at entry number 0, does not exist at all.
The default value “0” is used instead.
WARNING: The parameter “SigmoidInitialTime”, requested at entry number 0, does not exist at all.
The default value “0” is used instead.
WARNING: The parameter “MaxBandCovSize”, requested at entry number 0, does not exist at all.
The default value “192” is used instead.
WARNING: The parameter “NumberOfBandStructureSamples”, requested at entry number 0, does not exist at all.
The default value “10” is used instead.
WARNING: The parameter “UseAdaptiveStepSizes”, requested at entry number 0, does not exist at all.
The default value “true” is used instead.
WARNING: The parameter “AutomaticParameterEstimation”, requested at entry number 0, does not exist at all.
The default value “true” is used instead.
WARNING: The parameter “UseConstantStep”, requested at entry number 0, does not exist at all.
The default value “false” is used instead.
WARNING: The parameter “MaximumStepLengthRatio”, requested at entry number 0, does not exist at all.
The default value “1” is used instead.
WARNING: The parameter “MaximumStepLength”, requested at entry number 0, does not exist at all.
The default value “0.449219” is used instead.
WARNING: The parameter “NumberOfGradientMeasurements”, requested at entry number 0, does not exist at all.
The default value “0” is used instead.
WARNING: The parameter “NumberOfJacobianMeasurements”, requested at entry number 0, does not exist at all.
The default value “1000” is used instead.
WARNING: The parameter “NumberOfSamplesForExactGradient”, requested at entry number 0, does not exist at all.
The default value “100000” is used instead.
WARNING: The parameter “SigmoidScaleFactor”, requested at entry number 0, does not exist at all.
The default value “0.1” is used instead.
Elastix initialization of all components (for this resolution) took: 2 ms.
Computing the fixed image extrema took 1 ms.
Computing the moving image extrema took 0 ms.
Initialization of AdvancedMattesMutualInformation metric took: 5 ms.
Starting automatic parameter estimation for AdaptiveStochasticGradientDescent …
WARNING: The parameter “ASGDParameterEstimationMethod”, requested at entry number 0, does not exist at all.
The default value “Original” is used instead.
Computing JacobianTerms …
Computing the Jacobian terms took 0.004218s
NumberOfGradientMeasurements to estimate sigma_i: 6
Sampling gradients …

Progress: 0%Time spent in resolution 0 (ITK initialization and iterating): 0.017 s.
Stopping condition: Error in metric.
Settings of AdaptiveStochasticGradientDescent in resolution 0:
( SP_a 1.000000 )
( SP_A 20.000000 )
( SP_alpha 0.602000 )
( SigmoidMax 1.000000 )
( SigmoidMin -0.800000 )
( SigmoidScale 0.000000 )

itk::ExceptionObject (0x7fa16184a1d0)
Location: “ElastixTemplate - Run()”
File: /Volumes/Dashboards/Preview/S-0-E-b/SlicerElastix-build/elastix/Common/CostFunctions/itkAdvancedImageToImageMetric.hxx
Line: 1007
Description: itk::ERROR: itk::ERROR: AdvancedMattesMutualInformationMetric(0x7fa160840800): Too many samples map outside moving image buffer: 2203 / 16384

Error occurred during actual registration.

Errors occurred!
vtkDebugLeaks has found no leaks.

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

That’s not a problem at all. You can swap fixed/moving images and invert the final transform by a single click (“Invert” button in Transforms module).

OK, thanks a lot!

And what means “Command ‘elastix’ returned non-zero exit status 1.”?

It means Elastix encountered an error. Details of the error are described in the Elastix output log.

I have registered many CTs (fixed) and MRIs (moving), however I forgot to set the option “Slicer Linear Transform” in the General Registration modul. Is there retrospectively the option to get the transf. matrix from 2 registered volumes, as I want to invert now the registration (MRI <- CT)???

If you haven’t saved the linear transform node, only the resampled moving image, then there is no way to recover that information. Of course, you could re-register the transformed moving image to the moving image to compute a transformation, but then you could just as well re-run the registration.

I assume you have done it using a batch file anyway, so re-running the registration should not take too much effort. If the time required to redo the registrations is a concern then you can virtual machines from a google/microsoft/amazon to distribute the work and speed things up as much as you need.

Thank you once again for your fast reply and help!

However re-thinking the workflow, I rendered one logical problem:

If I wanna know if MRI is suitable for a spec. surgery planning which was accomplished by CT up to now, I thought I have to do the planning first in MRI and then check it in CT (after registration).

However, as I necessarily have to pre-align the CT and MRI data sets to perform the registration process successfully, I have my FIRST transformation
and
after using General Registration (BRAINS) I get my SECOND transformation.

So could I deduce from these transformations what my surgical planning would like to be in CT?
Do I have to put these two transformations together? Or do I just need the second one in order to answer whether my planning in MRI would be the same in CT???

Kind regards

Using Slicer, you can transform the surgical plan (points, directions, etc.) and images in any directions, using one combined transform or in multiple steps. So, most likely this will not be a limitation in any way.

We don’t have enough information to make any particular recommendation. Usually you choose a hypothesis, design a study to test it, and perform the study. If you have a high-level idea about what you want to do, we can then help with the technical details.