1
我caluclating兩種顏色直方圖分別是3個維數組之間的區別:爲什麼*運營商提供給錯誤的結果並Math.pow()正確
deltaH
是double
。
int[][][] t1 = item.getCh();
int[][][] t2 = comparedItem.getCh();
for(int i = 0; i < t1.length; i++)
for(int j = 0; j < t1[i].length; j++)
for(int p = 0; p < t1[i][j].length; p++)
deltaH = deltaH + ((t1[i][j][p] - t2[i][j][p]) * (t1[i][j][p] - t2[i][j][p]));
在這一個以上someties的結果我得到負數,這在數學上是不可能的。 當不使用*
我用Math.pow()方法:
int[][][] t1 = item.getCh();
int[][][] t2 = comparedItem.getCh();
for(int i = 0; i < t1.length; i++)
for(int j = 0; j < t1[i].length; j++)
for(int p = 0; p < t1[i][j].length; p++)
deltaH = deltaH + Math.pow(t1[i][j][p] - t2[i][j][p],2);
我得到正確的結果。爲什麼這樣?
你的號碼不適合'int'。 – SLaks
@SLaks即使這些數字沒有意義,我們仍然有x * x> = 0。 – Yoda
'deltaH'的類型是什麼? – Szymon