contour[j] = contour[j-1] + ((contour[index] - contour[i-1]) / (index - i)) ;
should be
contour[j] = contour[j-1] + ((contour[index] - contour[i-1]) / (index - i + 1)) ;
As the interpolation is between index and i-1. The current code has a too big increment on contour[j-1], resulting in setting the value of contour[i-1] in contour[i].
e.g.
MathUtils.interpolateNonZeroValues(new double[]{1,0,3})) results in
[1,3,3] rather than [1,2,3].
contour[j] = contour[j-1] + ((contour[index] - contour[i-1]) / (index - i)) ;
should be
contour[j] = contour[j-1] + ((contour[index] - contour[i-1]) / (index - i + 1)) ;
As the interpolation is between index and i-1. The current code has a too big increment on contour[j-1], resulting in setting the value of contour[i-1] in contour[i].
e.g.
MathUtils.interpolateNonZeroValues(new double[]{1,0,3})) results in
[1,3,3] rather than [1,2,3].