ShapeLabelMapFilter floating point exception


(Fijoy Vadakkumpadan) #1

Hello,

I’m getting a floating point exception at line #364 of:

crashing the application. The reason seems to be numerical precision issues in principal moments calculation, resulting in a call to std::sqrt() with a negative value. In my test specifically, the principalMoments array at that line contains {-2.2737367544323206e-13, 4.5474735088646412e-13, 2524.329986572267}.

Perhaps the filter could use a more robust algorithm? Alternatively, that crashing line needs to be further guarded with a check for negative values?

FYI, I’m using ITK version 4.10.1. Just by visually comparing the source above with the one in 4.10.1, I do see that there have been some updates to the moments calculation, but the underlying numerical calculations look similar.

Thanks,
–Fijoy


(Bradley Lowekamp) #2

I agree this is a bug.
Can you please create an issue on Github with this information?

Thanks.


(Bradley Lowekamp) #3

Please find a patch to prevent the sqrt of a negative number here: