SuperElastix / elastix

Official elastix repository
http://elastix.dev
Apache License 2.0
475 stars 116 forks source link

Metric outcome "AdvancedNormalizedCorrelation" -1 for the same images #1185

Closed han050 closed 2 months ago

han050 commented 3 months ago

I am experiencing an issue with the AdvancedNormalizedCorrelation metric in elastix. Specifically, the metric consistently returns a value of -1, even when the input images are identical. Given that the images are exactly the same, I would expect the metric to return a value of 1, indicating perfect correlation.

I have tried multiple combinations of parameters in the parameter file. However, the metric outcome remains -1. One of the parameter files is given below.

I would appreciate any insights or suggestions on why the AdvancedNormalizedCorrelation metric might be returning -1 for identical images and how to resolve this issue. Is there a known bug, or are there additional configurations or steps I might be missing?

Thank you in advance!

Example of parameter file:

(FixedInternalImagePixelType "float") (MovingInternalImagePixelType "float") (FixedImageDimension 3) (MovingImageDimension 3)

(Registration "MultiResolutionRegistration") (Transform "TranslationTransform") (Metric "AdvancedNormalizedCorrelation") (Optimizer "AdaptiveStochasticGradientDescent") (Interpolator "LinearInterpolator")

(ImageSampler "Full")

(NumberOfResolutions 1) (ImagePyramidSchedule 1 1 1)

(MaximumNumberOfIterations 10)

// Output settings (WriteResultImage "true") (ResultImageFormat "mhd")

// Debugging options (WriteTransformParametersEachIteration "true") (WriteResultImageAfterEachResolution "true") (WriteLogFile "true") (LogToConsole "true") (LogToFile "true")

N-Dekker commented 3 months ago

Interesting! I do indeed see the text appear, saying:

Final metric value = -1

mstaring commented 3 months ago

Since elastix, like ITK, only minimizes an objective, the objective is here the negative correlation. Same for mutual information.

N-Dekker commented 3 months ago

OK, thanks @mstaring so -1 means 100% correlation. @han050 Does that answer your question?

han050 commented 2 months ago

Thank you both for your quick response. As I understand it, a correlation coefficient of -1 indicates a perfect negative correlation, meaning that low intensity values in scan 1 correspond to high intensity values in scan 2, and vice versa. However, given that the inputs are two identical CT scans with the same HU values (the same intensity values), I would expect a perfect positive correlation, which would be indicated by a correlation coefficient of 1.

Therefore, I am still confused about how the outcome could be -1 instead of 1 in this context. Can you provide further clarification on why this might be happening or do I misunderstand the answer of @mstaring?

Thanks again!

jasper-tms commented 2 months ago

A correlation coefficient of 1 (two identical images) means the correlation metric will be -1. The key is understanding that the correlation metric is not the correlation coefficient, it's the negative of it.

As Marius mentioned, the reason for this is that optimizers are typically built to minimize things. In order to maximize a correlation, you ask the optimizer to try to minimize the correlation metric (which is just the negative of the correlation coefficient). By minimizing the correlation metric, the optimizer will maximize the image correlation, which is what you want.