// // Implementation of 'Two Incremental 1D' // // The following code uses the separability of the incremental // function to speed up the computation. The first pixel is // calculated by adding pixel values along the windowSize. The // subsequent pixels use the previous calculated pixel to obtain // their new value. At the end, all pixels are divided by // windowSize to get proper greyscale colors. // public class incremental extends Object { public incremental() {}; public int[] smoothen(int inPixels[], int windowSize, int width, int height) { int outPixels[] = new int[inPixels.length]; int offset = (windowSize-1)/2; int x = offset; // calculate the first pixel for (int i = x-offset; i <= x+offset; i++) outPixels[x] += inPixels[i]; // calculate subsequent pixels using previous result (separable) for (x = offset; x < inPixels.length - offset -1; x++) outPixels[x+1] = outPixels[x] - inPixels[x-offset] + inPixels[x+offset+1]; // divide all pixels by windowSize for (x = offset; x < inPixels.length - offset; x++) outPixels[x] /= windowSize; return outPixels; } }