NCC
simeks opened this issue · comments
There seems to be something weird going on with NCC for normalized volumes. NCC should range from -1 to 1 so our cost function should normalize it to 0-1. However, looking at the output of the cost function there seems to be cases with negative cost, even cases were the cost is less than -1, which seems even weirder.
Above is a map of the NCC cost for a single iteration on normalized data, the black dot has a cost of -4.8. The normalization seems to work as expected and I can't really see a pattern for the errors.
I will investigate further but I just wanted to put this up here so I don't forget.
I propose to change the epsilon for d
:
if(d > 1e-14) { ...
It seems to happend only for very small values on d
, hard to tell whether it's a precision error or not. ANTs seems to have this threshold set to 1e-5
, while ITK just checks d != 0.0
(...).
That could make sense, since d
appears at the denominator. In double precision it should not be an issue, but the result is later converted to float
(whose upper limit on most architectures is in the order of 1e38
), and I guess the problem may come from that conversion. For MSVC "A double value converted to a float value is represented exactly, if possible. [...] If the result is out of range, the behavior is undefined.".
Still not sure how it goes out of float
range, though.
Yeah, it's a bit odd, but I've probably missed something. I tried removing the conversion but the issue is still there. Another weird thing is that the GPU version has the same epsilon, it's even all single-precision, but the problem only exists on the CPU.
I'll just lower the epsilon a bit then, shouldn't have a large impact on the results.
Fixed in 04f098a