strasdat / ScaViSLAM

This is a general and scalable framework for visual SLAM. It employs "Double Window Optimization" (DWO).
GNU Lesser General Public License v3.0
335 stars 133 forks source link

Wrong equations in Zero-mean SSD #32

Open ghost opened 11 years ago

ghost commented 11 years ago

I have been checking the Zero-mean SSD equations in matcher.cpp:

// sum[ ((A-mean(A)) - (B-mean(B))^2 ] // = sum[ ((A-B) - (mean(A)-mean(B))^2 ] // = sum[ (A-B)^2 - 2(A-B)(mean(A)mean(B)) + (mean(A)-mean(B))^2 ] // = sum[ (A-B)^2 ] - 2(mean(A)mean(B))(sumA-sumB) + N(mean(A)-mean(B))^2 // = sum[ (A-B)^2 ] - N * (mean(A)-mean(B))^2 // = sum[ A^2-2AB-B^2 ] - 1/N * (sumA-sumB)^2 // = sumAA-2_sumAB-sumBB - 1/N * (sumA^2-2_sumA_sumB-sumB^2) *znssd = sumAA-2_sumAB-sumBB - (sumA_sumA - 2_sumA_sumB - sumB_sumB)/BOX_AREA;

This code seems to work but the equations are wrong, there are two mistakes:

(A-B)^2 -> A^2-2AB-B^2 ------------> A^2-2AB+B^2

(sumA-sumB)^2 -> sumA^2-2_sumA_sumB-sumB^2 -------------------------> sumA^2-2_sumA_sumB+sumB^2

So, znssd should be calculated this way:

_znssd = sumAA-2_sumAB+sumBB - (sumA_sumA - 2_sumA_sumB + sumB_sumB)/BOX_AREA;

Regards

JzHuai0108 commented 9 years ago

I AGREE.