voxelmorph icon indicating copy to clipboard operation
voxelmorph copied to clipboard

Cross Correlation not normalized

Open Taariq78 opened this issue 5 years ago • 6 comments

Hello, should the NCC loss not return a value between 0 and 1? During my training, I get NCC values that are not within the range that I expect (between 0 and 1)?

Taariq78 avatar Oct 23 '20 16:10 Taariq78

Sorry, I found my error

Taariq78 avatar Oct 23 '20 17:10 Taariq78

Hello again, sorry for reopening this issue. I can't make sense of something - I wanted to determine if the NCC loss function was working as intended, so I passed two identical images (the original + its copy) into the ncc_loss (Pytorch) function, expecting the output to be 1. However, what outputted was some decimal number and I can't figure out why its doing so.

Do you have any idea as to why this is happening? Thank you.

Taariq78 avatar Oct 23 '20 19:10 Taariq78

Hello I came also across this strange result. And to investigate I change the code so that instead of returning the mean over the volume it return the volume values of cc. When then passing 2 identical image (I get a mean of 0.46) I notice that withing the brain I get some 1 values and outside I get some 0 value (which explain a mean different from 1) given the mathematical formulation used, it make sense since with 0 intensity values you end up with a cc equal to zero (https://github.com/voxelmorph/voxelmorph/blob/2ce0fc197174ef35debc373dcb6b111632441690/voxelmorph/torch/losses.py#L65) note that there was also some zero value within the brain corresponding to very homogeneous regions (I was using a simulated data) also it is not 100% clear why, I guess this is related to a null variance ...

What I do not understand, is if this metric is equivalent the Normalized cross correlation, as it is defined here https://en.wikipedia.org/wiki/Cross-correlation#Normalized_cross-correlation_(NCC). The formulation are very different I indeed compare the 2 metrics, and they are not the same ... So my question is then Are you sure we can talk about Cross Correlation here ?

any hint will be appreciate, thanks

romainVala avatar Nov 25 '20 15:11 romainVala

Hi, @Taariq78, do you solve the problem? I also met the same problem. Any help is appreciated.

Thanks!

ElegantLin avatar Sep 13 '21 08:09 ElegantLin

We're coming across a similar issue in our code, has anyone found a solution to the problem?

imogen-edwards avatar Mar 17 '22 17:03 imogen-edwards

I have tried the code suggested in #358, and there has been no problem for me. Hope it helps.

kvttt avatar Jun 08 '22 17:06 kvttt